Single user server with lighttpd
On Linux, a web server is usually installed and run in the background as a system service, but you can run one as a normal user too. There are a few reasons why you may want to do this. If you only need to run a server occasionally to test some code, then keeping the server running in the background all the time is a bit overkill. Also, if the code you want to test resides in an encrypted directory, programs running with a UID different from the user who mounted the directory may not be able to access the files.
For this tutorial, I chose lighttpd for it’s light resource usage and ease of configuration. A look at the man page reveals that lighttpd can be called with the
-f option, which allows a configuration file to specified. Here are the basic steps:
- Make a directory called .lighttpd.
- Find the system configuration file and copy it to your newly created .lighttpd directory. On my laptop (Debian 7.0/CrunchBang 11), the system configuration file is /etc/lighttpd/lighttpd.conf. If this is not the case for you, then consult the documentation for your chosen distribution.
- Edit the configuration file:
- Change the port to something above 2000.
- Make all relevant paths in the file point to your .lighttpd directory.
- Comment out all of the lines that start with “include_shell” (without the quotes) except the one containing create-mime.assign.pl1
- Copy the contents of the dir_listing and userdir files into your modified configuration file. On my system, I found them in /etc/lighttpd/conf-available/.
- Fire up lighttpd with this command:
lighttpd -f .lighttpd/lighttpd.conf.
Here’s the configuration file I use on my system.
Looking at the above, I thought that “include-conf-enabled.pl” would work. That file allows you to enable different features just by making a symbolic link in the conf-enabled directory to the corresponding file in the conf-available directory. Unfortunately, it didn’t work for me, so I had to copy the file contents instead. Once you start the server, it will remain running until you kill the process (
1 If this line is commented out, lighttpd will not “serve” the pages. Instead of a rendered page, you will get a prompt to download the file. The same thing may also happen to server-side scripts.