LAMP on Ubuntu 14.04 with Apache Event MPM

September 18, 2014 17.8k views


I came across some really excellent tutorials on DigitalOcean on how to install LAMP on Ubuntu, but none of them mention anything about choosing 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.

It would be great to see a tutorial on how to configure Apache in a LAMP setup to use the Event MPM with - or without - PHP-FPM.

Much appreciated!

5 Answers

Assuming that you're starting with a basic LAMP stack, to get Event MPM and PHP-FPM up and running on Ubuntu 14.04 first install these packages:

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

Then 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


Then 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 should be all set to go!

Hey, what would be the recommended values for the Apache with Event MPM settings, and where is the configuration file to put them in? I didn't find them (even the defaults) specified in the main apache2.conf.

I know these settings depend mostly on the RAM available to the server, so if I get a recommendation for one droplet size, then I can scale accordingly for other sizes. Here is an example I found online:

<IfModule event.c>
    StartServers          3
    MinSpareThreads      75
    MaxSpareThreads     250 
    ThreadsPerChild      25
    MaxClients          400 // MaxRequestWorkers
    MaxRequestsPerChild   0 // MaxConnectionsPerChild

As it turns out, PHP-FPM has its own equivalent settings, like pm.max_children, pm.start_servers, pm.minspareservers, pm.maxspareservers, pm.max_requests, etc. Are these use together with the Apache settings, i.e. for dynamic content, or they complement/supercede them? Here's an example for these (I understand they are specified in the FPM's php.ini):

pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 5
pm.max_requests = 0

Thanks in advance!


This was asked a while ago, but for anyone still interested, check out this awesome article ...not written by me sadly :)

Have another answer? Share your knowledge.