Main Page

Friday, 12 February 2021

Install and configure Apache webserver 2.4.46 on Linux (Cent OS 8) from source

Step 1) Create the following directory structures for binaries, instances, static website content and log file locations. 

/home/osboxes/products/apache24/ -  download apache binaries at this location
/home/osboxes/instances/apache24/poc-instance   - New apache Instance location 
/home/osboxes/logs/apache24/poc-instance - Log file location for apache instance

[root@webserverhost ~]# pwd
/root
[root@webserverhost ~]# mkdir -p /home/osboxes/products/apache24/
[root@webserverhost ~]# mkdir -p /home/osboxes/instances/apache24/poc-instance
[root@webserverhost ~]# mkdir -p /home/osboxes/logs/apache24/poc-instance


Step 2) Install required packages for build

[root@webserverhost ~]# yum install python27 -y
[root@webserverhost ~]# yum install gcc make -y
[root@webserverhost ~]# yum install expat-devel pcre pcre-devel openssl-devel -y
[root@webserverhost ~]# yum install  autoconf libtool -y


Step 3) Create a symlink for python package command

[root@webserverhost ~]# cd /usr/bin/; ln -s python2.7 python

Step 4) Download httpd-2.4.46.tar.gz , apr-1.7.0.tar.gz & apr-util-1.6.1.tar.gz from source location to products/apache24

[root@webserverhost ~]# export PS1='[$(whoami)@$(hostname):$(pwd)]#'

[root@webserverhost ~]#  cd /home/osboxes/products/apache24/

[root@webserverhost:/home/osboxes/products/apache24]#wget https://downloads.apache.org//httpd/httpd-2.4.46.tar.gz

[root@webserverhost:/home/osboxes/products/apache24]#wget https://downloads.apache.org//apr/apr-1.7.0.tar.gz

[root@webserverhost:/home/osboxes/products/apache24]#wget https://downloads.apache.org//apr/apr-util-1.6.1.tar.gz

Step 5) Extract the packages

[root@webserverhost:/home/osboxes/products/apache24]#tar zxvf httpd-2.4.46.tar.gz
[root@webserverhost:/home/osboxes/products/apache24]#tar zxvf apr-util-1.6.1.tar.gz
[root@webserverhost:/home/osboxes/products/apache24]#tar zxvf apr-1.7.0.tar.gz

Step 6) Create a symlink for easy upgrades in future.

[root@webserverhost:/home/osboxes/products/apache24]# ln -s httpd-2.4.46 httpd

Step 7) Move apr and apr-util directory inside srclib directory located under httpd directory

[root@webserverhost:/home/osboxes/products/apache24]#mv apr-1.7.0 httpd/srclib/apr
[root@webserverhost:/home/osboxes/products/apache24]#mv apr-util-1.6.1 httpd/srclib/apr-util

Step 8) Compilation of apache source 

[root@webserverhost:/home/osboxes/products/apache24]#cd httpd
[root@webserverhost:/home/osboxes/products/apache24/httpd]#./buildconf


Step 9) Configure Apache and change the desired installation location 

[root@webserverhost:/home/osboxes/products/apache24/httpd]#./configure --enable-ssl --enable-so --with-mpm=event --with-included-apr --prefix=/home/osboxes/instances/apache24/poc-instance


Step 10) Execute the make command to prepare the files for the installation of Apache

[root@webserverhost:/home/osboxes/products/apache24/httpd]#make

Step 11) Execute make install command to install apache

[root@webserverhost:/home/osboxes/products/apache24/httpd]#make install


Step 12) Change the owner of the directories

[root@webserverhost:/home/osboxes/products/apache24/httpd]#cd /home/osboxes/
[root@webserverhost:/home/osboxes]#chown -R osboxes:osboxes products instances logs


Step 13) Change the following configurations in httpd.conf file

Listen 10001

ServerName webserverhost:10001

User osboxes
Group osboxes

[root@webserverhost:/root]#cd /home/osboxes/instances/apache24/poc-instance/conf
 [root@webserverhost:/home/osboxes/instances/apache24/poc-instance/conf]#sed -i 's/Listen 80/Listen 10001/g' httpd.conf
[root@webserverhost:/home/osboxes/instances/apache24/poc-instance/conf]#sed -i 's/#ServerName www.example.com:80/ServerName webserverhost:10001/g' httpd.conf
[root@webserverhost:/home/osboxes/instances/apache24/poc-instance/conf]#sed -i 's/User daemon/User osboxes/g' httpd.conf
[root@webserverhost:/home/osboxes/instances/apache24/poc-instance/conf]#sed -i 's/Group daemon/Group osboxes/g' httpd.conf


Step 14) Create log sylink to point the logs to a desired location where we wanted

[root@webserverhost:/home/osboxes/instances/apache24/poc-instance/conf]#cd ..

root@webserverhost:/home/osboxes/instances/apache24/poc-instance#rm -rf logs/
root@webserverhost:/home/osboxes/instances/apache24/poc-instance#ln -s /home/osboxes/logs/apache24/poc-instance logs
[root@webserverhost:/home/osboxes/instances/apache24/poc-instance]#chown -R osboxes:osboxes logs

Step 15) Start Apache instance with osboxes user

[root@webserverhost poc-instance]# exit
logout
[osboxes@webserverhost bin]$ cd /home/osboxes/instances/apache24/poc-instance/bin/
[osboxes@webserverhost bin]$ ./apachectl start


Step 16) Verify the status of apache instance

[osboxes@webserverhost bin]$ ps -ef | grep httpd
osboxes    71720       1  0 23:45 ?        00:00:00 /home/osboxes/instances/apache24/poc-instance/bin/httpd -k start
osboxes    71721   71720  0 23:45 ?        00:00:00 /home/osboxes/instances/apache24/poc-instance/bin/httpd -k start
osboxes    71722   71720  0 23:45 ?        00:00:00 /home/osboxes/instances/apache24/poc-instance/bin/httpd -k start
osboxes    71723   71720  0 23:45 ?        00:00:00 /home/osboxes/instances/apache24/poc-instance/bin/httpd -k start


[osboxes@webserverhost bin]$ curl -Ik http://webserverhost:10001
HTTP/1.1 200 OK
Date: Sat, 13 Feb 2021 04:46:45 GMT
Server: Apache/2.4.46 (Unix)
Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT
ETag: "2d-432a5e4a73a80"
Accept-Ranges: bytes
Content-Length: 45
Content-Type: text/html

[osboxes@webserverhost bin]$ cd /home/osboxes/logs/apache24/poc-instance/
[osboxes@webserverhost poc-instance]$ ls -rlt
total 12
-rw-r--r--. 1 osboxes osboxes   6 Feb 12 23:45 httpd.pid
-rw-rw-r--. 1 osboxes osboxes 758 Feb 12 23:45 error_log
-rw-rw-r--. 1 osboxes osboxes  71 Feb 12 23:46 access_log

[osboxes@webserverhost poc-instance]$ cat access_log
192.168.1.193 - - [12/Feb/2021:23:46:45 -0500] "HEAD / HTTP/1.1" 200 -








No comments:

Post a Comment