Install Lighttpd with MySQL5 and PHP5(PHP-FPM) Support on RHEL/CentOS 6.3/5.8
In our earlier web-server guides we’ve shown you how we’ve installed Apache with MySQL 5 and PHP5 and Nginx with MySQL5 and PHP5 (PHP-FPM). Here, in this tutorial we’ll show you how to install Lighttpd with MySQL 5 and PHP 5 (PHP-FPM) support on a RHEL/CentOS 6.3/5.8 systems. We do not issue any guarantee that it will work for you as it worked for us. Before heading up to installation, We would like to give a little about Lighttpd and PHP-FPM, We assume that you are already aware of MySQL and PHP.
What Is Lighttpd?
Lighttpd is an most popular open source secure, fast, flexible and more optimized web server designed for speed-critical environments. It can handle up-to 10,000 connections parallel in one server. More information can be found at http://www.lighttpd.net/.
What Is PHP-FPM?
PHP-FPM (FastCGI Process Manager) is an open source alternative module for PHP FastCGI implementation with extra features for busy servers. For more information visit http://php-fpm.org/.
Install Lighttpd with MySQL5 and PHP5(PHP-FPM) on RHEL/CentOS 6.3/5.8
Step 1: Installing Remi and Epel Repositories
By default Lighttpd package not available under RHEL/CentOS 6.3/5.8 official repositories. So, here we are using third-party Remi and Epel repositories to install it. Please choose correct repository for your operating system.
## Epel Dependency on RHEL/CentOS 6.3/6.2/6.1/6.0 ## # wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm # rpm -Uvh epel-release-6-7.noarch.rpm ## Remi Dependency on RHEL/CentOS 6.3/6.2/6.1/6.0 ## # wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm # rpm -Uvh remi-release-6.rpm ## Epel Dependency on RHEL/CentOS 5.8 ## # wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm # rpm -Uvh epel-release-5-4.noarch.rpm ## Remi Dependency on RHEL/CentOS 5.8 ## # wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm # rpm -Uvh remi-release-5.rpm
Step 2: Installing Lighttpd on RHEL/CentOS 6.3/5.8
Once you’ve installed selected repositories on your system, now install Lighttpd by running following command.
# yum install lighttpd
Create system start-up links for Lighttpd. So, whenever system boots it also starts Lighttpd automatically on system start-up. So, don’t need to start it manually.
# chkconfig --levels 235 lighttpd on # /etc/init.d/lighttpd start
If you get any similar to below error message while starting up Lighttpd. You need to fix few things to get it start properly without displaying any error messages.
(network.c.203) socket failed: Address family not supported by protocol Starting lighttpd: 2012-08-17 15:53:12: (server.c.915) can't have more connections than fds/2: 1024 1024
Open the file called /etc/lighttpd/lighttpd.conf with any editor.
# vi /etc/lighttpd/lighttpd.conf
Change the line that says server.use-ipv6 from enable to disable. It will fix first error message shown above.
## ## Use IPv6? ## server.use-ipv6 = "disable"
Un-comment the following line it will fix second error message.
## With SELinux enabled, this is denied by default and needs to be allowed ## by running the following once : setsebool -P httpd_setrlimit on server.max-fds = 2048
Now try again to start Lighttpd, it should work 100% without any error messages.
/etc/init.d/lighttpd start Starting lighttpd: [ OK ]
The default document root directory for Lighttpd is /var/www/lighttpd/ and the main configuration file is located under /etc/lighttpd/lighttpd.conf. Open your browser and type the following any URL, you will see similar to below page.
http://localhost/ OR http://YOUR-IP-HERE/
Step 3: Installing MySQL 5 on RHEL/CentOS 6.3/5.8
Next, install MySQL 5 support for Lighttpd. Just execute following command on the terminal it will automatically install MySQL 5.
# yum --enablerepo=remi,remi-test install mysql mysql-server
Create system boot start-up links for MySQL too, So, whenever system boots it will automatically start MySQL.
# chkconfig --levels 235 mysqld on # /etc/init.d/mysqld start
Try connecting to MySQL server with following command on the terminal.
# mysql -u root -p
Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 1052 Server version: 5.5.27 MySQL Community Server (GPL) by Remi Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql>
Step 4: Installing PHP 5 on RHEL/CentOS 6.3/5.8
Install PHP 5 support for Lighttpd. Run the whole command on the terminal, it will download and install PHP 5 with their required packages. The command might takes some time to complete the installation.
# yum --enablerepo=remi,remi-test install php-gd php-xml php-cli php-pear php-pdo php-imap php-ldap php-odbc php-xmlrpc
Step 4: Installing PHP5 (PHP-FPM) with FastCGI for Lighttpd
Once PHP 5 installed, now enable PHP-FPM and FastCGI support for Lighttpd, to do this you need to install these packages too.
# yum --enablerepo=remi,remi-test install php-fpm lighttpd-fastcgi
Now open a file called /etc/php-fpm.d/www.conf.
# vi /etc/php-fpm.d/www.conf
Set the user and group to lighttpd.
; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. ; 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
Create system start up links for PHP-FPM service.
# chkconfig --levels 235 php-fpm on # /etc/init.d/php-fpm start
Step 5: Enabling PHP5 (PHP-FPM) in Lighttpd
Here, we need to modify three files /etc/php.ini, /etc/lighttpd/lighttpd.conf and /etc/lighttpd/modules.conf to enable PHP5 support for Lighttpd. Open first file.
# vi /etc/php.ini
Un-comment the following line that says 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://php.net/cgi.fix-pathinfo cgi.fix_pathinfo=1
Then open second file called /etc/lighttpd/lighttpd.conf.
# vi /etc/lighttpd/modules.conf
Un-comment the following line that says include “conf.d/fastcgi.conf”.
## ## FastCGI (mod_fastcgi) ## include "conf.d/fastcgi.conf"
Next, open third file called /etc/lighttpd/conf.d/fastcgi.conf.
# vi /etc/lighttpd/conf.d/fastcgi.conf
Now add the following container at the bottom of the file and save it.
fastcgi.server += ( ".php" => (( "host" => "127.0.0.1", "port" => "9000", "broken-scriptfilename" => "enable" )) )
Restart the Lighttpd service to reflect changes and enable PHP5 support.
# /etc/init.d/lighttpd restart
Step 7: Enabling MySQL 5 in Lighttpd
Enable MySQL 5 support for PHP and Lighttpd by installing following packages.
# yum --enablerepo=remi,remi-test install php-mysql php-pecl-apc
Now restart the PHP-FPM and Lighttpd service.
# /etc/init.d/php-fpm reload # /etc/init.d/lighttpd reload
Step 8: Testing PHP5 (PHP-FPM) in Lighttpd
As We said above that the default document root for Lighttpd is /var/www/lighttpd/. So, here we will create a phpinfo.php file into this directory.
# vi /var/www/lighttpd/info.php
Add the following lines to it. This small piece of code will display information about PHP installation with their versions.
Open your browser and naviage to the following links.
http://localhost/phpinfo.php OR http://YOUR-IP-HERE/phpinfo.php
You will see working information of PHP 5, PHP-FPM and MySQL 5 with lots of other modules that are already enabled.