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

2

Install Lighttpd on CentOS 7
Install Lighttpd on CentOS 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, 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 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.

Install EPEL rpm by 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 after the installation.

# systemctl restart lighttpd.service

Iptables:

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

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

Open a 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.

Install Lighttpd on CentOS 7 - Lighttpd Default Page
Install Lighttpd on 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 the Lighttpd service 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 PHP by using 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

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 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

Un comment the following line.

include "conf.d/fastcgi.conf"

Enabling PHP-FPM Support on Virtual Host:

Let’s create name based virtual host on Lighttpd server for the following domain.

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 directory.

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

Add the following content.

$HTTP["host"] == "server.itzgeek.com" {   <strong><span style="color: #00ff00;">### Domain URL</span></strong>
      server.document-root = "/var/www/lighttpd/server.itzgeek.com"   <strong><span style="color: #00ff00;">### Document root</span></strong>
}

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:

&lt;?php phpinfo(); ?&gt;

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 your domain in the web address:  In my case it is  http://sever.itzgeek.com, the page will look like below:

Install Lighttpd on CentOS 7 - Lighttpd PHP-FPM
Install Lighttpd on 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.

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

That’s all!

You might also like

Close