0 0
Read Time:12 Minute, 42 Second

Remove any the previous installation of Apache if it is installed from yum command in the target system.

Installation procedure

To proceed with the installation procedure, run the below command which installs all the required packages for the source code compilation of Apache and press y to continue with the installation.

[root@linuxtips ~]# yum groupinstall " Development Tools" -y
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Loading mirror speeds from cached hostfile * base: mirrors.vinahost.vn * extras: mirrors.vhost.vn * updates: ftp.iitm.ac.in
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.69-11.el7 will be installed
--> Processing Dependency: m4 > = 1.4.14 for package: autoconf-2.69-11.el7.noarch
--> Processing Dependency: perl(Data::Dumper) for package: autoconf-2.69-11.el7.noarch
---> Package automake.noarch 0:1.13.4-3.el7 will be installed
--> Processing Dependency: perl(Thread::Queue) for package: automake-1.13.4-3.el7.noarch
--> Processing Dependency: perl(TAP::Parser) for package: automake-1.13.4-3.el7.noarch
---> Package bison.x86_64 0:3.0.4-1.el7 will be installed
---> Package byacc.x86_64 0:1.9.20130304-3.el7 will be installed
---> Package cscope.x86_64 0:15.8-10.el7 will be installed
---> Package ctags.x86_64 0:5.8-13.el7 will be installed
---> Package diffstat.x86_64 0:1.57-4.el7 will be installed
---> Package doxygen.x86_64 1:1.8.5-3.el7 will be installed
---> Package flex.x86_64 0:2.5.37-3.el7 will be installed
---> Package gcc.x86_64 0:4.8.5-16.el7 will be installed
.
.
perl-TermReadKey.x86_64 0:2.30-20.el7 perl-Test-Harness.noarch 0:3.28-3.el7 perl-Thread-Queue.noarch 0:3.02-2.el7 perl-XML-Parser.x86_64 0:2.41-10.el7 perl-srpm-macros.noarch 0:1-8.el7 subversion-libs.x86_64 0:1.7.14-11.el7_4 systemtap-client.x86_64 0:3.1-3.el7 systemtap-devel.x86_64 0:3.1-3.el7
Complete!

Now install pcre and pcre-devel packages which is also required for Apache installation by running the following command.

[root@linuxtips ~]# yum install expat-devel pcre pcre-devel openssl-devel -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile * base: mirrors.vinahost.vn * extras: mirrors.vinahost.vn * updates: ftp.iitm.ac.in
Package pcre-8.32-17.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package expat-devel.x86_64 0:2.1.0-10.el7_3 will be installed
---> Package openssl-devel.x86_64 1:1.0.2k-8.el7 will be installed
--> Processing Dependency: zlib-devel(x86-64) for package: 1:openssl-devel-1.0.2k-8.el7.x86_64
--> Processing Dependency: krb5-devel(x86-64) for package: 1:openssl-devel-1.0.2k-8.el7.x86_64
---> Package pcre-devel.x86_64 0:8.32-17.el7 will be installed
--> Running transaction check
---> Package krb5-devel.x86_64 0:1.15.1-8.el7 will be installed
--> Processing Dependency: libverto-devel for package: krb5-devel-1.15.1-8.el7.x86_64
--> Processing Dependency: libselinux-devel for package: krb5-devel-1.15.1-8.el7.x86_64
--> Processing Dependency: libcom_err-devel for package: krb5-devel-1.15.1-8.el7.x86_64
--> Processing Dependency: keyutils-libs-devel for package: krb5-devel-1.15.1-8.el7.x86_64
---> Package zlib-devel.x86_64 0:1.2.7-17.el7 will be installed
--> Running transaction check
---> Package keyutils-libs-devel.x86_64 0:1.5.8-3.el7 will be installed
.
.
Dependency Installed: keyutils-libs-devel.x86_64 0:1.5.8-3.el7 krb5-devel.x86_64 0:1.15.1-8.el7 libcom_err-devel.x86_64 0:1.42.9-10.el7 libselinux-devel.x86_64 0:2.5-11.el7 libsepol-devel.x86_64 0:2.5-6.el7 libverto-devel.x86_64 0:0.2.5-4.el7 zlib-devel.x86_64 0:1.2.7-17.el7
Complete!


Download the Apache source code along with apr and apr-util from Apache’ s official website or from Git repository by using the following URLs

Apache httpd – https://github.com/apache/httpd/releases
Apr – https://github.com/apache/apr/releases
Apr-util – https://github.com/apache/apr-util/releases

or execute the wget command followed by the respective download links.

