I have an apache2 webserver running on the pi. I have a php file that uses exec() to run a python script. Everything works well from the command line. when loaded through the browser, the exec() function returns nothing. The python script works when executed using sudo -u www-data. php file.php also works from the terminal, but not through the browser. When i try sudo -u www-data php file.php, it asks for the password, which i didnt set. What should I do? Here is the output of ls -l command.

-rwxrwxrwx 1 www-data www-data   125 Jul  2 19:52 test.php
-rwxr-x--- 1 www-data www-data   218 Jul  2 19:44 lights.py


echo(shell_exec("/usr/bin/python3 /var/www/html/control/lights.py"));
  • determine if the python script gets called by PHP
    – jsotola
    Jul 2 '19 at 16:27
  • Have you added the www-data user to the GPIO group? What shows up in /var/log/apache2/error.log when the script fails?
    – Dougie
    Jul 2 '19 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.