Running a web server

For my future reference1 I shall describe how to set up and configure a lighttpd web server, running as a process, for blisteringly-rapid local web page serving. I've now been running lighttpd on Raspberry Pi devices for the last couple of years to host the internal variant (a superset) of my external 'molehole' web pages.

Start...

... simply by installing the lighttpd package ...

lighttpd

... which takes about 10 seconds. On my Mint 17.2 system the webserver immediately sprang into life serving its placeholder web page from the URL "localhost" (or 127.0.0.1). If you point your web browser there, that's what you'll initially see:

Browsing localhost

Visual evidence of a successful installation. I can also browse from other devices on my LAN by specifying BlackBeast's IP address, of course, instead of "localhost".

The only "wrinkle" in...

... my set-up from a standard "out-of-the-box" installation is that (being a Neanderthal) I still use Server Side Includes. I must therefore add two lines to the default lighttpd.conf configuration file that's in /etc/lighttpd

server.modules = (
	"mod_access",
	"mod_alias",
	"mod_ssi",   <=== insert this
	"mod_compress",
 	"mod_redirect",
#       "mod_rewrite",
)

index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
ssi.extension               = ( ".shtml" )   <=== insert this

I found out the hard way (when repeating this exercise on Mint 17.2) that the order of the server.modules actually matters. (This isn't the complete file, by the way. And you'll need root access to make these edits.)

Four steps remain...

... and I'm indebted to Len for the finer points of groups, ownership, and permissions. The owner of the web files (erm, me) needs to have read / write access to all the web page files in the filespace that lighttpd is serving them from (namely /var/www)

1. add yourself as a member of the group (www-data) that can read and write files to the playspace that lighttpd will have set up in its DocumentRoot at /var/www

sudo adduser david www-data

2. set ownership (chown) and access permissions (chmod) for this www-data group to the local web files that lighttpd will be serving. I keep my local web files in a directory called "webfiles" in my /home top level file space so I need to change to that directory first, then run the 'chown' and 'chmod' commands respectively:

cd ~/webfiles
sudo chown -R www-data:www-data *
sudo chmod -R 775 *

3. now remove the existing www and placeholder index.html that lighttpd initially set up

sudo rm -rf /var/www

4. finally, set up a symbolic link to point to where my web page files actually live (in /home/david/webfiles remember) to let Linux "fool" lighttpd's hard-wired determination to look for them in /var/www

sudo ln -s /home/david/webfiles /var/www

Now just point your web browser at "localhost" and away you go.


Footnote

1  A code phrase whose true meaning is "next time I do something silly and have to re-install Linux from scratch".