Installing Apache server from source, and building from source provides the following options that are not available when using a version from a binary package manager.

Compiling from source allows you to:

  • use processor-specific optimizations
  • use the very latest version

Apache Server (HTTP) is a free open source web server for Unix-like systems, Windows and other operating systems.

For my web server setup, I will be using CentOS7 the latest version of Apache 2.4.26 PHP 7.1 with FPM and MariaDB for my database setup and I will configure apache to use Nginx as a reverse proxy.

Open a terminal and install the prerequisits we use the Sudo command to give us root control if you are logged in as a normal user.

 sudo yum -y install gcc.x86_64 pcre-devel.x86_64 openssl-devel.x86_64 expat-devel

 

Next, we will download the Apache source code

 
cd /usr/src
sudo wget https://www-eu.apache.org/dist//httpd/httpd-2.4.26.tar.gz
sudo tar xvfz httpd-2.4.26.tar.gz

We have downloaded the Apache source and extracted it to the /usr/src folder, we need to download and extract the apr and apr-util to be able to build the Apache source

sudo wget https://www-us.apache.org/dist//apr/apr-1.6.2.tar.gz
sudo wget https://www-us.apache.org/dist//apr/apr-util-1.6.0.tar.gz

sudo tar xvfz apr-1.6.2.tar.gz
sudo tar xvfz apr-util-1.6.0.tar.gz

sudo cp -av apr-1.6.2 httpd-2.4.26/srclib/apr
sudo cp -av apr-util-1.6.0 httpd-2.4.26/srclib/apr-util

We have coppied the apr and apr-util to the correct folders, now we can configure apache and install it under the /opt/httpd folder

cd httpd-2.4.26
sudo ./configure --prefix /opt/httpd --enable-rewrite --enable-ssl --enable-proxy --enable-so  --with-included-apr
sudo make
sudo make install

We can configure the apache server and create our SSL keys.

sudo nano /opt/httpd/conf/httpd.conf

Set user and group inside on file httpd.conf to apache

User apache
Group apache

Add this line under include vhosts

IncludeOptional conf/vhosts/*.conf

Create apache vhost directory, for place of config vrtualhost

Enable SSL in httpd.conf

LoadModule ssl_module modules/mod_ssl.so

LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

Include conf/extra/httpd-ssl.conf

sudo mkdir /opt/httpd/conf/vhosts
cd vhosts

Apache Server Create server.crt and server.key file

First, Generate the server.key using openssl.

cd /usr/src
sudo openssl genrsa -des3 -out server.key 1024

The above command will ask for the password. Make sure to remember this password. You need this while starting your Apache later.

Next, generate a certificate request file (server.csr) using the above server.key file.

# openssl req -new -key server.key -out server.csr

Finally, generate a self signed ssl certificate (server.crt) using the above server.key and server.csr file.

# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

After you’ve done with the above steps, you’ll see the following three files under /usr/src

# ls server*
  server.crt server.csr server.key

Copy the server.key and server.crt file to appropriate Apache configuration directory location.

cp server.key /opt/httpd/conf/
cp server.crt /opt/httpd/conf/

To start, stop and restart apache service

[[email protected]]# /opt/httpd/bin/apachectl start
[[email protected]]# /opt/httpd/bin/apachectl stop

open a web browser goto https://IP_address/ to test

Techie Mike
Techie Mike
Self-taught techie, with a passion for computers and all the cool things you can do with them. Techie Mike, B.Eng. B.Sc.
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Techie Mike - The IT guy in Thailand.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.