Installing lighttpd Web Server in Linux with PHP and MySQLBy Binny V A • Nov 10th, 2008 • Category: Linux, PHP, Tutorials, Web Development
After two articles on installing Apache, lets take a look at installing and configuring lighttpd web server on a linux system. lighttpd (pronounced “lighty”) is a web server designed to be secure, fast, standards-compliant and flexible while having a low memory footprint.
Before installation, a few points to remember. These instruction are not for a production environment – this is for a development environment. To install the software, you need root access. You can get that using this command…
su - [Enter root password]
or by prefixing ‘
sudo‘ before each command.
Installing the Server
First install lighttpd and PHP – use your distro’s package management(yum, apt-get) system to do this.
You can use this command in Red Hat based systems(Fedora, Cent OS, etc.) to install lighttpd. Debian/Ubuntu systems might the same package name – could someone post the package name of lighttpd in the comments?
yum install lighttpd lighttpd-fastcgi
If you don’t have PHP, you can install it using the command…
yum install php php-cli php-common
In Debian/Ubuntu systems, the command is…
apt-get install php5-cli php5-common php5-cgi
You can make sure you have php-cgi(needed for working with lighttpd) by running this command…
If MySQL is not yet installed, use this command to install it…
yum install mysql-server php-mysql mysql mysql-libs
apt-get install mysql-client mysql-common mysql-server php5-mysql
lighttpd configuration is done by editing the text file ‘/etc/lighttpd/lighttpd.conf’.
Enable some lighttpd modules by removing the comment character(#) from the beginning of the line. I have enabled the following modules…
server.modules = ( "mod_rewrite", "mod_redirect", "mod_access", "mod_fastcgi", "mod_accesslog" )
Configure lighttpd’s document root – if you already have Apache, I would recommend using the same document root as Apache(applicable for development servers only).
server.document-root = "/var/www/"
I find it helpful to enable folder listing in my server.
## virtual directory listings dir-listing.activate = "enable"
Turn On FastCGI PHP Support
Now, make sure lighttpd works with PHP – first get the path of php-cgi using the command..
$ whereis php-cgi php-cgi: /usr/bin/php-cgi #Might be different on your system.
Then add the path to the configuration file of lighttpd…
#### fastcgi module ## read fastcgi.txt for more info ## for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini fastcgi.server = ( ".php" => ( "localhost" => ( "socket" => "/tmp/php.socket", "bin-path" => "/usr/bin/php-cgi" ) ) )
Make sure you uncomment the above lines by removing the ‘#’ characters.
After you are done, save the file. Time to try out the server.
Starting the lighttpd Server
First stop Apache if it is running…
Now start lighttpd using the command
Go to your document root(
/var/www) and create a php files called ‘info.php’ and put this code inside it…
Now fire up a browser and go to localhost – you should see a file listing page with a ‘info.php’ in the list. Click on that link – if you see a PHP information page, your web server is setup correctly.
To make sure MySQL-PHP connection is working, install phpMyAdmin – or write a database connection script – whatever is easier for you.
- lighttpd fly light
- lighttpd – Wikipedia
- Lighttpd install perl, mysql support in chrooted jail
- Lighttpd PHP fastcgi configuration
- FreeBSD Install Lighttpd Web Server
- Install lighttpd with php
- Install and Configure lighttpd
- Installing Lighttpd With PHP5 And MySQL Support On Fedora 7
Shameless Plug: If you are a Linux user, you may want to check out my Linux Blog – LinDesk – its about Linux on the Desktop – Articles, Application Reviews and Tutorials about many aspects of Linux included configuration and scripting.