Apache with PHP-FPM and Event MPM

PHP has many handlers you can choose. Which one is the best? There are pros and cons of each handler and you can find them easily just by googling. It really depends on your application nature and server environment.

I use Digital Ocean one click app to install Joomla on the droplet. It is a LAMP (Linux, Apache, MySQL and PHP) setup and the default PHP handler is Apache PHP handler. I found out that php5-fpm performance is better than the default handler in my case.

Another changes I made was to use a specific Apache MPM (Multi Processing Module). The latest versions of Apache offer the Event MPM, which is the Apache’s only hope and fighting chance for good benchmarks against NGINX. The Ubuntu 14.04 LAMP image is configured with the oldest Prefork MPM, which is also the clumsiest and RAM hungriest of all Apache MPMs.

Here’s a step by step guide on how to use Apache with PHP-FPM and Event MPM.

First, install required packages.

#sudo apt-get install libapache2-mod-fastcgi php5-fpm apache2-mpm-event

Create the file “/etc/apache2/conf-available/php5-fpm.conf” with the contents:

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

Then disable old mods and enable the new mods and config:

sudo a2enmod actions fastcgi alias
sudo a2dismod mpm_prefork php5
sudo a2enconf php5-fpm
sudo a2enmod mpm_event
sudo service apache2 restart

You may test your configuration changes using phpinfo().

References:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s