1

Node-php is an npm package: https://www.npmjs.com/package/node-php#nodephp---run-wordpress-and-other-php-scripts-with-node

My problem: Up until now I only needed static html files for my webpage, which were delivered okay.

However, now I want to deliver a php file as well. If i simply try to send it like a static file a popup to save the file appears instead of displaying it. So i set up node-php which claims to be able to deliver php files correctly as well. But, it's not working.

How the webpage looks with the below code, going to either the html page or the php page

Either help to make node-php work, or another method to fix this are appreciated.

var express = require('express');
var php = require("node-php"); //Required by node-php
var path = require("path"); //Required by node-php
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.use("/", php.cgi("/usr/bin/php")); //Required by node-php

//LISTEN
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080);
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1');

http.listen(app.get('port'), app.get('ip'), function () {
console.log('LISTENING!');
});

app.use(express.static('public'));

//SEND FILES
app.get('/', function (req, res) {
    res.sendFile(__dirname + '/index.html');
});

app.get('/phpfile', function (req, res) {
    res.sendFile(__dirname + '/phpfile.php');
});
J G
  • 11
  • 1

2 Answers2

0

The argument passed to php.cgi() is supposed to be your PHP root directory (where your PHP files are located), not the path to a PHP binary.

mscdex
  • 104,356
  • 15
  • 192
  • 153
  • Ah! Will test and report back. – J G Jul 20 '16 at 01:34
  • I changed the line to "/var/lib/openshift/5716b3a77628e152370001d2/app-root/repo", which is the path to the files. However, all i get now when i go to any page is "No input file specified" in plaintext. :/ – J G Jul 20 '16 at 01:47
0

just in case you need only one server node and need to build around an node + php app i put here a method https://stackoverflow.com/a/68422021/5781320 that not involve this plugin (node-php) .so basically you can use node server and get post from a specific page(you can improve the node.js part , cause its only a prototype)