Short guide on how to manually install Apache HTTP 2.4.x in CentOS 6.x

Reason: the version 2.4.x is only available in the CentOS 7 repositories
So if we are using CentOS 6.8 we need to compile from sources! This is sometimes necessary as CentOS is a conservative distribution, not having generally the latest version of a software.

In this case the chosen version will be the Apache HTTP 2.4.25.

FIRST OF ALL SOME WARNINGS!!
I`m not responsible for any damage that you might incur while or after following these tutorial, as usual I strongly recommend to make a backup before proceeding. So please take a system snapshot or at least make a copy of the current Apache HTTPD configuration files and relative installation folder tree.
Also I`m not responsible for the information provided in the external websites here provided.
Use these instructions at your own risk!

 

 

 

 

 
The symbol # means the command must be run as root.
We will consider the working directory to be /root/apache
So we create the below path and chdir to it
#mkdir -p /root/apache && cd /root/apache

Then we need to download apr and apr-util

For more info on the “Apache Portable Runtime Library” please consult the website http://apr.apache.org/

#wget https://archive.apache.org/dist/apr/apr-1.4.2.tar.bz2
#wget https://archive.apache.org/dist/apr/apr-util-1.4.1.tar.gz

And most importantly we need to download Apache HTTP 2.4.25

#wget http://mirror.hosting90.cz/apache//httpd/httpd-2.4.25.tar.bz2

Higher versions of these sources might require updating the C runtime library, which will slightly complicate the process and would require a system reboot. In fact to be able to compile Apache HTTP 2.4.25 we need at least apr and apr-util in the version 1.4.0 and unfortunately they are not in the repositories (at least the default ones) in CentOS 6.8-7

We extract all archives..

tar -xjvf httpd-2.4.25.tar.bz2
tar -xjvf apr-1.4.2.tar.bz2
tar -xzvf apr-util-1.4.1.tar.gz

Move the apr extracted folders
mv apr-1.4.2 httpd-2.4.25/srclib && mv apr-1.4.1-util httpd-2.4.25/srclib

And we create some symbolic links before moving to the correct folder.

cd /root/apache/httpd-2.4.25/srclib
ln -s apr-util-1.4.1 apr-util
ln -s apr-1.4.2 apr
cd ..

We might also need to install any required library, for examples:
pcre-7.8-7.el6.x86_64
pcre-devel-7.8-7.el6.x86_64f

# yum install -y pcre pcre-devel

Containing the Perl compatible regular expression library

And we need also to have installed and updated openssl and openssl-devel

Otherwise the “pre-check” will fail.

After that we are ready to compile and specify our path to be /usr/local/apache2.4.25
What we want is installing all configuration files, libraries, modules and binaries in this path. This comes handy if we want to run another version or backup/remove this one.

So we chdir to /root/setups/apache/httpd/httpd-2.4.25 and run

./configure --prefix=/usr/local/apache2.4.25 --exec-prefix=/usr/local/apache2.4.25 --enable-ssl --enable-so --with-included-apr;make;make install

This will take some minutes depending on the system…

After the build process is successful we check that any library is copied from /root/apache/httpd-2.4.25/srclib/ to /usr/local/apache2.4.25/lib

Afterwards we can create a SysV init script in /etc/init.d called “httpd-2.4.25” or whatever we like. Note that In CentOS 6.x systemd is not yet the default init system.

Now before starting the web server, if we have the configuration files from a previous 2.2.x version, we need to make some modifications as there are changes in several Apache directives in the 2.4 version. These are described in the sites below:

https://www.digitalocean.com/community/tutorials/migrating-your-apache-configuration-from-2-2-to-2-4-syntax
https://httpd.apache.org/docs/2.4/upgrading.html

Note that if you want to run two different versions of the Apache web server, at least for a while, you don`t only need to specify a different HTTP or HTTPS port, but also to change the PID file, otherwise the new version will refuse to start stating that it is already started.

The directive to change is (in the httpd.conf file) PidFile
for instance
PidFile /var/run/httpd2.4.25.pid

That`s it! I hope you have found it useful.

References

How to Install Apache 2.4.2 from Source on CentOS 6.2 with SSL


https://www.digitalocean.com/community/tutorials/migrating-your-apache-configuration-from-2-2-to-2-4-syntax
https://wiki.apache.org/httpd/RewriteLog
https://httpd.apache.org/docs/2.4/upgrading.html