Run console php script by nodejs on heroku hosting

I have a nodejs application runned on heroku. I have to run console PHP script in it. I want to execute the script by child process - http://nodejs.org/api/child_process.html.

My question is - how can i enable both nodejs and php interpreter in heroku hosting?

this is index.js file of my application (simplified)

var http = require('http'),
  exec = require('child_process').exec;

http.createServer(function (req, res) {


  exec('php script.php',
    function (error, stdout, stderr) {
      if(error){
        throw error;
      } else {
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end(stdout);
      }
    });

}).listen(process.env.PORT || 3000);

this is script.php file

<?php
echo "Hello, world!";

When i try to start my application, i has this response in logs

Sep 23 06:44:48 blooming-woodland-9158 app/web.1:  Error: Command failed: /bin/sh: php: not found 
Sep 23 06:44:48 blooming-woodland-9158 app/web.1:      at ChildProcess.exithandler (child_process.js:648:15) 
Sep 23 06:44:48 blooming-woodland-9158 app/web.1:      at ChildProcess.emit (events.js:98:17) 
Sep 23 06:44:48 blooming-woodland-9158 app/web.1:      at maybeClose (child_process.js:756:16) 
Sep 23 06:44:48 blooming-woodland-9158 app/web.1:      at Socket.<anonymous> (child_process.js:969:11) 
Sep 23 06:44:48 blooming-woodland-9158 app/web.1:      at Socket.emit (events.js:95:17) 
Sep 23 06:44:48 blooming-woodland-9158 app/web.1:      at Pipe.close (net.js:465:12) 

so it looks like it do not have the PHP binary installed

UPD: they have the buildpack for php https://github.com/heroku/heroku-buildpack-php i'll try to use it and share the result here

UPD1: buildpack do not allows to start nodejs for it I decided to build php binary like described here and ship it with my project - probably i can build the PHP binary and ship it with my project - Compile PHP into Static Binary

No php binary on a server you don t control, you cannot install it, so your code just can t work, you have the choice between:

  • Move out of heroku, install node.js and php on your server, and use this code (if you have a server)
  • Make your php rest-ful, started on another server, and get the result in another form (if you have a server and time)
  • Rewrite your php script in a format supported by heroku (if you have time)

There is no other choice, each have drawback, but unless you have a lot of money, I doubt heroku will be willing to install php on their server just for you.

I have fixed this issue by myself. https://github.com/vodolaz095/nodejs-php-heroku-example

I have build PHP binary, than i have included it into nodejs project and pushed to server. And it is running.

I do not imply, that this is the only and the best solution, but it do exactly what i want

So, i have posted an example how can i do it