How to install Apache from Source Code on CentOS 6
To install Apache from Source Code on CentOS 6
Apache is a web server used to server web page content over HTTP and HTTPS protocol. For the easy installation of Apache web server we normally use yum install command to install Apache in the system. In this tutorial, we will install Apache by compiling from it' s source code. For compling Apache from it' s source it will require for APR and APR-UTIL, which means Apache Portable Runtime (APR). This tutorial will cover the ground on the installation of Apache from Source code on CentOS 6.
Remove the previous installation of Apache web server in the system if it is installed via yum command.
Installation procedure
To proceed with the installation procedure, run the below command to install all the required packages for the source code compilation of Apache and press y to continue with the installation.
[root@linuxhelp ~]# yum groupinstall " Development Tools" -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
* base: centos.myfahim.com
* epel: mirror.ehost.vn
* extras: centos.myfahim.com
* updates: centos.myfahim.com
epel/group_gz | 150 kB 00:00
Package 1:make-3.81-23.el6.x86_64 already installed and latest version
Package patch-2.6-6.el6.x86_64 already installed and latest version
Package 1:pkgconfig-0.23-9.1.el6.x86_64 already installed and latest version
Package gettext-0.17-18.el6.x86_64 already installed and latest version
Package elfutils-0.164-2.el6.x86_64 already installed and latest version
Package cvs-1.11.23-16.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.63-5.1.el6 will be installed
---> Package automake.noarch 0:1.11.1-4.el6 will be installed
---> Package binutils.x86_64 0:2.20.51.0.2-5.46.el6 will be updated
---> Package binutils.x86_64 0:2.20.51.0.2-5.47.el6_9.1 will be an update
---> Package bison.x86_64 0:2.4.1-5.el6 will be installed
---> Package byacc.x86_64 0:1.9.20070509-7.el6 will be installed
.
.
.
Dependency Installed:
cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-18.el6 gettext-devel.x86_64 0:0.17-18.el6 gettext-libs.x86_64 0:0.17-18.el6
kernel-devel.x86_64 0:2.6.32-696.13.2.el6 libgcj.x86_64 0:4.4.7-18.el6 libgfortran.x86_64 0:4.4.7-18.el6 libstdc++-devel.x86_64 0:4.4.7-18.el6
mpfr.x86_64 0:2.4.1-6.el6 perl-Compress-Raw-Zlib.x86_64 1:2.021-144.el6 perl-Compress-Zlib.x86_64 0:2.021-144.el6 perl-Error.noarch 1:0.17015-4.el6
perl-Git.noarch 0:1.7.1-9.el6_9 perl-HTML-Parser.x86_64 0:3.64-2.el6 perl-HTML-Tagset.noarch 0:3.20-4.el6 perl-IO-Compress-Base.x86_64 0:2.021-144.el6
perl-IO-Compress-Zlib.x86_64 0:2.021-144.el6 perl-URI.noarch 0:1.40-2.el6 perl-XML-Parser.x86_64 0:2.36-7.el6 perl-libwww-perl.noarch 0:5.833-5.el6
ppl.x86_64 0:0.10.2-11.el6 systemtap-client.x86_64 0:2.9-7.el6 systemtap-devel.x86_64 0:2.9-7.el6
Updated:
binutils.x86_64 0:2.20.51.0.2-5.47.el6_9.1
Complete!
Now install pcre and pcre-devel packages which is also required for Apache installation by running the following command.
[root@linuxhelp ~]# yum install expat-devel pcre pcre-devel openssl-devel -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: centos.myfahim.com
* epel: epel.scopesky.iq
* extras: centos.myfahim.com
* updates: centos.myfahim.com
Package pcre-7.8-7.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package expat-devel.x86_64 0:2.0.1-13.el6_8 will be installed
---> Package openssl-devel.x86_64 0:1.0.1e-57.el6 will be installed
--> Processing Dependency: zlib-devel for package: openssl-devel-1.0.1e-57.el6.x86_64
--> Processing Dependency: krb5-devel for package: openssl-devel-1.0.1e-57.el6.x86_64
---> Package pcre-devel.x86_64 0:7.8-7.el6 will be installed
--> Running transaction check
---> Package krb5-devel.x86_64 0:1.10.3-65.el6 will be installed
.
.
.
Installed:
expat-devel.x86_64 0:2.0.1-13.el6_8 openssl-devel.x86_64 0:1.0.1e-57.el6 pcre-devel.x86_64 0:7.8-7.el6
Dependency Installed:
keyutils-libs-devel.x86_64 0:1.4-5.el6 krb5-devel.x86_64 0:1.10.3-65.el6 libcom_err-devel.x86_64 0:1.41.12-23.el6 libselinux-devel.x86_64 0:2.0.94-7.el6 libsepol-devel.x86_64 0:2.0.41-4.el6
zlib-devel.x86_64 0:1.2.3-29.el6
Complete!
Download the Apache source code along with apr and apr-util from Apache' s official website or from Git repository by using below 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@linuxhelp ~]# wget https://github.com/apache/httpd/archive/2.4.28.tar.gz -O httpd-2.4.28.tar.gz --2017-10-11 05:59:10-- https://github.com/apache/httpd/archive/2.4.28.tar.gz Resolving github.com... 192.30.255.112, 192.30.255.113 Connecting to github.com|192.30.255.112|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://codeload.github.com/apache/httpd/tar.gz/2.4.28 [following] --2017-10-11 05:59:11-- https://codeload.github.com/apache/httpd/tar.gz/2.4.28 Resolving codeload.github.com... 192.30.255.120, 192.30.255.121 Connecting to 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” [ < => ] 11,489,746 814K/s in 36s 2017-10-11 05:59:49 (314 KB/s) - “ httpd-2.4.28.tar.gz” saved [11489746] [root@linuxhelp ~]# wget https://github.com/apache/apr/archive/1.6.2.tar.gz -O apr-1.6.2.tar.gz --2017-10-11 05:59:54-- https://github.com/apache/apr/archive/1.6.2.tar.gz Resolving github.com... 192.30.255.113, 192.30.255.112 Connecting to github.com|192.30.255.113|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://codeload.github.com/apache/apr/tar.gz/1.6.2 [following] --2017-10-11 05:59:55-- https://codeload.github.com/apache/apr/tar.gz/1.6.2 Resolving codeload.github.com... 192.30.255.120, 192.30.255.121 Connecting to 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” [ < => ] 730,808 351K/s in 2.0s 2017-10-11 05:59:58 (351 KB/s) - “ apr-1.6.2.tar.gz” saved [730808] [root@linuxhelp ~]# wget https://github.com/apache/apr-util/archive/1.6.0.tar.gz -O apr-util-1.6.0.tar.gz --2017-10-11 06:00:09-- https://github.com/apache/apr-util/archive/1.6.0.tar.gz Resolving github.com... 192.30.255.112, 192.30.255.113 Connecting to 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-11 06:00:11-- https://codeload.github.com/apache/apr-util/tar.gz/1.6.0 Resolving codeload.github.com... 192.30.255.121, 192.30.255.120 Connecting to codeload.github.com|192.30.255.121|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [application/x-gzip] Saving to: “ apr-util-1.6.0.tar.gz” [ < => ] 434,431 130K/s in 3.3s 2017-10-11 06:00:15 (130 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@linuxhelp ~]# tar -xzf httpd-2.4.28.tar.gz
[root@linuxhelp ~]# tar -xzf apr-1.6.2.tar.gz
[root@linuxhelp ~]# 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 below command to move apr and apr-util directory to the respective directory.
[root@linuxhelp ~]# mv apr-1.6.2 httpd-2.4.28/srclib/apr
[root@linuxhelp ~]# mv apr-util-1.6.0 httpd-2.4.28/srclib/apr-util
Now move to HTTPD directory.
[root@linuxhelp ~]# cd httpd-2.4.28
Compilation of Apache source
To build configure script, execute the following buildconf script file as follows.
[root@linuxhelp 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.6.6 (ok)
buildconf: autoconf version 2.63 (ok)
buildconf: libtool version 2.2.6b (ok)
.
.
.
rebuilding rpm spec file
copying build files
rebuilding include/ap_config_auto.h.in
rebuilding configure
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@linuxhelp 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... /bin/grep
checking for egrep... /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
.
.
.
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
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@linuxhelp 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
/bin/sh /root/httpd-2.4.28/srclib/apr/libtool --silent --mode=link 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 -no-install -o tools/gen_test_char tools/gen_test_char.lo -lrt -lcrypt -lpthread
/root/httpd-2.4.28/srclib/apr/build/mkdir.sh include/private
.
.
.
se -I/root/httpd-2.4.28/modules/filters -I/root/httpd-2.4.28/modules/ldap -I/root/httpd-2.4.28/modules/loggers -I/root/httpd-2.4.28/modules/lua -I/root/httpd-2.4.28/modules/proxy -I/root/httpd-2.4.28/modules/session -I/root/httpd-2.4.28/modules/ssl -I/root/httpd-2.4.28/modules/test -I/root/httpd-2.4.28/server -I/root/httpd-2.4.28/modules/arch/unix -I/root/httpd-2.4.28/modules/dav/main -I/root/httpd-2.4.28/modules/generators -I/root/httpd-2.4.28/modules/mappers -prefer-pic -c mod_rewrite.c & & touch mod_rewrite.slo
/root/httpd-2.4.28/srclib/apr/libtool --silent --mode=link gcc -std=gnu99 -g -O2 -pthread -o mod_rewrite.la -rpath /usr/local/apache2/modules -module -avoid-version mod_rewrite.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'
Exectue the make install command to install Apache to it' s appropriate directory.
[root@linuxhelp 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
.
.
.
Installing CGIs
mkdir /usr/local/apache2/cgi-bin
Installing header files
Installing build system files
Installing man pages and online manual
mkdir /usr/local/apache2/man
mkdir /usr/local/apache2/man/man1
mkdir /usr/local/apache2/man/man8
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 version. A error may appear as shown below.
[root@linuxhelp ~]# 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@linuxhelp ~]# vim /etc/profile.d/httpd.sh
pathmunge /usr/local/apache2/bin
The file has been created, now logout from the current session and relogin to reload the profile. Check the Apache version by running the following command.
[root@linuxhelp ~]# httpd -v
Server version: Apache/2.4.28 (Unix)
Server built: Oct 11 2017 06:10:14
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@linuxhelp ~]# vim /etc/init.d/httpd
#!/bin/sh
#
# Startup script for the Apache Web Server
#
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server. It is used to serve
# HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/httpd.conf
# Source function library.
. /etc/rc.d/init.d/functions
# See how we were called.
case " $1" in
start)
echo -n " Starting httpd: "
daemon /usr/local/apache2/bin/httpd -DSSL
echo
touch /var/lock/subsys/httpd
stop)
echo -n " Shutting down httpd: "
killproc httpd
echo
rm -f /var/lock/subsys/httpd
rm -f /var/run/httpd.pid
status)
status httpd
restart)
$0 stop
$0 start
reload)
echo -n " Reloading httpd: "
killproc httpd -HUP
echo
*)
echo " Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
Create the new init script for httpd executable using below command.
[root@linuxhelp ~]# chmod +x /etc/init.d/httpd
Now manage httpd service via command line as shown below.
[root@linuxhelp ~]# service httpd start Starting httpd: [ OK ] [root@linuxhelp ~]# chkconfig httpd on
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 concludes the installation of Apache from Source code on CentOS 6.
Comments ( 0 )
No comments available