The Apache web server is one of the most popular on the planet. Out of the box, Apache does a pretty solid job of handling average traffic. But, once you start hitting it with an above average load, under certain circumstances such as resource capacity and complexity of websites served, you might find it struggles a bit. If that describes what you are experiencing, the Multi-Processing Modules (MPM) Prefork module might be in order.

The MPM Prefork module uses a single control process which is responsible for launching child processes. These child processes listen for connections and serve them when they arrive. MPM Prefork is self-regulating, so unless you need a much larger overhead, there's very little cause for adjusting it's default configurations. However, you do need to enable this module as it is disabled out of the box.

I'm going to show you how to enable the MPM Prefork module on Apache. I'll be demonstrating on Ubuntu Server 18.04. 

What you'll need

The only things you'll need to enable this module are:

  • A running instance of Ubuntu Server 18.04
  • Apache installed and running
  • A user with sudo privileges
  • A network connection

How to enable the mpm_prefork

Most likely, the mpm_prefork module is already installed on your Apache instance. Out of the box, however, it's not enabled. 

Apache2 has support for both prefork and worker. These are both MPMs, but are quite different from one another. The prefork module creates a number of child processes at launch, each child process handles only one thread. Conversely, worker uses child processes which spawn many threads per process, with each thread ready to take on new requests. Although prefork requires considerably more RAM, it is the safest module and should be employed when using non-thread-safe libraries.

To check to see if the prefork module is loaded, issue the command:

apache2ctl -M | grep prefork

If you see no results, prefork isn't loaded. Before you do load it, you'll have to first unload the mpm_event module, as they will conflict. To unload mpm_event, issue the command:

sudo a2dismod mpm_event

Restart Apache with the command:

sudo systemctl restart apache2

Now you can load mpm_prefork with the command:

sudo a2enmod mpm_prefork

Once again, restart Apache with the command:

sudo systemctl restart apache2

How to configure the mpm_prefork

On the off-chance your web server does need significant overhead, you can make adjustments to the prefork configuration. To do this, issue the command:

sudo nano /etc/apache2/mods-available/mpm_prefork.conf

In that file, you'll see the following options:

StartServers                       5
MinSpareServers               5
MaxSpareServers              10
MaxRequestWorkers         150
MaxConnectionsPerChild   0

You might want to bump those numbers up considerably, if you know your server is going to be under a larger load (and you have the RAM to spare), you could alter that configuration like so:

StartServers                          4
MinSpareServers                  3
MaxSpareServers                 40
MaxRequestWorkers             200
MaxConnectionsPerChild      10000

Make sure to edit those numbers according to what your hardware can handle and your expected load will require. Save and close the file. Restart Apache with the command:

sudo systemctl restart apache2

At this point, mpm_prefork is enabled and configured. If you're interested in testing this out, you can run a Perl script. Please use caution when doing so, as it is a Perl script and you just never know. In fact, you might want to download the script and comb through it first (to check for any nefarious code).

Download the script with this command:

wget  https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl

Once you've looked through it, and found it trustworthy, run the command:

sudo perl apache2buddy.pl

Once the command completes, you should see a report of Apache's memory usage.

And there you have it. Apache mpm_prefork is now doing its thing. Make sure to adjust your configuration to best meet the needs of your environment and this module will serve you well.

Was this answer helpful? 133 Users Found This Useful (1225 Votes)

Powered by WHMCompleteSolution