file writing permission error as user www-data
Question: I am trying to write to a file by running a python script as user www-data.
When I run the script using the following:

    
    
    sudo python my_script.py
    

it writes fine. When I run the PHP script as www-data it doesn't write.
Permissions:

    
    
    folder(PiControl....contains status_log file): drwxrwxrwx
    file(status_log....the file I am trying to write to): -rwxrwxrwx User:www-data group:www-data
    

writing to file Python code:

    
    
    #!/usr/bin/python
    import datetime
    
    status="on"
    
    with open("status_log", "a") as myfile:
        myfile.write("{} {} {}".format("<br>light is now:", status,datetime.datetime.now()))
    

I created a webpage button to run the file

Can someone tell me what to change here?


Answer: Because I had symlink'ed my web files from my home directory when the PHP read
status_log they found it in my local directory, when www-data wrote to it (via
the Python above) it created the file in /var/www, instead of /home where I
was trying to read it from.

The solution was to change the path of the file being read to its location in:
/var/www

