Running a python script from PHP with Apache -
i have set apache 2 server on raspberry pi index.php
can access computer on network. in same folder (/var/www
) have python script test.py
.
the script works fine when running manually. however, want able run script in browser using php. tried this:
<?php $command = escapeshellcmd('test.py'); $output = shell_exec($command); echo $output; ?>
however nothing happens. tried using full filepath /var/www/test.py
, didn't work either.
any suggestions on how can working?
two things come mind:
first, first line in file contain full path python interpreter? i.e:
#!/usr/bin/python
second, file have appropriate file permissions. can you open www-data
user (same user apache process should running as)?
sudo -u www-data /var/www/test.py
Comments
Post a Comment