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