[Ubuntu] Lighttpd

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
Introduction

So you just got your VPS and thinking "Now what?". In this tutorial I will show you how to get lighttpd running and how to configure it. Lighttpd is a web server similar to apache. Only it uses less system resources. This tutorial will be released in multiple parts. It is written for Ubuntu but may work on other operating systems.
This tutorial assumes that you know how to log into ssh. Anything written in italics is something you should run in the terminal.

Requirements

Nano - apt-get install nano
Cron - apt-get install cron

Stuff you might want to know

To save a file in nano, type ctrl - x, y, enter.
You should not have anything installed that is using port 80.
This tutorial is written for Ubuntu.

Part 1 - Installing Lighttpd

Installation is very simple. Simply run apt-get install lighttpd. Once that finishes you have a fully working lighttpd! Check http://yourvpsip and you should get a page similar to the one at http://server.fyepro.com/. If it doesn't work, make sure you don't have anything else running on port 80 such as apache.

Part 2 - Installing PHP
So now you've got lighttpd running. Time to install PHP. If you don't need php, just skip this. We are going to use FastCGI to provide php support. To start, run apt-get install php5-cgi.
Now we need to edit the php configuration file. Run nano /etc/php5/cgi/php.ini. At the end of that file add
Code:
cgi.fix_pathinfo = 1
Now we need to enable FastCGI in lighttpd. To do so, run nano /etc/lighttpd/lighttpd.conf. Now look for
Code:
server.modules              = (
Directly underneath that add
Code:
            "mod_fastcgi",
Now add
Code:
fastcgi.server = ( ".php" => (( 
                     "bin-path" => "/usr/bin/php5-cgi",
                     "socket" => "/tmp/php.socket"
                 )))
to the end of the file.
Now you are almost done! Just run /etc/init.d/lighttpd restart to restart lighttpd and php is good to go!
For php modules, check out http://packages.ubuntu.com/search?suite=hardy&searchon=names&keywords=php5-
Install them using apt-get install [packageName] and then restart lighttpd using nano /etc/lighttpd/lighttpd.conf.
Only install the ones you need! Installing ones you don't need will take up unnecessary RAM.

Part 3 - Using multiple domains

In this part I will be explaining how to use more than one domain. Similar to parked and addon domains in cPanel. If you are going to use more than one domain, I recomend you keep your sites out of the root /var/www/. Helps keep things neater. But that's up to you. In this tutorial I will assume that you are putting your sites in a subfolder of the /var/www/ folder. You can put them elsewhere but you need to mess with permission stuff which I wont cover here. Now to get started.
First, open your lighttpd config file with the command nano /etc/lighttpd/lighttpd.conf. Now add the code below to the end of the file. I'll explain what it all means shortly.
Code:
$HTTP["host"] == "SITEURL" {
  server.document.root = "/var/www/FOLDER/"
}
Replace SITEURL with the domain of your site. Replace FOLDER with the folder you put the files in. Make sure you keep the last /. If you need any other special configurations for that domain (they will be covered later) add them before the }.

Up Next: Redirects & Rewrites

Notes and references
PHP Installation
MySQL setup will also be covered in a different tutorial. However, I need to finish optimizing my MySQL server first.
 
Last edited:

Nathan H

New Member
Messages
562
Reaction score
0
Points
0
For those not on ubunto much of this tutorial will still apply because apt-get will also (normaly) download everything else (dependancies) needed. For those who cannot get apt-get to work, you might be on a slightly different type of shell, use yum instead of apt-get and it should work
 
Top