I'd like to start a python application from a php script which runs on a webserver. So far, so good. I tried
passthru("python track.py");
but it didn't work. Simply nothing happend. I tried exec() and system() as well just to make sure. Then I tried to run a php script with:
passthru("php test.php");
passthru("/usr/bin/php test.php")
Still nothing happening. But a
passthru("ls")
just works fine as expected.
I set the permissions that every user can edit and run the files.
This sounds like a situation where the webserver user cannot read the file in question.
Unfortunately, passthru()
simply returns NULL
if a command fails, instead of throwing an exception. For example, even such nonsense as var_dump(passthru('foobar'));
returns NULL
.
How can you solve this? You can test from the command line if the webserver would be able to execute the command (assuming www-data
is your webserver user, and you have sudo privileges):
sudo su - www-data -c 'python track.py'
This way, you'll get a meaningful error message and can solve the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.