title: permission denied when opening python script from php
body: <p>I have a PHP script that will create and append data to a text document.  The script will then execute a python script that will read over that document, and move create a different document else where on the raspberry pi.  I have been looking for the past several hours at different solutions, and they all seem to boil down to permissions.  Based on what I have found, I have set the following:</p>
  <blockquote>
  <p>-rwxrwxrwx 1 www-data www-data   314 Jan  9 16:09 AlbumString.py</p>
  <p>-rwxrwxrwx 1 www-data www-data 74 Jan  9 21:31 display.txt</p>
  </blockquote>
  <p>The AlbumString.py is the python script, the display.txt is where the PHP file rights to, and the Python script reads from.  Further research somone suggested looking at the error logs for apache.  When I looked at this I saw that I was getting a permission error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;AlbumString.py&quot;, line 13, in &lt;module&gt;
      display = open('/media/pi/external/Photos/' + templist.pop(0),'a')
  PermissionError: [Errno 13] Permission denied: '/media/pi/external/Photos/Erik.txt'
  </code></pre>
  <p>My python code will create or append a file if it already exists.  In the case of running this iteration, the file Erik.txt did not exist, so it would have had to create it.
  The code for AlbumString.py:</p>
  <pre><code>#!/usr/bin/python
  
  import sys
  import json
  import base64
  
  album = open('/var/www/html/uploads/display.txt')
  templist = []
  a= 0
  for x in album:
      templist.append(x.rstrip('\n'))
  album.close()
  display = open('/media/pi/external/Photos/' + templist.pop(0),'a')
  for x in templist:
      display.write(x+'\n')
  display.close()
  </code></pre>
  <p>The PHP code that I am using to call the python script:</p>
  <pre><code>fclose($fh);
  $testing = shell_exec(&quot;python3 AlbumString.py&quot;);
  if(!$testing){
      echo &quot;You are a failure!&lt;br&gt;&quot;;
  } else {
      echo &quot;You are a genius&lt;br&gt;&quot;;
  }
        echo &quot;end of document&quot;;
  }
  </code></pre>
  <p>I have also added www-data to my sudoers file, which is not suggested but that I would give it a chance, and nothing has worked.  The PHP correctly writes to the file, and if I call the python script from a console, that properly executes as well.</p>