CentOS Install Lighttpd Web-server With yum Command

Posted on in Categories , , last updated March 9, 2014

I know how to install nginx on a CentOS Linux using yum command. Is there is a guide to install Lighttpd web-server on a CentOS Linux or RHEL server with yum command? How can I install and configure php and mysql on a CentOS with Lighttpd web-server?

Lighttpd is a fast and secure web-server which has been optimized for high-performance environments. The server has a very low memory footprint compared to other webservers and takes care of cpu-load. It includes the following advanced features:

  1. FastCGI
  2. CGI
  3. Auth
  4. Output-Compression
  5. URL-Rewriting and more make

CentOS turn on EPEL repo

The lighttpd server is not part of default CentOS or RHEL based system. To install lighttpd using the yum command, first grab the latest epel release file, enter:
# wget http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm
Sample outputs:

--2014-02-23 12:24:52--  http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm
Resolving epel.mirror.net.in..., 2401:4800:2121:c0:ff:ee:ee:2
Connecting to epel.mirror.net.in||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14540 (14K) [application/x-redhat-package-manager]
Saving to: “epel-release-6-8.noarch.rpm”
100%[==========================================================================================>] 14,540      54.6K/s   in 0.3s    
2014-02-23 12:24:53 (54.6 KB/s) - “epel-release-6-8.noarch.rpm” saved [14540/14540]

Use rpm command to install downloaded epel-release-6-8.noarch.rpm file, type:
# rpm -ivh epel-release-6-8.noarch.rpm
Sample outputs:

warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]

CentOS Linux install Lighttpd web-server

Type the following yum command:
# yum install lighttpd lighttpd-fastcgi lighttpd-mod_geoip
Sample outputs:

Loaded plugins: downloadonly, fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirror.thelinuxfix.com
 * epel: mirror.steadfast.net
 * extras: holmes.umflint.edu
 * updates: bay.uchicago.edu
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package lighttpd.x86_64 0:1.4.34-1.el6 will be installed
---> Package lighttpd-fastcgi.x86_64 0:1.4.34-1.el6 will be installed
--> Processing Dependency: spawn-fcgi for package: lighttpd-fastcgi-1.4.34-1.el6.x86_64
---> Package lighttpd-mod_geoip.x86_64 0:1.4.34-1.el6 will be installed
--> Processing Dependency: libGeoIP.so.1()(64bit) for package: lighttpd-mod_geoip-1.4.34-1.el6.x86_64
--> Running transaction check
---> Package GeoIP.x86_64 0:1.4.8-1.el6 will be installed
---> Package spawn-fcgi.x86_64 0:1.6.3-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
 Package                Arch       Version             Repository
 lighttpd               x86_64     1.4.34-1.el6        epel     294 k
 lighttpd-fastcgi       x86_64     1.4.34-1.el6        epel      44 k
 lighttpd-mod_geoip     x86_64     1.4.34-1.el6        epel      21 k
Installing for dependencies:
 GeoIP                  x86_64     1.4.8-1.el6         epel     620 k
 spawn-fcgi             x86_64     1.6.3-1.el6         epel      16 k
Transaction Summary
Install       5 Package(s)
Total download size: 995 k
Installed size: 2.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): GeoIP-1.4.8-1.el6.x86_64.rpm            | 620 kB     00:00     
(2/5): lighttpd-1.4.34-1.el6.x86_64.rpm        | 294 kB     00:00     
(3/5): lighttpd-fastcgi-1.4.34-1.el6.x86_64.rp |  44 kB     00:00     
(4/5): lighttpd-mod_geoip-1.4.34-1.el6.x86_64. |  21 kB     00:00     
(5/5): spawn-fcgi-1.6.3-1.el6.x86_64.rpm       |  16 kB     00:00     
Total                                 1.7 MB/s | 995 kB     00:00     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
 Userid : EPEL (6) <[email protected]>
 Package: epel-release-6-8.noarch (installed)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : lighttpd-1.4.34-1.el6.x86_64                       1/5 
  Installing : GeoIP-1.4.8-1.el6.x86_64                           2/5 
  Installing : spawn-fcgi-1.6.3-1.el6.x86_64                      3/5 
  Installing : lighttpd-fastcgi-1.4.34-1.el6.x86_64               4/5 
  Installing : lighttpd-mod_geoip-1.4.34-1.el6.x86_64             5/5 
  Verifying  : lighttpd-1.4.34-1.el6.x86_64                       1/5 
  Verifying  : lighttpd-mod_geoip-1.4.34-1.el6.x86_64             2/5 
  Verifying  : spawn-fcgi-1.6.3-1.el6.x86_64                      3/5 
  Verifying  : GeoIP-1.4.8-1.el6.x86_64                           4/5 
  Verifying  : lighttpd-fastcgi-1.4.34-1.el6.x86_64               5/5 
  lighttpd.x86_64 0:1.4.34-1.el6                                      
  lighttpd-fastcgi.x86_64 0:1.4.34-1.el6                              
  lighttpd-mod_geoip.x86_64 0:1.4.34-1.el6                            
Dependency Installed:
  GeoIP.x86_64 0:1.4.8-1.el6      spawn-fcgi.x86_64 0:1.6.3-1.el6     

