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

Share this Article :

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 :

[[email protected] ~]# yum install lighttpd php php-fpm lighttpd-fastcgi php-mysql mysql mysql-server -y

3. Configure Lighttpd :

[[email protected] ~]# 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:

[[email protected] ~]# chkconfig --levels 235 lighttpd on
[[email protected] ~]# /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 :

[[email protected] ~]# 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 :

[[email protected] ~]# chkconfig --levels 235 php-fpm on
[[email protected] ~]# /etc/init.d/php-fpm start

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

[[email protected] ~]# 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 :

[[email protected] ~]# 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 :

[[email protected] ~]# /etc/init.d/php-fpm reload
[[email protected] ~]# /etc/init.d/lighttpd reload

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

[[email protected] ~]# chkconfig --levels 235 mysqld on
[[email protected] ~]# /etc/init.d/mysqld start

12. Create info.php under ligghttpd document root :

[[email protected] ~]# vi /var/www/lighttpd/info.php
<?php
phpinfo();
?>

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

Leave a Reply