0

lighttpd – Changing default user (Raspberry Pi)

After following the great tutorial here (http://www.penguintutor.com/linux/light-webserver) for getting lighttpd setup and running on my Raspberry Pi, I wanted to change the default user the service ran as so I could run commands from php scripts requiring more permissions.

The part I got stuck on was that on a reboot, the folder in /var/run/lighttpd would be re-created with permissions for only the www-data user and not ‘pi’ which I had changed the service to run as. So below are the full steps I had to go through to change the default user and everything is now working nicely, even after a reboot. (Skip to step 5 for this fix).

1) Ensure the service is stopped:

sudo service lighttpd stop 

2) Modify /etc/lighttpd/lighttpd.conf to change the default user. Change ‘www-data’ to ‘pi’ or whatever user you want to change it to. For the rest of this guide, I’ll be using pi.

sudo nano /etc/lighttpd/lighttpd.conf

Ctrl+X then Y and hit enter with nano to save the changes.

3) Modify /etc/init.d/lighttpd. Change ‘www-data’ to ‘pi’.

sudo nano /etc/lighttpd/lighttpd.conf
        from: install -d -o www-data -g www-data -m 0750 "/var/run/lighttpd" 
          to: install -d -o pi -g pi -m 0750 "/var/run/lighttpd"

4) Then we can modify the owner and permissions of existing folders, run each of these commands:

sudo chown -R pi:pi /var/log/lighttpd
sudo chown -R pi:pi /var/run/lighttpd
sudo chown -R pi:pi /var/cache/lighttpd

5) Modify /usr/lib/tmpfiles.d/lighttpd.tmpfile.conf and change www-data to pi. This is the part which was stopping it from working for me after a reboot.

sudo nano /usr/lib/tmpfiles.d/lighttpd.tmpfile.conf
          from: d /var/run/lighttpd 0750 www-data www-data -
          to: d /var/run/lighttpd 0750 pi pi -

6) Save the file then reboot.

sudo reboot

If you’re still having issues, look into the following log files to see why it’s failing to startup lighttpd:
(to go to the bottom of a file open in ‘nano’ hit CTRL + _ (that’s ctrl + underscore) and then CTRL + V):

sudo nano /var/log/syslog
sudo nano /var/log/lighttpd/error.log

I also had run the following commands prior to me getting it working so I’m unsure if these will help:

sudo usermod -a -G www-data pi
sudo usermod -a -G pi www-data

Hope this helps someone else out there, took my ages to get it working properly after a reboot.