How to Install Lighttpd With PHP5 (PHP-FPM) and MySQL on CentOS 6.5

Lighttpd (pronounced “lighty”) is an open-source web server as an alternative to Apache and Nginx. It is a secure, flexible, fast and designed for speed-critical environments. It has a low memory footprint and can handle large number of connections in one server especially for busier sites.

PHP is an acronym for “PHP Hypertext Preprocessor”; PHP is a widely-used server-side scripting language executed on the server.

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.

MySQL is a popular database solution for use in web applications.

This post will show you how to install Lighttpd With PHP5 (PHP-FPM) and MySQL on CentOS 6.5 VPS or dedicated server.

1. EPEL repository is another extra repository that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux, including, but not limited to, Red Hat Enterprise Linux (RHEL) and CentOS server. How to Configure EPEL Repository on CentOS.

2. Install Lighttpd, MySQL and PHP5 work in Lighttpd through PHP-FPM :

[root@centos6-05 ~]# yum install lighttpd php php-fpm lighttpd-fastcgi php-mysql mysql mysql-server -y

3. Configure Lighttpd :

[root@centos6-05 ~]# vi /etc/lighttpd/lighttpd.conf
server.use-ipv6 = "enable"

Change to :

server.use-ipv6 = "disable"

4. Make lighttpd start at boot and also start lighttpd service:

[root@centos6-05 ~]# chkconfig --levels 235 lighttpd on
[root@centos6-05 ~]# /etc/init.d/lighttpd start

Browse your web server and Lighttpd welcome page should be displayed :
lighttpd-centos6.5-1

5. Configure PHP to work in Lighttpd through PHP-FPM :

[root@centos6-05 ~]# vi /etc/php-fpm.d/www.conf

Enable PHP-FPM use a TCP connection instead of unix socket :

;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000

Configure user and group to lighttpd :

..
..
; RPM: apache Choosed to be able to access some dir as httpd
user = lighttpd
; RPM: Keep a group allowed to write in log dir.
group = lighttpd
..
..

6. Make php-fpm start at boot and also start the php-fpm service :

[root@centos6-05 ~]# chkconfig --levels 235 php-fpm on
[root@centos6-05 ~]# /etc/init.d/php-fpm start

7. Open and modify /etc/php.ini :

[root@centos6-05 ~]# vi /etc/php.ini

Uncomment the line cgi.fix_pathinfo=1

..
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
cgi.fix_pathinfo=1
..

8. Open and modify /etc/lighttpd/modules.conf :

[root@centos6-05 ~]# vi /etc/lighttpd/modules.conf

Uncomment the line include “conf.d/fastcgi.conf”:

..
## FastCGI (mod_fastcgi)
##
include "conf.d/fastcgi.conf"
..

9. Open and modify /etc/lighttpd/conf.d/fastcgi.conf :

Add below fastcgi.server at bottom of the file :

..
fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)
..

10. Reload the PHP-FPM and Lighttpd service :

[root@centos6-05 ~]# /etc/init.d/php-fpm reload
[root@centos6-05 ~]# /etc/init.d/lighttpd reload

11. Since MySQl has been install, dont forget to make MySQL start at boot and start the MySQL service :

[root@centos6-05 ~]# chkconfig --levels 235 mysqld on
[root@centos6-05 ~]# /etc/init.d/mysqld start

12. Create info.php under ligghttpd document root :

[root@centos6-05 ~]# vi /var/www/lighttpd/info.php
<?php
phpinfo();
?>

Browse your page http://IP-Adress/info.php. Thats all.

How to Configure Basic Setup for lighttpd on CentOS 6.3

lighttpd is a secure, fast, compliant, and very flexible web-server that has been optimized for high-performance environments. It has a very low memory footprint compared to other webservers and takes care of cpu-load. This post will show you the basic lighttpd setup on CentOS 6.3. Refer to previous post to install lighttpd.

1. Configure basic lighttpd setup :

[root@centos63 ~]# vi /etc/lighttpd/lighttpd.conf
..
..
var.log_root    = "/var/log/lighttpd"
var.server_root = "/var/www"
var.state_dir   = "/var/run"
var.home_dir    = "/var/lib/lighttpd"
var.conf_dir    = "/etc/lighttpd"
..
..
server.port = 80
..
..
server.use-ipv6 = "disable"
..
..
server.document-root = server_root + "/lighttpd"
..
..
server.max-connections = 512

2. To check your lighttpd.conf for Syntax error, you can use this command, it can helps to find any misconfigurations easily:

[root@centos63 ~]# lighttpd -t -f /etc/lighttpd/lighttpd.conf
Syntax OK

3. Start lighttpd service :

[root@centos63 ~]# /etc/init.d/lighttpd start
Starting lighttpd:                                         [  OK  ]

4. Stop lighttpd service :

[root@centos63 ~]# /etc/init.d/lighttpd stop
Stopping lighttpd:                                         [  OK  ]

5. Create a HTML test page and access to it with web browser :

[root@centos63 ~]# vi /var/www/lighttpd/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Lighttpd Test Page
</div>
</body>
</html>

How to Install lighttpd with Fastcgi on CentOS 6.3

