Run PHP7-FPM with Apache mpm_event on Ubuntu 16.04

Last modified
Tuesday, February 14, 2017 - 12:54

On this post I'll show you how to run Drupal 8 or any PHP application using Apache HTTP Server with mod_event enabled and PHP 7-FPM

First we need to get the required PHP and Apache packages from the Ubuntu repository:

$sudo apt-get install php7.0-fpm apache2 libapache2-mod-fastcgi

then we need to disable the worker that's enabled by default and switch to mpm_event:

$sudo a2dismod mpm_worker
$sudo a2enmod mpm_event

Now that we have enabled the event module, let's activate some required extra apache modules needed to run our apps like Drupal:

$sudo a2enmod alias rewrite fastcgi expires headers remoteip ssl actions

We need to create a config file for PHP-FPM so apache is aware of how to treat it:

$sudo nano /etc/apache2/conf-available/php-fpm.conf

in this file, paste following configuration directive:

<IfModule mod_fastcgi.c>
   AddHandler php.fcgi .php
   Action php.fcgi /php.fcgi
   Alias /php.fcgi /usr/lib/cgi-bin/php.fcgi
   FastCgiExternalServer /usr/lib/cgi-bin/php.fcgi -socket /run/php/php7.0-fpm.sock -pass-header Authorization -idle-timeout 3600
   <Directory /usr/lib/cgi-bin>
       Require all granted

Let's enable the above configuration:

$sudo a2enconf php-fpm

and restart Apache:

$sudo service apache2 restart

Alright, let's see if our new installation is working, if you open your browser and visit you server IP you should see the default Apache info page, for example go to http://YOUR_SERVER_IP/ and you'll get a similar screen as shown below:

apache default

and finally let's see if PHP is correctly configured and running. Create a new file on the following directory:

$sudo nano /var/www/html/index.php

and add the following line that will print out the PHP configuration on our browser

<?php echo phpinfo();?>

and that's it! Point your browser to http://YOUR_BROWSER__IP/index.php and you should see the PHP default config available on your system, similar to the screenshot below:

php default

Hope it helps!


Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.