I have a open() command in my Python script which opens the file data.json in my Apache serve running on Raspberry Pi in w mode. This script in turn is run by PHP using the shell_exec command. When the script is run alone, the Python code works. However, it does not function when run by PHP. Does anyone have any idea why this is happening, or is more information needed? Thank you in advance for your help!
Did you use the relative or absolute path?
Try to use the absolute path and check what's your working directory.
I think you are starting the python script not in the directory you think you are. :)
Python open() function not working when script executed by shell_exec() in PHP