Raging Penguin

The random ramblings of a Linux geek

mobile menu button

Single user server with lighttpd

2013-06-19 by TuxRag3r, tagged as tutorials

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:

  1. Make a directory called .lighttpd.
  2. 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.
  3. 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
  4. Optional:
    • 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/.
  5. Fire up lighttpd with this command: lighttpd -f .lighttpd/lighttpd.conf.

Example configuration

Here’s the configuration file I use on my system.

server.modules = (
#       "mod_rewrite",

server.document-root        = "/home/tuxrag3r/www"
server.upload-dirs          = ( "/home/tuxrag3r/.lighttpd/cache/lighttpd/uploads" )
server.errorlog             = "/home/tuxrag3r/.lighttpd/error.log"
server.pid-file             = "/home/tuxrag3r/.lighttpd/lighttpd.pid"
server.username             = "phoenix"
server.groupname            = "phoenix"
server.port                 = 3000

# directory listing
dir-listing.encoding = "utf-8"
server.dir-listing   = "enable"

index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/home/tuxrag3r/.lighttpd/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
#include_shell "/home/tuxrag3r/.lighttpd/use-ipv6.pl " + server.port
include_shell "/home/tuxrag3r/.lighttpd/create-mime.assign.pl"
#include_shell "/home/tuxrag3r/.lighttpd/include-conf-enabled.pl"

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 (pkill lighttpd).

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.

comments powered by Disqus

Built with Vim, The GIMP, and BlazeBlogger.

Valid HTML5