0

I have installed lighttpd on the Pi, and configured it to run web.py using fastcgi. Accessing python scripts from the browser works. But when I add the code to access GPIO, it fails with the following:

RuntimeError: No access to /dev/mem. Try running as root! Traceback (most recent call last): File "/var/www/index.py", line 134, in

  GPIO.setup(17, GPIO.OUT);#enable A RuntimeError: No access to /dev/mem.  Try running as root!</p>

I have added lighttpd to the sudoers file using the visudo command. But still, it won't work. Any suggestions?

Here is my lighttpd config file:

> server.modules = (
>     "mod_access",
>     "mod_alias",
>     "mod_compress",
>     "mod_accesslog", )
> 
> server.document-root        = "/var/www" server.upload-dirs          =
> ( "/var/cache/lighttpd/uploads" ) server.errorlog             =
> "/var/log/lighttpd/error.log" server.pid-file             =
> "/var/run/lighttpd.pid" server.username             = "www-data"
> server.groupname            = "www-data"
> 
> 
> ## Use ipv6 if available
> #include_shell "/usr/share/lighttpd/use-ipv6.pl"
> 
> 
> compress.cache-dir          = "/var/cache/lighttpd/compress/"
> compress.filetype           = ( "application/x-javascript",
> "text/css", "text/html", "text/plain" )
> 
> include_shell "/usr/share/lighttpd/create-mime.assign.pl"
> include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
> 
> server.modules   += ( "mod_fastcgi" ) server.modules   += (
> "mod_rewrite" )
> 
>  fastcgi.server = ( "/index.py" =>  ("/" => ( "socket" =>
> "/tmp/fastcgi.socket",
>     "bin-path" => "/var/www/index.py",
>     "max-procs" => 1,    "bin-environment" => (
>      "REAL_SCRIPT_NAME" => ""    ),    "check-local" => "disable"  ))  )
> 
>  url.rewrite-once = (    "^/favicon.ico$" => "/static/favicon.ico",   
> "^/static/(.*)$" => "/static/$1",    "^/(.*)$" => "/index.py/$1",  )
yogur
  • 111
  • 5

3 Answers3

1

make sure you enable Remote gpio from Application Menu > Preferences > Raspberry Pi Configuration > Interfaces > Enable Remote GPIO

1

I solved it using this:

I was not aware that Jessie does not require root to access GPIO. So I upgraded to Raspbian Jessie following the steps on this guide:

https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=121880

And then I fixed GPIO permissions using this answer:

Access GPIO pins without root. No access to /dev/mem. Try running as root!

Now lighttpd no longer requires root access to run the python scripts.

yogur
  • 111
  • 5
0

To elaborate on yogur's answer. All you need to do is:

sudo adduser www-data gpio

This will add the www-data user (used by lighttpd) to the gpio group. Then restart lighttpd and you are done:

sudo /etc/init.d/lighttpd restart
Yoni Baciu
  • 101
  • 1
  • This is no longer required on Raspbian Jessie. GPIO no longer requires super user permissions. – yogur Dec 27 '16 at 06:47