[root@linuxtips ~]# wget https://github.com/apache/httpd/archive/2.4.28.tar.gz -O httpd-2.4.28.tar.gz
--2017-10-14 15:57:39-- https://github.com/apache/httpd/archive/2.4.28.tar.gz
Resolving github.com (github.com)... 192.30.255.113, 192.30.255.112
Connecting to github.com (github.com)|192.30.255.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/apache/httpd/tar.gz/2.4.28 [following]
--2017-10-14 15:57:41-- https://codeload.github.com/apache/httpd/tar.gz/2.4.28
Resolving codeload.github.com (codeload.github.com)... 192.30.255.120, 192.30.255.121
Connecting to codeload.github.com (codeload.github.com)|192.30.255.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘ httpd-2.4.28.tar.gz’ [ < => ] 1,14,89,746 556KB/s in 27s
2017-10-14 15:58:09 (420 KB/s) - ‘ httpd-2.4.28.tar.gz’ saved [11489746]
[root@linuxtips ~]# wget https://github.com/apache/apr/archive/1.6.2.tar.gz -O apr-1.6.2.tar.gz
--2017-10-14 15:58:18-- https://github.com/apache/apr/archive/1.6.2.tar.gz
Resolving github.com (github.com)... 192.30.255.112, 192.30.255.113
Connecting to github.com (github.com)|192.30.255.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/apache/apr/tar.gz/1.6.2 [following]
--2017-10-14 15:58:20-- https://codeload.github.com/apache/apr/tar.gz/1.6.2
Resolving codeload.github.com (codeload.github.com)... 192.30.255.120, 192.30.255.121
Connecting to codeload.github.com (codeload.github.com)|192.30.255.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘ apr-1.6.2.tar.gz’ [ < => ] 7,30,808 265KB/s in 2.7s
2017-10-14 15:58:24 (265 KB/s) - ‘ apr-1.6.2.tar.gz’ saved [730808]
[root@linuxtips ~]# wget https://github.com/apache/apr-util/archive/1.6.0.tar.gz -O apr-util-1.6.0.tar.gz
--2017-10-14 15:58:31-- https://github.com/apache/apr-util/archive/1.6.0.tar.gz
Resolving github.com (github.com)... 192.30.255.112, 192.30.255.113
Connecting to github.com (github.com)|192.30.255.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/apache/apr-util/tar.gz/1.6.0 [following]
--2017-10-14 15:58:33-- https://codeload.github.com/apache/apr-util/tar.gz/1.6.0
Resolving codeload.github.com (codeload.github.com)... 192.30.255.120, 192.30.255.121
Connecting to codeload.github.com (codeload.github.com)|192.30.255.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘ apr-util-1.6.0.tar.gz’ [ < => ] 4,34,431 243KB/s in 1.7s
2017-10-14 15:58:37 (243 KB/s) - ‘ apr-util-1.6.0.tar.gz’ saved [434431]

All the required packages has been downloaded. Now extract the packages by running the tar command as follows.

[root@linuxtips ~]# tar -xzf httpd-2.4.28.tar.gz
[root@linuxtips ~]# tar -xzf apr-1.6.2.tar.gz
[root@linuxtips ~]# tar -xzf apr-util-1.6.0.tar.gz

Next we need to place apr and apr-util directory inside srclib directory which is located under HTTPD directory, and the name should be in apr and apr-util. Use the following command to move apr and apr-util directory to the respective directory.

[root@linuxtips ~]# mv apr-1.6.2 httpd-2.4.28/srclib/apr
[root@linuxtips ~]# mv apr-util-1.6.0 httpd-2.4.28/srclib/apr-util

Now move to HTTPD directory.

[root@linuxtips ~]# cd httpd-2.4.28

Compilation of Apache source
To build configure script, execute the following buildconf script file as follows.

[root@linuxtips httpd-2.4.28]# ./buildconf
found apr source: srclib/apr
found apr-util source: srclib/apr-util
rebuilding srclib/apr/configure
buildconf: checking installation...
buildconf: python version 2.7.5 (ok)
buildconf: autoconf version 2.69 (ok)
buildconf: libtool version 2.4.2 (ok)
buildconf: copying libtool helper files using /usr/bin/libtoolize
.
.
rebuilding rpm spec file
fixing timestamps for ap_expr sources

Next run the configure command as shown below. You can change the default Apache installation directory path, here we have mentioned /usr/local/apache2 directory path.

[root@linuxtips httpd-2.4.28]# ./configure --enable-ssl --enable-so --with-mpm=event --with-included-apr --prefix=/usr/local/apache2
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
configuring package in srclib/apr now
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.6.2
checking for chosen layout... apr
.
.
configure: summary of build options: Server Version: 2.4.28 Install prefix: /usr/local/apache2 C compiler: gcc -std=gnu99 CFLAGS: -g -O2 -pthread LDFLAGS: LIBS: CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE C preprocessor: gcc -E

Execute the make command to prepare the files for the installation of Apache.

[root@linuxtips httpd-2.4.28]# make
Making all in srclib
make[1]: Entering directory `/root/httpd-2.4.28/srclib'
Making all in apr
make[2]: Entering directory `/root/httpd-2.4.28/srclib/apr'
make[3]: Entering directory `/root/httpd-2.4.28/srclib/apr'
/root/httpd-2.4.28/srclib/apr/build/mkdir.sh tools
/bin/sh /root/httpd-2.4.28/srclib/apr/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I./include -I/root/httpd-2.4.28/srclib/apr/include/arch/unix -I./include/arch/unix -I/root/httpd-2.4.28/srclib/apr/include/arch/unix -I/root/httpd-2.4.28/srclib/apr/include -I/root/httpd-2.4.28/srclib/apr/include/private -I/root/httpd-2.4.28/srclib/apr/include/private -o tools/gen_test_char.lo -c tools/gen_test_char.c & & touch tools/gen_test_char.lo
.
.
make[4]: Leaving directory `/root/httpd-2.4.28/modules/mappers'
make[3]: Leaving directory `/root/httpd-2.4.28/modules/mappers'
make[2]: Leaving directory `/root/httpd-2.4.28/modules'
make[2]: Entering directory `/root/httpd-2.4.28/support'
make[2]: Leaving directory `/root/httpd-2.4.28/support'
make[1]: Leaving directory `/root/httpd-2.4.28' 

Execute the make install command to install Apache in it’ s appropriate directory.

[root@linuxtips httpd-2.4.28]# make install
Making install in srclib
make[1]: Entering directory `/root/httpd-2.4.28/srclib'
Making install in apr
make[2]: Entering directory `/root/httpd-2.4.28/srclib/apr'
make[3]: Entering directory `/root/httpd-2.4.28/srclib/apr'
make[3]: Nothing to be done for `local-all' .
make[3]: Leaving directory `/root/httpd-2.4.28/srclib/apr'
/root/httpd-2.4.28/srclib/apr/build/mkdir.sh /usr/local/apache2/lib /usr/local/apache2/bin /usr/local/apache2/build /usr/local/apache2/lib/pkgconfig /usr/local/apache2/include
mkdir /usr/local/apache2
mkdir /usr/local/apache2/lib
mkdir /usr/local/apache2/bin
mkdir /usr/local/apache2/build
mkdir /usr/local/apache2/lib/pkgconfig
mkdir /usr/local/apache2/include
.
.
mkdir /usr/local/apache2/manual
make[1]: Leaving directory `/root/httpd-2.4.28' 

Now the Apache is successfully installed on the server from it’ s source code. Next run the httpd -v command to check Apache’ s version. A error may appear as shown below.

[root@linuxtips httpd-2.4.28]# httpd -v
bash: httpd: command not found...

To remove that error, create a HTTPD commad manually. Create a script file for httpd command under /etc/profile.d/ directory. Enter the following line in the file and save it.

[root@linuxtips httpd-2.4.28]# vim /etc/profile.d/httpd.sh
pathmunge /usr/local/apache2/bin

The file has been created, now logout from the current session and re-login to reload the profile. Check the Apache version by running the following command.

[root@linuxtips ~]# httpd -v
Server version: Apache/2.4.28 (Unix)
Server built: Oct 13 2017 23:23:07

Create an init script for managing httpd service. So create a httpd file under /etc/init.d/ directory using vim editor and make the following changes in the file. Save and exit the file.

[root@linuxtips ~]# vim /etc/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl -k start
ExecReload=/usr/local/apache2/bin/apachectl -k graceful
ExecStop=/usr/local/apache2/bin/apachectl -k graceful-stop
PIDFile=/usr/local/apache2/logs/httpd.pid
PrivateTmp=true
[Install]
WantedBy=multi-user.target

Reload the Systemctl daemon by executing the following command.

[root@linuxtips ~]# systemctl daemon-reload

Now start and enable your Apache httpd service with the following command.

[root@linuxtips ~]# systemctl start httpd
[root@linuxtips ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /etc/systemd/system/httpd.service.

Switch over to the browser and enter the IP address for the Apache server to run in the target system. It runs without any glitches.

Thus we conclude the installation and configuration of Apache from its Source Code on CentOS 7.