The Blog

Compiling and installing Apache on Ubuntu from source code

Compiling and installing Apache on Ubuntu from source code.

Normally we install apache on Ubuntu using the command,

 sudo apt-get install apache2 

This will install the latest version of apache server in our ubuntu system along with the default settings.

The main use of compiling and installing apache from source code is we can use the custom settings in it and also it helps in installing two apache web server in 1 machine.

Installing the dependencies

So moving on to the installation we need to install some dependencies first.

Installing each and every dependencies individually may take some time so for doing them all in once lets write a script named prereq.sh.

 #!/bin/bash
#installing the required things for compiling cource code od apache
sudo apt-get update
sudo apt-get install -y \
build-essential \
binutils \
libpcre3-dev \
libssl-dev \
zlibc \
zlib1g-dev \
libexpat1-dev \
ssl-cert \
libxml2-dev \
libyajl-dev \ 

The dependencies here are useful for;so this will install all the essential dependencies.

Moving on to next part 

Downloading the source code

For recompiling an Ubuntu package from source, their package manager would be placed in the /usr/src/{pkg}.

Create a folder in /usr/src/ with a name apache.

 sudo mkdir -p /usr/src/apache 

Then head to this direction.

 cd /usr/src/apache 

Download the latest version of source code and apr and apr-util
These are available at

 https://httpd.apache.org
https://apr.apache.org 
 wget https://dlcdn.apache.org//httpd/httpd-2.4.51.tar.gz
wget https://dlcdn.apache.org//apr/apr-1.7.0.tar.gz
wget https://dlcdn.apache.org//apr/apr-util-1.6.1.tar.gz 

Note: Kindly check with the website for the latest versions.

Now for ease lets make the above mentioned steps as a script and execute it so that all of them will be executed automatically in one click.

 #!/bin/bash
#script for downloading the necessary files for httpd
 
#make sure the code will be downloaded to /usr/src/apache
sudo mkdir -p /usr/src/apache
 
cd /usr/src/apache
 
#download the latest version of source code and apr and apr-util
#available at
#https://httpd.apache.org
#https://apr.apache.org
 
wget https://dlcdn.apache.org//httpd/httpd-2.4.51.tar.gz
wget https://dlcdn.apache.org//apr/apr-1.7.0.tar.gz
wget https://dlcdn.apache.org//apr/apr-util-1.6.1.tar.gz 

On successful completion of the script head to the location and check the files are downloaded or not.

Extracting, Compiling and installing

Head to the above mentioned location /usr/src/apache  and extract the files.

Then head to the extracted files location 

and Run the command 

 ./configure --prefix=/usr/local/apr/ 

The configure script will make it ready to be compiled.

Then run these two commands which will compile and install the compiled source code.

Follow the same for APR(Apache portable runtime project) and APR-UTIL.

 visit: https://apr.apache.org/ for more 

Make a script based on this and run the script which will configure, Compile and install APR and APR-UTIL

 #!/bin/bash
#compile APR and APR-UTILS
#confirm version first
APR="apr-1.7.0"
APRUTIL="1.6.1"
 
#APR
cd /usr/src/apache
tar -xzvf apr-1.7.0.tar.gz
cd apr-1.7.0
./configure --prefix=/usr/local/apr/
make
sudo make install
 
#APR_UTIL
cd /usr/src/apache
tar -xzvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr/ --with-apr=/usr/local/apr/
make
sudo make install 

And another script containing commands to compile configure and build apache from source

 #!/bin/bash
#compile apache httpd
cd /usr/src/apache
mv httpd-2.4.51.tar.gz httpd.tar.gz
tar -xzvf httpd.tar.gz
cd httpd
./configure --prefix=/usr/local/httpd \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr/bin/apr-1-config \
--enable-mpms-shared=all \
--enable-nonportable-atomics=yes
 
make
sudo make install
sudo ln -s /usr/local/httpd/apache 

The last line creates a symbolic link for apache.

 To start Apache manually use the command
/usr/local/httpd/bin/apachectl -k start 

And for confirming the installation is succesfull or not use the command.

 curl -v localhost 

Or load your Server ip in the browser.

Thus we successfully installed apache from source code.

DevOps Gurukul is one of the best training academies which provides the Best online Linux training in Kerala and RedHat Training Center In Kochi

Leave a Comment

Your email address will not be published.

×

Powered by WhatsApp Chat

× How can I help you?