How to compile and install apache from source on CentOS 7

We discuss here how to compile and install apache from source on CentOS 7 server or any other RHEL like systems.

If this is a fresh server do a yum update and reboot the server.

yum update -y
reboot

You will need compilers for this installation.

yum install gcc gcc-c++ -y;

Now you need to download source files needed for this installation. Download it to a convenient directory.

cd /usr/local/src/;
wget https://downloads.apache.org/httpd/httpd-2.4.48.tar.gz;
wget https://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz;
wget https://archive.apache.org/dist/apr/apr-1.6.2.tar.gz;
wget https://ftp.pcre.org/pub/pcre/pcre-8.32.tar.gz;

Extract all these files.

tar xvf apr-util-1.5.4.tar.gz;
tar xvf apr-1.6.2.tar.gz;
tar xvf httpd-2.4.48.tar.gz;
tar xvf pcre-8.32.tar.gz;

Go to extracted apr directory and install apr.

cd apr-1.6.2/;
./configure;
make;
make install;


Go to extracted apr-util directory and install apr-util.

cd ../apr-util-1.5.4/;
./configure --with-apr=/usr/local/apr/bin/apr-1-config;
make;
make install;

Go to extracted pcre directory and install pcre.

cd ../pcre-8.32/;
./configure;
make;
make install;

Go to extracted httpd directory and install httpd. pcre location should be included for httpd to complete installation successfully.

cd ../httpd-2.4.48/;
./configure --with-pcre=/usr/bin/pcre-config;
make;
make install;

Now, we need to find the location from where we can start httpd.
For that we locate the right file.

updatedb;
locate httpd | grep bin;

We will get a list of files from which we can locate the right file.
Use that file to start httpd

/usr/local/apache2/bin/httpd -k start;


You can verify whether apache is running or not, using netstat command.

[root@e22 ~]# netstat -autpn | grep :80 
tcp6       0      0 :::80                   :::*                    LISTEN      38717/httpd

This will make sure that httpd is up and running.

Note : If you have a firewall, you will need to configure firewall to allow port 80 for the server to respond in browser. You will need to edit httpd.conf to allow ipv4, if you use ipv4. We will discuss configuring firewall, enabling IPv4 and creating websites in other pages in this website.

Thus we learned how to compile and install apache from source on CentOS 7.

One more note : Even if you just copy paste all the commands above updatedb and run it as a script, it will run without any trouble 😉

Add a Comment

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