PHP-FPM (FastCGI Process Manager) is an alternative implementation of PHP FastCGI. It provides some additional features like Adaptive process spawning which is useful for sites. This tutorial will help you to install Apache with PHP-FPM/FastCGI on Ubuntu 16.04 system. In this tutorial, we are using PHP 7.2 and configure with Apache using PHP-FPM and FastCGI.

Advertisement

You can also visit the previous tutorial to configure Apache with multiple PHP versions using PHP-FPM/FastCGI on Ubuntu systems.

Apache Installation

Install Apache web server from the official repository. Launch terminal on your system or login with ssh to remote systems. Execute the following commands to install the latest available version of Apache web server and FastCGI module.

sudo apt update 
sudo apt install apache2 libapache2-mod-fastcgi

PHP Installation

For the installation of PHP versions, we use the PPA maintained here. Use the below couple of commands to add the PPA to your system.

sudo apt install python-software-properties
sudo add-apt-repository ppa:ondrej/php

And install PHP 7.2 the latest version available on the day of writing this tutorial. Simply execute follows commands for the installation of PHP and PHP-FPM packages.

apt update
sudo apt install php7.2 php7.2-fpm
Note:- When you are using PHP-FPM. All the PHP modules configurations are residing under /etc/php/7.2/fpm directory. You can read more about enable/disable PHP modules.

After installing above packages php7.2-fpm service will automatically be started. You can make sure by typing below command on terminal.

sudo systemctl status php7.2-fpm

● php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabl
   Active: active (running) since Wed 2018-02-21 10:13:28 UTC; 17s ago
     Docs: man:php-fpm7.2(8)
 Main PID: 27506 (php-fpm7.2)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
   CGroup: /system.slice/php7.2-fpm.service
           ├─27506 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
           ├─27509 php-fpm: pool www
           └─27510 php-fpm: pool www

Feb 21 10:13:28 tecadmin systemd[1]: Starting The PHP 7.2 FastCGI Process Manager...
Feb 21 10:13:28 tecadmin systemd[1]: Started The PHP 7.2 FastCGI Process Manager.

Apache Configuration

Now enable few modules required for the configuration of multiple PHP versions with Apache. These modules are necessary to integrate PHP FPM and FastCGI with Apache server.

a2enmod actions fastcgi alias proxy_fcgi

Let’s configure the Apache VirtualHost to run with FPM/FastCGI. For this tutorial, we use default VirtualHost. Edit VirtualHost host configuration file in text editor. You can create new VirtualHost as per your requirements, so make sure to enable any new VirtualHost.

sudo vim /etc/apache2/sites-available/000-default.conf

Update the configuration as followings.

Save your changes to the configuration file and restart Apache to reload the changes.

sudo systemctl restart apache2

Test Setup

Create a PHP script with phpinfo() function and place it to your server document root. Use below command to do it.

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Open a web browser access the info.php using server IP address (for default VirtualHost) for your configured domain in Apache VirtualHost.

Share.

5 Comments

  1. Smell something funny with this line:

    SetHandler “proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/”

    `php5.6-fpm.sock`???

    Is this copied from an old example or something?

Reply To JKK Cancel Reply

Exit mobile version