title: raspberry pi: Can't execute script.py from PHP
body: <p>update:</p>
  
  <p>after advice in the comments I found my error.log (/var/log/apache2/error.log):</p>
  
  <pre><code>Traceback (most recent call last):
  File "/var/www/html/nano.py", line 7, in &lt;module&gt;
  GPIO.setup(17,GPIO.OUT)
  RuntimeError: No access to /dev/mem.  Try running as root!
  </code></pre>
  
  <p>I solved my problem by adding sudo:</p>
  
  <pre><code>&lt;?php
  echo exec("sudo /usr/bin/python /var/www/html/nano.py");
  ?&gt;
  </code></pre>
  
  <p>but I still don't understand it.
  I need to run it as sudo when I call nano.py from my webserver, but when I run nano.py from my terminal (as pi user) I don't have to run it as sudo.
  I thought that I gave apache root access when I edited sudoers. </p>
  
  <p>anyone who can explain this?
  and is this safe? (my apache server is only accessible from my own wifi network for now)</p>
  
  <hr>
  
  <p>I know this question has been asked and answered many times, but I've tried every solution I could find but I still can't execute my script.py from my PHP webpage.</p>
  
  <p>I can execute my nano.py script from terminal:
  <a href="https://i.stack.imgur.com/PrHp2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PrHp2.png" alt="nano.py"></a></p>
  
  <p>My apache server is also working fine (I can display text if I want)</p>
  
  <p>nano.py script:</p>
  
  <pre><code>#!/usr/bin/env python
  import RPi.GPIO as GPIO
  import time
  GPIO.setmode(GPIO.BCM)
  GPIO.setwarnings(False)
  GPIO.setup(17,GPIO.OUT)
  print "LED on"
  GPIO.output(17,GPIO.HIGH)
  time.sleep(1)
  print "LED off"
  GPIO.output(17,GPIO.LOW)
  </code></pre>
  
  <p>I have a python script called nano.py located at:
  /var/www/html/nano.py      (-rwxrwxrwx 1 pi www-data 236 Jan 26 13:12 nano.py)
  and
  /home/pi/nano.py           (-rwxr-xr-x 1 pi pi 225 Jan 26 13:19 nano.py)
  the scripts are both the same:</p>
  
  <pre><code>&lt;?php
      echo shell_exec("python /var/www/html/nano.py");
  ?&gt;
  </code></pre>
  
  <p>I tried many things, but I can't execute nano.py from my PHP page:</p>
  
  <ul>
  <li>tried different paths(/var/www/html/nano.py /home/pi/nano.py nano.py)</li>
  <li>tried shell_exec, exec </li>
  <li>tried different python paths (python /usr/bin/python)</li>
  </ul>
  
  <p>I tried giving apache sudo access:</p>
  
  <pre><code>www-data ALL=(ALL) NOPASSWD:ALL
  </code></pre>
  
  <p>I don't really know what other options I have,
  So I hope someone can help me.</p>