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'); ?>
9
  • 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... Commented Jul 18, 2015 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. Commented Jul 18, 2015 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 ? Commented Jul 18, 2015 at 11:51
  • Yes the code goes up there. I've already checked that. Commented Jul 18, 2015 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... Commented Jul 18, 2015 at 12:03

1 Answer 1

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.