Run PHP scripts in Node.js web server

What steps are needed to have a Node.js web server feature like Apache executing PHP scripts? Any way to integrate PHP into Node.js?

Note. I do not want to run PHP scripts directly in Node.js, but "route" through an Apache instance or something like that.

+55
Jun 30 '11 at 23:24
source share
10 answers

Node.js only supports JavaScript. Here is a tutorial on how PHP works with Node.js on the side.

http://blog.mixu.net/2011/01/04/nginx-php-fpm-and-node-js-install-on-centos-5-5/

+27
Jun 30 '11 at 23:29
source share

I had the same question. I tried calling php through the shell interface and it gave the desired result:

var exec = require("child_process").exec; app.get('/', function(req, res){exec("php index.php", function (error, stdout, stderr) {res.send(stdout);});}); 

I am sure that this is not so much on the list of recommended practices, but he seems to have done what I wanted. If, on the other hand, you do not want to execute PHP scripts directly from Node.js, but want to transfer them from another web server that does this, this seems to do the trick:

 var exec = require("child_process").exec; app.get('/', function(req, res){exec("wget -q -O - http://localhost/", function (error, stdout, stderr) {res.send(stdout);});}); 
+53
Oct 12 '11 at 3:26
source share

Take a look here: https://github.com/davidcoallier/node-php

From them read by me:

Embedded PHP server running on Node.js

Be worried, be very worried. The name NodePHP takes its name from the fact that we effectively turn a beautiful Node.js server into a FastCGI Interface that interacts with PHP-FPM.

This is an omega-alpha-super-beta proof of concept, but it already runs some simple scripts. It was mainly done for my negotiations on Node.js for PHP Developers , it turns out to be a rather interesting project, which we are most likely to use with Orchestra when we decide to release the Embedded PHP Server , which allows people to run PHP without Apache, Nginx or any web server.

Yes, this contradicts all the ideas and concepts of Node.js, but the idea is to be able to create a web server directly from any worker, in order to allow developers to move even faster than it was before. No need to create vhosts or server blocks. / etc / hosts.

+5
Mar 15 '13 at 9:18
source share

Snappy PHP is a node module for running PHP on the server side.
It is compatible, but not dependent on express.
It also supports websockets requests on the HTTP port.
It is biased for speed at light load, not for saving resources.

To install in node:

 npm install sphp 

in your application:

 var express = require('express'); var sphp = require('sphp'); var app = express(); var server = app.listen(8080); app.use(sphp.express('public/')); app.use(express.static('public/')); 

For more information see https://github.com/paragi/sphp
I must mention that I am an author :)

+5
Jan 08 '16 at 21:24
source share

You can try implementing a direct link node β†’ fastcgi β†’ php. In the previous answer, nginx serves php requests using http-> fastcgi serialisation-> unix socket-> php and node requests as http-> nginx reverse proxy β†’ node http server.

It seems that node-fastcgi paser can be used at the moment, but only as node backcgi. You must accept it for use as a fastcgi client for the php fastcgi server.

+3
Jul 01 2018-11-11T00:
source share

A simple, quick approach , in my opinion, would be to use dnode-php .

You can see a brief introduction here . Simple, fast and easy!

+2
May 19 '13 at 13:58
source share

If php is in FPM mode node -phpfpm may be an option, check the documentation https://www.npmjs.com/package/node-phpfpm

+2
Jul 13 '16 at 5:00
source share

You can use node-php to run php using node js: https://github.com/mkschreder/node-php

+1
Jan 27 '14 at 12:29
source share

You can directly serve PHP using node WAS: https://github.com/paragi/was

0
Feb 05 '14 at 1:07
source share

You should check out node-php-fpm .

0
Dec 11 '17 at 16:00
source share



All Articles