This post will cover the step to install lighttpd with Fastcgi on CentOS 6.3. lighttpd is a secure, fast, compliant, and very flexible web-server that has been optimized for high-performance environments. It has a very low memory footprint compared to other webservers and takes care of cpu-load. Its advanced feature-set (FastCGI, CGI, Auth, Output-Compression, URL-Rewriting and many more) make lighttpd the perfect webserver-software for every server that suffers load problems.

Run the following command to install using yum :

[root@centos63 ~]# yum install lighttpd lighttpd-fastcgi -y

Example :

[root@centos63 ~]# yum install lighttpd lighttpd-fastcgi -y
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
 * base: mirror1.ku.ac.th
 * epel: mirror.nus.edu.sg
 * extras: mirror.issp.co.th
 * updates: mirror1.ku.ac.th
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package lighttpd.i686 0:1.4.31-1.el6 will be installed
---> Package lighttpd-fastcgi.i686 0:1.4.31-1.el6 will be installed
--> Processing Dependency: spawn-fcgi for package: lighttpd-fastcgi-1.4.31-1.el6.i686
--> Running transaction check
---> Package spawn-fcgi.i686 0:1.6.3-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package                       Arch              Version                    Repository         Size
====================================================================================================
Installing:
 lighttpd                      i686              1.4.31-1.el6               epel              296 k
 lighttpd-fastcgi              i686              1.4.31-1.el6               epel               45 k
Installing for dependencies:
 spawn-fcgi                    i686              1.6.3-1.el6                epel               16 k

Transaction Summary
====================================================================================================
Install       3 Package(s)

Total download size: 357 k
Installed size: 808 k
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 357 k
(1/3): lighttpd-1.4.31-1.el6.i686.rpm                                        | 296 kB     00:02
(2/3): lighttpd-fastcgi-1.4.31-1.el6.i686.rpm                                |  45 kB     00:00
(3/3): spawn-fcgi-1.6.3-1.el6.i686.rpm                                       |  16 kB     00:00
----------------------------------------------------------------------------------------------------
Total                                                               112 kB/s | 357 kB     00:03
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : lighttpd-1.4.31-1.el6.i686                                                       1/3
  Installing : spawn-fcgi-1.6.3-1.el6.i686                                                      2/3
  Installing : lighttpd-fastcgi-1.4.31-1.el6.i686                                               3/3
  Verifying  : lighttpd-fastcgi-1.4.31-1.el6.i686                                               1/3
  Verifying  : spawn-fcgi-1.6.3-1.el6.i686                                                      2/3
  Verifying  : lighttpd-1.4.31-1.el6.i686                                                       3/3

Installed:
  lighttpd.i686 0:1.4.31-1.el6                 lighttpd-fastcgi.i686 0:1.4.31-1.el6

Dependency Installed:
  spawn-fcgi.i686 0:1.6.3-1.el6

Complete!

To start lighttpd, run the following command :

[root@centos63 ~]# /etc/init.d/lighttpd start

To stop lighttpd, run the following command :

[root@centos63 ~]# /etc/init.d/lighttpd stop

How to Install and Configure Lighttpd on CentOS 6.2

The Lighttpd is an open-source web server more optimized for speed-critical environments than common products while remaining standards-compliant, secure and flexible. Lighttpd is an excellent tool for small to medium sized web sites. It is a web server for Linux/UNIX and Windows operating systems platform and is an alternative to Apache web server. In this post, i will show on how to setup Lighttpd on linux CentOS 6.2 server.

1. Install and configure PMforge Repository on CentOS 6.2 :
How to Add the RPMforge Repository on CentOS 6/RHEL 6 Linux Server

2. Install lighttpd using yum command :

[root@centos62 ~]# yum install lighttpd -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ipserverone.com
 * extras: centos.ipserverone.com
 * rpmforge: ftp-stud.fht-esslingen.de
 * updates: centos.ipserverone.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package lighttpd.i686 0:1.4.28-2.el6.rf will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package               Arch              Version                        Repository             Size
====================================================================================================
Installing:
 lighttpd              i686              1.4.28-2.el6.rf                rpmforge              706 k

Transaction Summary
====================================================================================================
Install       1 Package(s)

Total download size: 706 k
Installed size: 2.6 M
Downloading Packages:
lighttpd-1.4.28-2.el6.rf.i686.rpm                                            | 706 kB     00:08
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : lighttpd-1.4.28-2.el6.rf.i686                                                    1/1

Installed:
  lighttpd.i686 0:1.4.28-2.el6.rf

Complete!

3. Configure Lighttpd starts automatically when boot up :

[root@centos62 ~]# chkconfig --levels 235 lighttpd on

or

[root@centos62 ~]# chkconfig lighttpd on

4. Open /etc/lighttpd/lighttpd.conf :

[root@centos62 ~]# vi /etc/lighttpd/lighttpd.conf

Make sure server.use-ipv6 is set to “disable” :

##
## Use IPv6?
##
server.use-ipv6 = "disable"

5. The server.document-root is located at /srv/www/lighttpd. Upload or create the following index.html to test your web server :

[root@centos62 ~]# vi /srv/www/lighttpd/index.html

Add this html code into index.html

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Lighttpd Test Page on CentOS 6.2
</div>
</body>
</html>

6. Start lighttpd :

[root@centos62 ~]# /etc/init.d/lighttpd start
Starting lighttpd:                                         [  OK  ]

7. Browser your server ip address :
http:server_ip_address
Lighttpd