title: php script to execute python script to write some files
body: <p>I have a php script that calls a python script which in turn is in charge of writing some files to disk. </p>
  
  <p>If I execute the php script by entering its url in the web browser it can perform several filesystem related tasks:</p>
  
  <ul>
  <li>it's able to create a dir</li>
  <li>it's able to chmod the dir</li>
  </ul>
  
  <p>but it's not able to execute the python script which would create and write other files.</p>
  
  <p>The strange thing is that if I run the python script manually as <code>www-data</code>:</p>
  
  <pre><code>user@host $ sudo su www-data
  passwd for sudo:
  $ whoami
  www-data
  $ python my_script.py
  </code></pre>
  
  <p>It works like a charm.</p>
  
  <p>I'm assuming the user when I run the script through the browser is <code>www-data</code>. So why is the result in the console any different?</p>
  
  <hr>
  
  <h2>SOLVED:</h2>
  
  <p>Python script starts off by importing some modules from my repository, which are appended to the path via <code>.bashrc</code> or <code>.bash_profile</code> on login consoles. These modules were not available from the browser to the user <code>www-data</code>. So adding this to the python script solved it:</p>
  
  <pre><code>import sys
  sys.path.insert(0, 'path_to_my_modules')
  </code></pre>
  
  <p>solved it.</p>
  
  <p>I apologize for the question. It didn't bring all the necessary information for users to lead to a solution. I guess the problem was so broad that it was difficult for me to start thinking of where its root was.</p>
  
  <p>I lacked a good debugging technique to see what the error was. I commented out all the python script and begun with a simple <code>print 'here'</code>. Uncommenting lines one by one showed me the place where it just didn't print anything anymore (the error was obvious then).</p>