title: While running a Python script on Apache2, I get this error: IOError: [Errno 13] Permission denied
body: <p>I am programming a web based application in Python and PHP. Now I running the server on the same computer as I am programming. The Python script will be executed in PHP. This part is working well.</p>
  
  <p>The script have to read files and store pathnames in a list. This list is used in the rest ot the script. </p>
  
  <pre><code>fileList = ['/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules /Read_files_determine_overlap_and_visualisation/B.txt', '/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules/Read_files_determine_overlap_and_visualisation/D.txt', '/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules/Read_files_determine_overlap_and_visualisation/C.txt', '/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules/Read_files_determine_overlap_and_visualisation/E.txt', '/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules/Read_files_determine_overlap_and_visualisation/A.txt']
  </code></pre>
  
  <p>The function readFiles will use this list. fileList is a global variable. Its made by glob.</p>
  
  <pre><code>def readFiles():
  
  Dic = {}
  
  for filePath in fileList:
      geneList = [] #create a new list every new loop to put in genesPerBacteriaDic as value
      for line in open(filePath, 'r').readlines(): #innerloop to read every file in lines
          if not line.startswith('FIG'):
              sys.exit('Wrong file format!!\nUpload FIGFAMS-format only') #terminate program if incorrect file format is imported
          FIGnumber = line[0:11] #remove '\n' or another characters on the end of the string
          geneList.append(FIGnumber)
      head, fileName = os.path.split(filePath) # convert filePath to fileName
      Dic[fileName] = geneList
  return Dic
  </code></pre>
  
  <p>When running on Apache when I call the Python script I get the following error in tail -f /var/log/apache2/error.log :</p>
  
  <pre><code>Traceback (most recent call last):
  File "/var/www/Coregrapher/makeVisualisation.py", line 192, in &lt;module&gt;
  main()
  File "/var/www/Coregrapher/makeVisualisation.py", line 48, in main
  genesPerBacteriaDic = readFiles()
  File "/var/www/Coregrapher/makeVisualisation.py", line 70, in readFiles
  for line in open(filePath, 'r').readlines(): #innerloop to read every file in lines
  IOError: [Errno 13] Permission denied: '/home/mark/Bureaublad/Dropbox/Stage-documenten/Python-modules/Readp_files_determine_overlap_and_visualisation/B.txt'
  </code></pre>
  
  <p>When I run the same script in IDLE and Linux Terminal the script gives no errors and the correct visualisation of the content of the file(s).</p>
  
  <p>I tried already CHMOD 777 in the directory where the script have to read the files and check with ls -l the files have all permissions. It's done for my own account and the account of the Apache server. I am administrator on this Linux computer.</p>
  
  <p>In the orignal script, fileList is created in the script itself. I also needed to create the list in IDLE and copy/paste to the same script thats running on Apache. Without this on Apache [] is returned only and in IDLE the correct list that is shown above. This may caused by the same problem but there is no error message in this case. When I put the correct list in the script on Apache, the error occured.</p>
  
  <p>Why does the script work in IDLE and directly in command line correctly and on Apache it dont have the permission to open files, even with CHMOD 777 on my account and the account of the server?</p>