Archive for the ‘Webserver’ Category

lighttpd

December 11, 2006

This is a summary of what I went through to get the web server lighttpd up and running on my Fedora Core 5 Linux machine at work.

Since I am using Fedora Core 5 it was a simple process to get the basic software to get started.

# yum install lighttpd

Once it was downloaded and installed I simply had to turn it on.

# /etc/init.d/lighttpd start; chkconfig lighttpd on

That second part is there to make sure if the server reboots lighttpd will come back on.

At this point the lighttpd server can already serve out static html pages. The document root was located at /srv/www/lighttpd … by the way, I really like their simple, elegant logo.

Anyway, my first obvious task after installation was to configure this web server to handle PHP. I was a little intimidated when I discovered that I would have to install PHP from source with special flags so that PHP would use the lighttpd-fastcgi module. With this webserver, PHP works by using this special module. I spent some time at the fast-cgi module website , but found that installing on Fedora Core 5 was as simple as:

# yum install lighttpd-fastcgi

Once I had installed this module, I had to uncomment the section in the webserver config file so that the module would load. This is fairly simple. Just open the /etc/lighttpd/lighttpd.conf file in your favorite text editor (vim!), and uncomment the line where you find fast-cgi. Once this is uncommented you can write and quit the file, and then restart the lighttpd service, as shown:

# /etc/init.d/lighttpd restart

The next step is to compile PHP. Be careful that you have all the compilers and libraries installed on your machine before attempting to compile your own binary. On my machine, I didn’t even have gcc installed, so I had to make sure all those programming tools were downloaded and installed. I won’t get into all that detail here.

Installing the PHP is fairly straightforward.

# ./configure \
--enable-fastcgi \
--enable-discard-path \
--enable-force-redirect

Once the configuration is finished, then you have to make it.

# make

and finally…

# make install

Once the PHP was installed, and the /etc/lighttpd/lighttpd.conf configured to use the fast-cgi module, I was then able to serve out PHP pages.

My next project after getting the PHP to work was to make sure that I could host multiple domains with this web server. This required figuring out how to do virtual domains. It took me half a day to figure out how to do this in this lighttpd.conf file, but when I figured it out I found it to be a simple and elegant way of handling virtual hosts. In Apache every virtual host container has to be spelled out in the config file, but not in lighttpd. In lighttpd all you have to spell out is where to go if a request does not match a domain in the default document root folder. Here is the snippet of code that I used in my lighttpd.conf:

#all other reqs go here
simple-vhost.server-root = "/srv/www/"
simple-vhost.default-host = "scully.sunlitsurf.com"
simple-vhost.document-root = "pages"

If you notice there, the default virtual host server root is the path /srv/www. All you have to do to add new domains to this server is simply add directories that are domain names underneath there. For example, rather than adding my mikewriting.com domain into the config file, I simply created a folder or subdirectory underneath /srv/www of mikewriting.com. Now, whenever the server receives a request for that domain, it automatically serves out the pages in that folder. In order to accommodate those who type in the www sub-domain I simply created a symbolic link of www.mikewriting.com that pointed back to mikewriting.com. It was so simple! It took me a long time to understand it.

I hope this brief summary of my adventure into lighttpd has helped you on your way.