Lighttpd With PHP FPM And MariaDB on CentOS 7 / RHEL 7

ADVERTISEMENT

Lighttpd

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.

ADVERTISEMENT
Article will continue after the ad

This tutorial shows you how to install lighttpd on an CentOS 7 / RHEL 7 with PHP (through PHP-FPM) and MariaDB support.

The first thing you need to do is to login as root, switch to root user.

$ su

Installing MariaDB:

First we will install the MySQL by issuing the following command.

# yum -y install mariadb mariadb-server

Start MySQL server.

# systemctl start mariadb.service

To make the MySQL to start during the every boot, Type the following on terminal and hit Enter.

# systemctl enable mariadb.service

Next is to make MariaDB secure by using the mysql_secure_installation command.

Installing Lighttpd:

Latest lighttpd is available on EPEL, setup EPEL repository on CentOS 7 / RHEL 7. Install EPEL rpm by using the following command.

# rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

Install lighttpd using the following command.

# yum -y install lighttpd

Start the lighttpd after the installation.

# systemctl restart lighttpd.service

Iptables and SELinux:

Issue the following commands to allow http request through the firewall.

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload

Open web browser and visit http://your-ip-address, you should see the following page; this will confirm you that the lighttpd is successfully installed on the server.

 CentOS 7 - Lighttpd Default Page

CentOS 7 – Lighttpd Default Page

The default document root on CentOS 7 is /var/www/lighttpd/. The configuration files are under /etc/lighttpd/ directory.

Auto start lighttpd at system start up.

# systemctl enable lighttpd.service

Installing 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 it by issuing the following 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

Open /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" )

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 
 [....]

Enable Fast-cgi, open /etc/lighttpd/modules.conf

vi /etc/lighttpd/modules.conf

Un comment the following line.

include "conf.d/fastcgi.conf"

Enabling PHP-FPM Support on Virtual Host:

Lets create name based virtual host on Nginx server for the following details.

Server Name : server.itzgeek.com
Document Root : /var/www/lighttpd/server.itzgeek.com

Create the configuration file called itzgeek.conf in /etc/lighttpd/vhosts.d.

# vi /etc/lighttpd/vhosts.d/itzgeek.conf

Add the following content.

$HTTP["host"] == "server.itzgeek.com" {   ### Domain URL
server.document-root = "/var/www/lighttpd/server.itzgeek.com"   ### Document root
}
fastcgi.server += ( ".php" =>   ### PHP-FPM Support
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

Edit /etc/lighttpd/lighttpd.conf.

# vi /etc/lighttpd/lighttpd.conf

Un comment the following line.

include_shell "cat /etc/lighttpd/vhosts.d/*.conf"

Testing PHP-FPM support on Virtual host:

Create the document root directory and log directory.

# mkdir /var/www/lighttpd/server.itzgeek.com

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.com/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.service
# systemctl restart php-fpm.service

Now open up your web browser and type the your domain in the web address:  In my case it is  http://sever.itzgeek.com, the page will look like below:

CentOS 7 - Lighttpd PHP-FPM
CentOS 7 – Lighttpd PHP-FPM

From the above screen shot , PHP is working, and it’s working through FPM/FastCGI, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP.
Scroll down the browser and look for the MySQL support information.

CentOS 7 - Lighttpd PHP-FPM and MariaDB Support
CentOS 7 – Lighttpd PHP-FPM and MariaDB Support

That’s all!

ADVERTISEMENT

POSTS YOU MAY LIKE -:)

Share This Post

Shares