How to Install Lighttpd With PHP FPM And MariaDB on CentOS 7 / RHEL 7
Security, speed, compliance, and flexibility — all of these describe Lighttpd (pron. lighty) which is rapidly redefining efficiency of a web server; as it is designed and optimized for high-performance environments. With a small memory footprint compared to other web-servers, effective management of the CPU-load, and advanced feature set (FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more).
Lighttpd is the perfect solution for every server that is suffering load problems. And best of all it’s Open Source licensed under the revised BSD license.
This tutorial shows you how to install Lighttpd on CentOS 7 / RHEL 7 with PHP (through PHP-FPM) and MariaDB support.
The first thing you need to do is to log in as root or switch to the root user.
$ su -
OR
$ sudo su -
Install MariaDB
First, we will install the MySQL by issuing the following command.
yum -y install mariadb mariadb-server
Start MySQL server.
systemctl start mariadb
To make the MySQL service to start automatically during every boot, Type the following on terminal and hit Enter.
systemctl enable mariadb
Next is to make MariaDB secure by using the mysql_secure_installation command.
Install Lighttpd
Latest Lighttpd is available on EPEL. So, you need to set up EPEL repository on CentOS 7 / RHEL 7.
Install EPEL repository rpm using the following command.
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Install Lighttpd using the following command.
yum -y install lighttpd
Start the Lighttpd service after the installation.
systemctl start lighttpd
Issue the following commands to allow HTTP request through the firewall.
firewall-cmd --permanent --add-service=http firewall-cmd --reload
Open a web browser and visit
You should get the following page, and this will confirm you that the Lighttpd is successfully installed on the server.

The default document root of Lighttpd on CentOS 7 is /var/www/lighttpd/. The configuration files are placed under /etc/lighttpd/ directory.
Enable the Lighttpd service to start automatically at system startup.
systemctl enable lighttpd
Troubleshooting
In case, if you are unable to access the Lighttpd’s default page, then consider disabling IPv6 support.
To disable the IPv6 support on Lighttpd, edit the below file
vi /etc/lighttpd/lighttpd.conf
Comment out the following line.
# server.use-ipv6 = "enable"
Restart the Lighttpd service.
systemctl restart lighttpd
Install PHP5-FPM
Next is to install PHP through PHP-FPM (PHP-FPM (FastCGI Process Manager), it is an alternative PHP FastCGI implementation. it has some additional features useful for sites of any size, especially busier sites).
Install PHP by using the yum command.
yum -y install php-fpm php-mysql lighttpd-fastcgi
Edit /etc/php.ini.
vi /etc/php.ini
set cgi.fix_pathinfo=1.
cgi.fix_pathinfo=1
Edit /etc/lighttpd/conf.d/fastcgi.conf.
vi /etc/lighttpd/conf.d/fastcgi.conf
Look for the below entry; make sure that is enabled.
server.modules += ( "mod_fastcgi" )
Add the below content at the end of the fastcgi.conf file.
fastcgi.server += ( ".php" => ### PHP-FPM Support
((
"host" => "127.0.0.1",
"port" => "9000",
"broken-scriptfilename" => "enable"
))
)
Edit /etc/php-fpm.d/www.conf.
vi /etc/php-fpm.d/www.conf
Make sure you modify the following entries.
[....] listen = 127.0.0.1:9000 [....] user = lighttpd group = lighttpd [....]
Edit /etc/lighttpd/modules.conf.
vi /etc/lighttpd/modules.conf
Uncomment the following line.
include "conf.d/fastcgi.conf"
Enable PHP-FPM Support on Virtual Host
Let’s create name-based virtual host on Lighttpd server for the following domain.
Server Name : server.itzgeek.local
Document Root : /var/www/lighttpd/server.itzgeek.local
Create the configuration file called itzgeek.conf in /etc/lighttpd/vhosts.d directory.
vi /etc/lighttpd/vhosts.d/itzgeek.conf
Add the following content.
$HTTP["host"] == "server.itzgeek.local" { ### Domain URL server.document-root = "/var/www/lighttpd/server.itzgeek.local" ### Document root }
Edit /etc/lighttpd/lighttpd.conf.
vi /etc/lighttpd/lighttpd.conf
Uncomment the following line.
include "/etc/lighttpd/vhosts.d/*.conf"
Test PHP-FPM support on the Virtual Host
Create the document root directory and log directory.
mkdir /var/www/lighttpd/server.itzgeek.local
For testing the PHP, Place one PHP file on to the document root of the created virtual host, In the terminal copy/paste the following line:
vi /var/www/lighttpd/server.itzgeek.local/index.php
This will open up a file called index.php, Copy/Paste this line into the index.php file:
<?php phpinfo(); ?>
Save and close the file. Use Esc + ;wq for saving the file.
Set permission.
chown -R lighttpd:lighttpd /var/www/lighttpd/
Restart the services.
systemctl restart lighttpd systemctl restart php-fpm
Now open up your web browser and type your domain in the web address: In my case it is
The page will look like below:

From the above screenshot, it is confirmed that the PHP is working, through FPM/FastCGI, as shown in the Server API line.
If you scroll further down, you will see all modules that are enabled in PHP.
MariaDB support information:

That’s all.