Reputation: 59
I'm trying to run a node file from php. The following works...
running the node from terminal running an .sh that runs the node file from terminal running a .sh from php, that writes a text file ( so the php is succesfully triggering the .sh )
However, when I run the .sh file, running the node file from php it fails. I have tried using wait 30 ( the process takes about 10 seconds ) to make sure it's not exiting before completion. Do I need to set any special permissions in order for php --> .sh --> node to work? Done quite a bit of searching can't find anything.
Upvotes: 0
Views: 74
Reputation: 50798
It's important to understand how the file and execution chain is completed in order to understand why this won't work (assumedly).
Assuming a pretty common setup below...
When Apache is initialized, it has an owner, we'll say www-data
in this particular case. Now, Apache will execute and listen on port 80 as the www-data
user. This means that all requests it handles from here on out will be executed as the www-data
user.
So when you go to http://example.com/my-page.php, Apache is going to receive this request. Then it's going to go out and find the file associated with my-page.php
in the file system based on it's DocumentRoot
in the VirtualHost
directive. Once it's done this, the PHP interpreter that has been attached to the .php
file will do a top down interpretation of the file.
Once it gets to your bash script, www-data
is still the owner. Now the bash script
has been executed as www-data
in this case, and I'm willing to bet that www-data
(or your Apache user) is not in the list of sudoers (and rightfully so).
To combat this problem, you should instead make sure that the node
instance can be invoked without sudo permissions on your paritcular configuration. If this is just a localhost thing and the outside world isn't going to be hitting it, I'd say adding www-data
(or your Apache user) to the list of sudoers wouldn't be a bad thing.
Upvotes: 1