I have set up an Apache 2 server on a Raspberry Pi with an index.php which I can access from any computer on the network. In the same folder (/var/www) I also have a python script test.py.
The script works fine when running it manually. However, I want to be able to run the script in my browser by using php. I tried this:
<?php
$command = escapeshellcmd('test.py');
$output = shell_exec($command);
echo $output;
?>
However nothing happens. I also tried using the full filepath /var/www/test.py, but that didn't work either.
Any suggestions on how I can get this working?
1 Answer 1
Two things come to mind:
First, does the first line in the file contain the full path to the python interpreter? i.e:
#!/usr/bin/python
Second, does the file have the appropriate file permissions. Can you you open it with the www-data user (same user as which your apache process should be running as)?
sudo -u www-data /var/www/test.py
2 Comments
test.py is trying to create the file testVideo.raw as the www-data user. You need to make sure that the directory where that file is being created allows the www-data user to write to it. Create a new private directory somewhere, change its owner using sudo chown www-data:www-data /path/to/directory, and write your raw file there.