Turn on lighttpd server on a CentOS Linux for the first time, enter:
# service lighttpd start
# chkconfig lighttpd on

CentOS Linux install PHP

Type the following yum command to install php5.x and related modules on a CentOS Linux:
# yum install php-cli php-mbstring php-pecl-apc php-pdo php php-gd \
php-mysql php-xml php-bcmath php-xmlrpc php-pear php-common \
php-devel php-imap php-suhosin php-pecl-memcache

The php has been installed with MySQL database server, graphics (gd) library, and other most common modules.

CentOS Linux install MySQL database server

Type the following command to install mysql database server on a CentOS Linux based system using yum command:
# yum install mysql-server mysql
Turn on mysql server:
# chkconfig mysqld on
# service mysqld start

Set the root user password for mysql server admin account, type:
# mysqladmin -u root password NEWPASSWORDHERE

CentOS Linux Lighttpd web-server configuration

  1. Configuration directory: /etc/lighttpd/
  2. Main configuration file: /etc/lighttpd/lighttpd.conf
  3. Modules configuration file: /etc/lighttpd/modules.conf
  4. Modules and other config files directory: /etc/lighttpd/conf.d/
  5. Default DocumentRoot / Server root to store php/html/css/js files: /var/www/lighttpd/
  6. Default log directory: /var/log/lighttpd/

Configure lighttpd

Edit /etc/lighttpd/lighttpd.conf, enter:
# vi /etc/lighttpd/lighttpd.conf

Setting server root

Set it as follows to protect server root:

var.server_root = "/var/www"

Load the modules

Uncomment the following line:

include "modules.conf"

Set server port to 80

server.port = 80

Bind to a specific IP called

Set the following to your web-server public ip such as

server.bind = ""

Set document root

You are going to store html/images/js/php files in server_root + "/lighttpd" i.e. /var/www/lighttpd/ directory:

server.document-root = server_root + "/lighttpd"

Hide/set server tag

Set server name or hide it:

server.tag = "nixCraft-Web-Server"

Save and close the file.

Configure lighttpd modules

Edit /etc/lighttpd/modules.conf, enter:
# vi /etc/lighttpd/modules.conf

Configure php as fastcgi

Uncomment the following FastCGI (mod_fastcgi) line for php:

include "conf.d/fastcgi.conf"

Also make sure following is uncommted as per requirement :

server.modules = (
#  "mod_evasive",
#  "mod_setenv",
#  "mod_usertrack",

Configure php5

Edit /etc/lighttpd/conf.d/fastcgi.conf file, type:
# cp -v /etc/lighttpd/conf.d/fastcgi.{conf,bakup}
# vi /etc/lighttpd/conf.d/fastcgi.conf

Update it as follows to configure PHP and lighttpd with FastCGI:

## small server config ##
## For a large server set max-procs, PHP_FCGI_CHILDREN, and PHP_FCGI_MAX_REQUESTS as per your setup ##
server.modules += ( "mod_fastcgi" )
fastcgi.server    = ( ".php" =>
        "bin-path" => "/usr/bin/php-cgi",
        "socket" => "/tmp/php-cgi.socket." + var.PID,
        "max-procs" => 1,
        "idle-timeout" => 30,
        "bin-environment" => (
                "PHP_FCGI_CHILDREN" => "1",
                "PHP_FCGI_MAX_REQUESTS" => "50"
        "bin-copy-environment" => (
        "broken-scriptfilename" => "enable"

Save and close the file.

Restart the lighttpd

Type the following command to restart lighttpd server on a CentOS Linux:
# service lighttpd restart

Verify that everything is working

Make sure port 80 is opened and owned by lighttpd:
# netstat -tulpn | grep :80
Sample outputs:

tcp        0      0        *                   LISTEN      29085/lighttpd

Make sure no errors were reported in log file:
# tailf /var/log/lighttpd/error.log
Sample outputs:

2014-03-09 04:48:11: (server.c.1241) logfiles cycled UID = 0 PID = 30314 
2014-03-09 10:54:27: (server.c.1557) server stopped by UID = 0 PID = 4680 
2014-03-09 10:54:28: (log.c.166) server started 

Test it

Create a hello.php in /var/www/lighttpd/ directory:
# vi /var/www/lighttpd/hello.php
Append the following code:

<title>Hello - Lighttpd - PHP - nixCraft - Test</title>
<h1>Hosshin - Zen monk</h1>
Zen monk poem:
    $zen_poem  = '<blockquote><em>';
    $zen_poem .= "Coming, all is clear,<br>";
    $zen_poem .= "no doubt about it.<br>";
    $zen_poem .= "Going, all is clear,<br>";
    $zen_poem .= "without a doubt.<br>";
    $zen_poem .= "What, then, is it all?";
    $zen_poem .= "</em></blockquote>";
    echo $zen_poem;
<?php phpinfo(); ?>
<center><small>&copy; nixCraft</small></center>

Fire a web-browser and type url:


Sample outputs:

Fig. 01: PHP in action on a CentOS Lighttpd based server
Fig. 01: PHP in action on a CentOS Lighttpd based server

See also

And there you have it, the lighttpd+php+mysql configured on a CentOS Linux based server. I recommend that you read the following resource for more information:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment