We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.

[nextpage title=”Introduction”]

We prepared this tutorial for those currently running the Apache webserver and who plan to upgrade it to the latest 2.4 series, as there are important differences between the Apache 2.4 series and the previous series, so the migration process is as smooth as possible.

Before going into the details of how to compile and how to configure Apache 2.4, there is one major difference between Apache 2.4 and previous versions that you must know.

Previous versions of Apache used the “prefork” multi-processing module (MPM) by default. This engine creates an individual process for each connection. So, if there are 500 connections going on at your webserver, you should see 500 httpd processes running.

Apache 2.4, on the other hand, uses the “event” multi-processing module by default. This engine creates only a few processes, with each process handling several connections (up to 25, by default). Because of this, you will see far less httpd processes running. For example, with 500 connections going on at your webserver, you should see only 20 httpd processes running (500 / 25). Therefore, this new engine makes Apache use less memory (RAM).

Of course, you can still compile Apache 2.4 to use the “old” “prefork” multi-processing module. But if you don’t provide any additional parameters during compilation time, it will use the “event” engine and you will need to make some adjustments to your configuration file (httpd.conf). We will explain those later.

Let’s now see how to compile Apache 2.4.

[nextpage title=”Compilation”]

Before compiling Apache, you must know the current configuration line for PHP, as you will have to recompile PHP and most likely you have PHP installed on your webserver. The easiest way to do that is to create a file called phpinfo.php on the root directly on a website hosted on your webserver, containing the following:


Then, open this file using your browser (e.g., https://www.yoursite.com/phpinfo.php, where yoursite.com is the URL of the website containing the phpinfo.php file), and copy everything that is listed beside “Configure Command”.

Another way to achieve the same result is to run the command (you will have to change the “/usr/local/apache2/” path to point to where Apache is actually installed on your server):

#/usr/local/apache2/php/bin/php -i | grep “Configure Command”

In both cases, you will have to remove all single quotation marks (apostrophes) from the text you copied.

If you need to know where Apache is currently installed on your system, simply run:

#find / -name apxs

One big difference between Apache 2.4 and previous versions is that the APR (Apache Portable Runtime) modules don’t come together with Apache anymore. Therefore, besides downloading the latest version of Apache 2.4, you must download the latest versions of APR and APR-util, which are available at https://apr.apache.org/download.cgi.

Let’s assume that you downloaded all three files (Apache, APR, and APR-util) to the directory /downloads. You must decompress the three files, and move APR and APR-util to the correct directories under the Apache compilation directory. For example (replace x, y, and z with the correct numbers, depending on the versions you downloaded):

/downloads# tar -xvzf httpd-2.4.x.tar.gz

/downloads# tar -xvzf apr-x.y.z.tar.gz

/downloads# tar -xvzf apr-util-x.y.z.tar.gz

/downloads# mv apr-x.y.z /downloads/httpd-2.4.x/srclib/apr

/downloads# mv apr-util-x.y.z /downloads/httpd-2.4.x/srclib/apr-util

Now you have the proper structure to compile Apache (change –prefix=/usr/local/apache2 to where you want to install Apache; we suggest you use the path to the current Apache installation):

/downloads# cd httpd-2.4.x

/downloads/httpd-2.4.x# ./configure –prefix=/usr/local/apache2 –enable-deflate –enable-mods-shared=all –with-included-apr  –enable-nonportable-atomics=yes

/downloads/httpd-2.4.x# make && make install

If you want to use the “old” “prefork” engine, add –with-mpm=prefork to the configure line.

Now you have Apache 2.4 compiled. You must now recompile PHP, if you have PHP installed on the system (most likely).

Assuming, again, that you downloaded the latest PHP packed to /downloads, you must:

/downloads/httpd-2.4.x# cd /downloads

/downloads# tar -xvzf php-x.y.z.tar.gz

/downloads# cd php-x.y.z

/downloads/php-x.y.z# [paste here the compilation line you obtained from phpinfo]

/downloads/php-x.y.z# make && make install

If you use a caching system such as Xcache (which we highly recommend you install to improve performance of your webserver), you must recompile it as well. Assuming you downloaded the latest version of Xcache to /downloads, you must run the following commands (you must replace “/usr/local/apache2/php/” with the actual PHP installation directory, if different):

/downloads/php-x.y.z# cd /downloads

/downloads# tar -xvzf xcache-x.y.z.tar.gz

/downloads# cd xcache-x.y.z

/downloads/xcache-x.y.z# /usr/local/apache2/php/bin/phpize –clean

/downloads/xcache-x.y.z# /usr/local/apache2/php/bin/phpize

/downloads/xcache-x.y.z#./configure –enable-xcache –enable-xcache-optimizer –with-php-config=/usr/local/apache2/php/bin/php-config

/downloads/xcache-x.y.z# make && make install

Pay attention to the output provided by the installation script, as it will show you where xcache.so was installed (it will be a path such as “/usr/local/apache2/php/lib/php/extensions/no-debug-zts-20090626/”.

If you had Xcache installed before, all you need to do now is to edit the php.ini file (located at /usr/local/apache2/php in our examples), find xcache.so, delete the line where it is present, and replace it with something like:

extension = /usr/local/apache2/php/lib/php/extensions/no-debug-zts-20090626/xcache.so

The path must be the one provided by the installation script. Save the php.ini file and you are now ready to make the proper adjustments to the httpd.conf file as described on the next page.

If your previous PHP installation didn’t have Xcache installed, you must add the proper configuration lines to php.ini, as follows (of course you must change “/usr/local/apache2/php/” to the actual location of php.ini, if you installed Apache and PHP under a different directory):

/downloads/xcache-x.y.z# cat xcache.ini>>/usr/local/apache2/php/php.ini

You must now edit php.ini file, look for xcache.so, and replace the line where it is present with the line published above (“extension…”).

You also must configure “xcache.count” with the number provided by the command cat /proc/cpuinfo |grep -c processor.

And we recommend you change xcache.optimizer from “Off” to “On”.

You can fine-tune Xcache later by checking its control panel, after Apache is online for a while. Xcache’s control panel is available under the “xcache” directory under Xcache’s installation directory. For example, you can run the following command to have Xcache’s control panel available at https://www.yoursite.com/xcache (you must replace /www/yoursite with the actual path to your website on your server, of course):

/downloads/xcache-x.y.z# mv xcache /www/yoursite

Let’s now see the additional configurations we must perform.

[nextpage title=”Configuring httpd.conf”]

There are several changes done to the way certain parameters are configured at httpd.conf. You must use your current httpd.conf file as a starting point, and below we will explain what you must change.

Before editing your httpd.conf, you should perform a backup. For instance:

/downloads/xcache-x.y.z# cd /usr/local/apache/conf

/usr/local/apache/conf# cp httpd.conf httpd.conf.2.2

If your previous Apache installation used the “prefork” engine and your new installation uses the “event” engine, you will have to change the parameters listed below (which are just a generic example):

ServerLimit                    2048

StartServers                  512

MinSpareServers             25

MaxSpareServers            50

MaxClients                     2048

MaxRequestsPerChild       100

If your server parameters have the and parameters around them, as in our example, you must either replace “prefork.c” with “event.c” or remove them. Another option is to leave these parameters the way they are and create a new and section, which will hold the new parameters for the “event” engine.

MaxRequestsPerChild must be renamed to ThreadsPerChild and MaxClients must be renamed to MaxRequestWorkers.

The parameters StartServers, MinSpareServers, and MaxSpareServers must be eliminated.

MaxRequestWorkers must specify the maximum number of Apache processes that can be created. This will be the multiplication of ServerLimit by ThreadsPerChild. If ThreadsPerChild (old MaxRequestsPerChild) doesn’t exist, the default value of 25 must be used. The default value of ServerLimit is 6, meaning that by default Apache 2.4 can handle up to 150 simultaneous connections (25 * 6). In our example, as we want each process to handle up to 100 connections and we want a maximum of 2048 connections, we have a problem, as 2048 is not a multiple of 100. If you leave the default value of 25, MaxRequestWorkers (old MaxClients) must be a multiple of 25. In our example, we would have to change MaxRequestWorkers (old MaxClients) to either 2000 or 2100. If we go with 2000, ServerLimit must be set at 20 (2000/100). In your particular case, this value would be different. In summary:

ServerLimit = MaxRequestWorkers / ThreadsPerChild

We also recommend adding the parameter ListenBackLog 5000.

After making these adjustments, our configuration became:

ServerLimit                         20

MaxRequestWorkers             2000

ThreadsPerChild                  100

ListenBackLog                    5000

Of course you can fine-tune these numbers later on, based on the values necessary for your webserver to handle peak traffic.

Let’s now look at other changes you must make.


LoadModule cgi_module            modules/mod_cgi.so


LoadModule cgid_module          modules/mod_cgid.so

Add the following, if not present yet:

LoadModule authz_host_module    modules/mod_authz_host.so

LoadModule authn_core_module    modules/mod_authn_core.so

LoadModule unixd_module            modules/mod_unixd.so

Configurations such as:

Order allow,deny

Deny from all (or Allow from all)

Must be changed to:

Require all granted

Configurations such as:

Order deny,allow

Deny from all

Must be changed to:

Require all denied

If you have .htaccess files used on your websites with similar parameters, they must be changed too.

Delete or comment lines with the parameter DefaultType.

Delete or comment lines with the parameter NameVirtualHost *.

Phew! Now you are ready to start Apache with apachectl start.

We covered the most common parameters that must be changed. There are several other changes in parameters that may affect your Apache installation. If you see an error message, you must verify its origin, with the aid of the “Upgrading to 2.4 from 2.2” guide available at Apache’s website.