How to Install Lighttpd with PHP-FPM and MariaDB on CentOS 7 – Page 2.

To start installation

On this page

  • 5 Setting up Lighttpd and PHP
  • 6 PHP Testing / Get more information about your PHP5 installation
  • 7 Getting MySQL Support in PHP
  • 8 Making PHP-FPM use Unix socket
  • 9 References

5 Setting up Lighttpd and PHP

To enable PHP in Lighttpd, we need to modify two files, /etc/php.ini and /etc/lighttpd/lighttpd.conf. First, we open /etc/php.ini and uncomment the line cgi.fix_pathinfo = 1:

nano /etc/php.ini

; 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

Then we open /etc/lighttpd/modules.conf and uncomment the include “conf.d / fastcgi.conf“ line:

nano /etc/lighttpd/modules.conf

## FastCGI (mod_fastcgi)
include "conf.d/fastcgi.conf"

Next, open /etc/lighttpd/conf.d/fastcgi.conf:

nano /etc/lighttpd/conf.d/fastcgi.conf

There’s a line in fastcgi.server – leave a comment and add your own fastcgi.server like this:

## PHP Example
## For PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini.
## The number of php processes you will get can be easily calculated:
## num-procs = max-procs * ( 1 + PHP_FCGI_CHILDREN )
## for the php-num-procs example it means you will get 17*5 = 85 php
## processes. you always should need this high number for your very
## busy sites. And if you have a lot of RAM. :)

fastcgi.server += ( ".php" =>
                "host" => "",
                "port" => "9000",
                "broken-scriptfilename" => "enable"

#fastcgi.server = ( ".php" =>
#                   ( "php-local" =>
#                     (
#                       "socket" => socket_dir + "/php-fastcgi-1.socket",
#                       "bin-path" => server_root + "/cgi-bin/php5",
#                       "max-procs" => 1,
#                       "broken-scriptfilename" => "enable",
#                     )
#                   ),

We will now restart Lighttpd:

systemctl restart  lighttpd.service

6 Testing PHP / Getting More Information About Your PHP5 Installation

The default website document root is / var / www / htdocs /. Now we will create a small PHP file (info.php) in this directory and call it in the browser. The file will display many useful details about our PHP installation, such as the version of PHP installed.

nano /var/www/htdocs/info.php


Now we will call this file in the browser (for example

As you can see PHP is running and it is running via FPM / FastCGI as shown on the Server API line. If you scroll further down, you will see all the modules that are already included in PHP. MySQL is not listed, which means that we do not have MySQL support, PHP does not yet.

7 Getting MySQL Support in PHP

To get MySQL support in PHP, we can install the php-mysql package. It is a good idea to install some other PHP modules, and you may also need them for your applications. You can search for available PHP5 modules:

yum search php

Select the ones you need and install them as follows:

yum -y install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

APC is a free and open source PHP opcode for caching and optimizing PHP intermediate code. It is similar to other PHP caching code like Eaccelerator and XCache. It is highly recommended that one of these be installed to speed up your PHP page.

APC can be installed as follows:

yum -y install php-pecl-apc

Now download PHP-FPM:

systemctl reload php-fpm.service

Now open in your browser and scroll down to the modules section. You should now find many new modules there, including the MySQL module:

Getting MySQL Support in PHP

8 Building PHP-FPM to Use Unix Socket

By default PHP-FPM listens on port 9000 on It is also possible to make PHP-FPM use a Unix socket, which avoids the TCP overhead. To do this, open /etc/php-fpm.d/www.conf …

nano /etc/php-fpm.d/www.conf

… And make the listen line like this:

;listen =
listen = /tmp/php5-fpm.sock

Then reload PHP-FPM:

systemctl reload php-fpm.service

Then open the PHP LightTPD configuration file in /etc/lighttpd/conf.d/fastcgi.conf and replace the host and port lines with “socket” => “/tmp/php5-fpm.sock“:

nano /etc/lighttpd/conf.d/fastcgi.conf

fastcgi.server += ( ".php" =>
                "socket" => "/tmp/php5-fpm.sock",
                "broken-scriptfilename" => "enable"

Finally restart Lighttpd:

systemctl restart  lighttpd.service

  • Lighttpd:
  • PHP:
  • PHP-FPM:
  • MySQL:
  • CentOS:

To start installation
Lighttpd with PHP-FPM and MariaDB on CentOS 7