I have installed lighttpd with fast-cgi on the raspberry pi. When running a python script that requires root priveleges, I get the following error:

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!

I have added www-data as a sudoer using visudo and "sudo usermod -a -G sudo www-data", but it did not work. How can I give lighttpd root priveleges? Security is NOT important as this is a personal project.

1 Answer 1


lighttpd doesn't use sudo. Therefore adding www-data to the sudoers group doesn't help.

You need to change the Web user in your config file from www-data to root:

server.username = "root"

You can leave the group at www-data if needed, but if you want, you can change that to root as well.

What you could do instead, though, is using sudo as www-data from your Python script. Make sure you set NOPASSWD.

In any case, running a web server as root (or with the ability to switch to any user for any command) is very bad practice as any vulnerability in the web server or any of the web application it serves means the full system could be totally compromised.

Here, most likely you'd want whatever operation needs to be done with /dev/mem to be performed by a dedicated utility that is setuid root (or is run via sudo) or by a separate service that is invoked by your web server.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .