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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.