enable apache mpm prefork

How to Enable Apache MPM Prefork

Apache web server is one of the most popular web servers in the world, used by millions of websites and organizations. It is capable of handling high traffic to websites and applications. However, its default settings support only average traffic to websites. In order to scale your server, you need to enable its multiprocessing module (MPM). In this article, we will learn how to enable Apache MPM Prefork.

Apache multiprocessing module supports prefork, workers and events. Prefork is a configuration wherein you have a single controller process that spawns all child processes for listening to incoming connections. In case of workers, each worker can, in turn, create multiple threads, one for each incoming request. MPM events are designed to support more requests by passing some of the processing to supporting threads, and freeing up main threads to process new requests.

For our example, we will enable Apache MPM prefork.


How to Enable Apache MPM Prefork

Here are the steps to enable Apache MPM prefork module. We will be using Ubuntu/Debian system for our purpose.


1. Enable MPM Prefork

In most cases, Apache MPM module is already installed along with Apache server, but not enabled. You can only use one type of MPM configuration at a time. In other words, if you use Prefork, you will need to disable worker and event.

So open terminal and run the following command to check if prefork is enabled or not.

$ apache2ctl -M | grep prefork

If you don’t get any output, it means prefork is not enabled yet. In such case, run the following commands to disable MPM worker & event, and enable prefork.

$ sudo a2dismod mpm_event
$ sudo a2dismod mpm_worker

Restart Apache server to apply changes.

$ sudo systemctl restart apache2

Enable MPM Prefork.

$ sudo a2enmod mpm_prefork

Restart Apache Server to apply changes.

$ sudo systemctl restart apache2

Please note, a2enmod and a2dismod commands are available only in Ubuntu/Debian systems. If you are using Redhat/CentOS/Fedora/SUSE Linux, then you need to open Apache configuration file in a text editor.

$ sudo vi /etc/apache2/httpd.conf

Comment the line containing modules for worker and event, by adding # at its beginning, and uncomment the line containing prefork module by removing # at its beginning, as shown below.

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
#LoadModule mpm_event_module modules/mod_mpm_event.so

Save and close the file, and restart Apache server to apply changes.


2. Configure MPM_Prefork

In most cases, the default configuration of MPM Prefork is enough to handle large web traffic. However, if you need to customize it, then here is how to do it.

Open MPM Prefork’s configuration file in a text editor.

$ sudo vi /etc/apache2/mods-available/mpm_prefork.conf

In this file, you will see the following options.

StartServers             5
MinSpareServers          5
MaxSpareServers          10
MaxRequestWorkers        150
MaxConnectionsPerChild   0

Modify them to the following values. Please make sure that your hardware can handle these values. Also, increase them only to the extent of handling your expected load.

StartServers                4
MinSpareServers             3
MaxSpareServers             40
MaxRequestWorkers           200
MaxConnectionsPerChild      10000

Restart Apache server.

$ sudo systemctl restart apache2

At this point, MPM Prefork is enabled on your system. You can test it using Apache bench to see if it is able to handle your expected load.

Also read:

How to Change Apache Prefork to Worker
How to Enable PHP in Apache
How to Install Rspamd in Ubuntu
How to Change Wifi Password in terminal
How to Set JAVA_HOME in Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *