How to install multiple Apache instances in same Server on CentOS 6
To install multiple Apache instances in same Server on CentOS 6
Apache is a modular web server mostly used in Linux that is maintained and developed by a community of open source developers. Apache Web Servers are often used in combination with the MySQL database engine, the HyperText Preprocessor (PHP) scripting language, and other popular scripting languages such as Python and Perl. The Apache server can be run in more than one instances in a single server. There are two methods to achieve this. First is using yum install command and second method is using source code compilation. For running multiple instances in a same server, we need to change port number of individual instance and create a seperate service daemon for every running instance of Apache. This tutorial will explain the installation procedure of running multiple instances of Apache in same Server on CentOS 6.
Installation procedure
Apache First Instance Installation
To proceed with the first instance installation, execute the yum command to install Apache web server with default settings with port number as 80 and press y to continue with the installation process.
[root@linuxhelp ~]# yum install httpd -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirror.dhakacom.com
* extras: mirror.dhakacom.com
* updates: centos-hn.viettelidc.com.vn
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-60.el6.centos.5 will be installed
--> Processing Dependency: httpd-tools = 2.2.15-60.el6.centos.5 for package: httpd-2.2.15-60.el6.centos.5.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.2.15-60.el6.centos.5 will be installed
--> Finished Dependency Resolution
.
.
.
Running Transaction
Installing : httpd-tools-2.2.15-60.el6.centos.5.x86_64 1/2
Installing : httpd-2.2.15-60.el6.centos.5.x86_64 2/2
Verifying : httpd-2.2.15-60.el6.centos.5.x86_64 1/2
Verifying : httpd-tools-2.2.15-60.el6.centos.5.x86_64 2/2
Installed:
httpd.x86_64 0:2.2.15-60.el6.centos.5
Dependency Installed:
httpd-tools.x86_64 0:2.2.15-60.el6.centos.5
Complete!
Now add the following content in document root named index.html. Save and exit the file.
[root@linuxhelp ~]# vim /var/www/html/index.html
Apache Instance One
Start and enable Apache service by running the following set of commands.
[root@linuxhelp ~]# service httpd start Starting httpd: [ OK ] [root@linuxhelp ~]# chkconfig httpd on
To check the configuration of Apache, switch over to the browser and call the target machine' s IP. The first instance of Apache server is running successfully.
Apache Second Instance Installation
Now to install Apache from it’ s source code for second instance. Install the following dependencies needed to compile Apache from source code by executing the following command.
[root@linuxhelp ~]# yum groupinstall " Development Tools" -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
* base: mirror.dhakacom.com
* extras: mirror.dhakacom.com
* updates: centos-hn.viettelidc.com.vn
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
.
.
.
Updated:
binutils.x86_64 0:2.20.51.0.2-5.47.el6_9.1
Complete!
Next install the pcre and pcre-devel packages needed for Apache service.
[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: mirror.vbctv.in
* extras: mirror.vbctv.in
* updates: mirror.vbctv.in
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
.
.
.
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 using below set of wget commands as follows.
[root@linuxhelp ~]# wget https://github.com/apache/httpd/archive/2.4.28.tar.gz -O httpd-2.4.28.tar.gz --2017-10-13 01:12:54-- 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-13 01:12:55-- 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 101K/s in 2m 9s 2017-10-13 01:15:06 (86.7 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-13 01:15:17-- https://github.com/apache/apr/archive/1.6.2.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/tar.gz/1.6.2 [following] --2017-10-13 01:15:18-- https://codeload.github.com/apache/apr/tar.gz/1.6.2 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-1.6.2.tar.gz” [ < => ] 730,808 165K/s in 4.3s 2017-10-13 01:15:24 (165 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-13 01:15:56-- 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-13 01:15:57-- https://codeload.github.com/apache/apr-util/tar.gz/1.6.0 Resolving codeload.github.com... 192.30.253.121, 192.30.253.120 Connecting to codeload.github.com|192.30.253.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 224K/s in 1.9s 2017-10-13 01:16:00 (224 KB/s) - “ apr-util-1.6.0.tar.gz” saved [434431]
Next extract those downloaded packages using tar command.
[root@linuxhelp ~]# tar -xzf apr-1.6.2.tar.gz
[root@linuxhelp ~]# tar -xzf apr-util-1.6.0.tar.gz
[root@linuxhelp ~]# tar -xzf httpd-2.4.28.tar.gz
Move the apr and apr-util packages into srclib directory located under HTTPD directory and also rename the packages as apr and apr-util respectively.
[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 start the compilation of Apache source by moving the prompt to Apache directory and build configure script by executing buildconf script.
[root@linuxhelp ~]# cd httpd-2.4.28
[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)
buildconf: copying libtool helper files using /usr/bin/libtoolize
buildconf: creating include/arch/unix/apr_private.h.in ...
buildconf: creating configure ...
buildconf: generating ' make' outputs ...
buildconf: 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 we need to configure Apache before installing. To see all options in the configuration process, execute the following command and the list of options will be displayed to the user.
[root@linuxhelp httpd-2.4.28]# ./configure --help
`configure' configures this package to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..' ]
.
.
.
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L< lib dir> if you have libraries in a
nonstandard directory < lib dir>
LIBS libraries to pass to the linker, e.g. -l< library>
CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I< include dir> if
you have headers in a nonstandard directory < include dir>
CPP C preprocessor
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Configure the Apache installation by running the below command and mention the directory path for Apache installation.
[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
.
.
.
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 &ndash E
Now install Apache in the current location by running the make command.
[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
.
.
.
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'
Install Apache in it’ s appropriate directory using make install command.
[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 second apache instance is successfully installed. First instance of Apache is running in port number 80 with daemon name httpd. So next configure a seperate daemon name for second Apache instance with the name called “ web” . Execute the following command to check if there is a daemon in the same name. The web command is not working
[root@linuxhelp ~]# web -v
bash: web: command not found
To create a web command, change the default HTTPD daemon name to any name the user requires.
[root@linuxhelp ~]# cd /usr/local/apache2/bin/
[root@linuxhelp bin]# mv httpd web
Now create web command by creating a file named web.sh and enter the following content in the file. Save and exit the file.
[root@linuxhelp ~]# vim /etc/profile.d/web.sh
pathmunge /usr/local/apache2/bin
Reload the current profile by reopening the terminal then check with following command.
[root@linuxhelp ~]# web -v
Server version: Apache/2.4.28 (Unix)
Server built: Oct 13 2017 01:23:36
Next to configure Apache daemon with name called “ web” , open the apachectl script file and there replace the httpd name into web in each and every line of that apachectl script file. Also create a new init script for managing Apache services.
[root@linuxhelp ~]# vim /etc/init.d/web
#!/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 web: "
daemon /usr/local/apache2/bin/web -DSSL
echo
touch /var/lock/subsys/web
stop)
echo -n " Shutting down web: "
killproc web
echo
rm -f /var/lock/subsys/web
rm -f /var/run/web.pid
status)
status web
restart)
$0 stop
$0 start
reload)
echo -n " Reloading web: "
killproc web -HUP
echo
*)
echo " Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
Set the execution permission for init script by running the following command.
[root@linuxhelp ~]# chmod +x /etc/init.d/web
Change the port number for second Apache instance thus the First Apache instance is running with default port 80. Open the second Apache’ s default configuration file and change the port number as 8080. Save and exit the file.
[root@linuxhelp ~]# vim /usr/local/apache2/conf/httpd.conf
Listen 8080
Now create default index file and enter the second instance content in the file. Save and exit the file.
[root@linuxhelp ~]# vim /usr/local/apache2/htdocs/index.html
Apache Instance Two
Start the Apache service with daemon name web by executing the following commands.
[root@linuxhelp ~]# service web start Starting web: [ OK ] [root@linuxhelp ~]# chkconfig web on
Switch over to the browser and call the Machine' s IP address followed by port number that has been configured for Second instance of Apache. The second instance of Apache is running without any glitches.
Thus we conclude the installation and configuration procedure of running multiple instaces of Apache in a single server on CentOS 6.
Comments ( 0 )
No comments available