PHP Not Executing from Webpage [but is fine from PHP-CLI] on a Raspberry Pi PHP Not Executing from Webpage [but is fine from PHP-CLI] on a Raspberry Pi nginx nginx

PHP Not Executing from Webpage [but is fine from PHP-CLI] on a Raspberry Pi


PHP is probably configured to run in safe mode in your website configuration. When running in safe mode, some features like exec are disabled. Try disabling safe mode.

Another possibility is that the script lights.py cannot be found in the directory where your web server is running. To solve that, use the full path to your script, like exec("/usr/bin/python /home/armani/lights.py").

Another possibility is that the web server is running as a different user as yourself when you are logged (probably as nouser). And this user may not have access to some of the resources.

And there are probably many more such possible errors. Please provides more information on the error you get (try enabling debug in PHP to get a traceback).


None of the given answers helped me... in fact, my updates to my posts log what was ultimately the answer, which I found through my own trial/error and Googling.

I needed to assign user www-data into the dialout group in order to have access to /dev/ACM0, and a reboot was required (of the whole server, not just nginx for some reason).

I don't know why everybody kept answering that this was a path issue, WHEN I KEPT SAYING THE PYTHON SCRIPT RAN FINE FROM SHELL, AND THE PHP FILE RAN FINE FROM PHP-CLI.

Anyway, that's what solved it in the end. Thanks to everyone for trying.


What's the chmod of your lights.py file ?Could you try the followind command ?

chmod +x lights.py