0

I am unable to execute the node server.js file from php code but when I executes it from terminal it works fine.

<?php exec('/usr/local/bin/node Sever.js'); ?>
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
  • Can you switch on your verbose please ? :) We need more informations about "why do you say it doesn't work", there are so many possible way a thing doesn't work... – Random Jul 18 '15 at 11:39
  • In my project I have a Server.js file which includes node.js libraries. So when I execute it from terminal it is executing but not from my index.php file. – Tuhin Biswas Jul 18 '15 at 11:48
  • how do you see it doesn't ? have you error logs ? saying it couldn't execute ? have you logs before that line to be sure the code goes up there ? – Random Jul 18 '15 at 11:51
  • Yes the code goes up there. I've already checked that. – Tuhin Biswas Jul 18 '15 at 11:56
  • 2 things : 1: you got a space in your exec. 2: you should have something in your php_error if you reach that line but doesn't exec it... – Random Jul 18 '15 at 12:03
  • You have `Sever.js` in the PHP `exec()`, but you said that the script is called Server.js? – VolenD Jul 18 '15 at 12:14
  • Yes it looks like that but originally there is no space in between Server.js, I've checked it twice. – Tuhin Biswas Jul 18 '15 at 12:19
  • 1) So, `Sever.js` or `Server.js`? 2) Check that the php file and 'sever.js` (or `server.js`?) are in one folder, or specify the full path to the `server.js` in exec. – stdob-- Jul 18 '15 at 13:30
  • This is what I did exec('node /var/www/docs/Silkeletz/public/silk_Eletz/admin/Server.js'); I gave full path to the Server.js but it's still not working. – Tuhin Biswas Jul 20 '15 at 06:27

1 Answers1

0

I was able to execute the file. First get full path to node. Run in terminal < which node > then add web path of your js file in exec function.

Check here Calling node.js script from PHP returns nothing

exec('/usr/local/bin/node '.WEB_PATH.'/Server.js');
Community
  • 1
  • 1