Installing Apache from Source Code on CentOS

Tadashi Shigeoka ·  Tue, November 1, 2011

I installed Apache 2.2.21 from source code on CentOS 5.7.

Here’s a rough overview of the installation procedure. (Will be updated as needed)

Remove RPM version of apache

Remove the RPM version of apache that’s installed by default on CentOS.

# httpd -v
Server version: Apache/2.2.3
# rpm -e --allmatches --nodeps httpd
# httpd -v
-bash: /usr/sbin/httpd: No such file or directory

Download and extract Apache source code

Download and extract the Apache source code.

Get the Unix Source of the Stable version from the following site using wget.

・Download:Download - The Apache HTTP Server Project

$ su -
# cd /usr/local/src/
# wget http://www.meisei-u.ac.jp/mirror/apache/dist//httpd/httpd-2.2.21.tar.gz
# tar zxvf httpd-2.2.21.tar.gz
# cd httpd-2.2.21

Install Apache from source code

Configure with several options.

# cd httpd-2.2.21
# ./configure --prefix=/usr/local/apache2/ \\
    --enable-so \\
    --enable-rewrite \\
    --enable-ssl=/usr/local/openssl

→ Since an error occurs when openssl isn’t installed, for now:  

# ./configure --prefix=/usr/local/apache2/ \\
    --enable-so \\
    --enable-rewrite

Then make and install:

# make
# make install

Verify that Apache was installed properly.

# /usr/local/apache2/bin/httpd -v
Server version: Apache/2.2.21 (Unix)
Server built:   Nov  2 2011 19:14:14

Create apache user

# groupadd apache
# useradd -g apache -d /var/empty/ -s /sbin/nologin apache
# vi /usr/local/apache2/conf/httpd.conf 
User apache
Group apache

 

Configure apache startup script

# cp /usr/local/src/httpd-2.2.21/build/rpm/httpd.init /etc/rc.d/init.d/httpd
# chmod 755 /etc/rc.d/init.d/httpd

Edit the relevant parts of the apache configuration file.

# vi /etc/rc.d/init.d/httpd

httpd=${HTTPD-/usr/local/apache2/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache2/logs/httpd.pid}
# check for 1.3 configuration
check13 () {
        CONFFILE=/usr/local/apache2/conf/httpd.conf

Verify Apache startup.  

# service httpd start 
Starting httpd:  [OK]

Normal startup confirmed.

Check the IP address with ifconfig command. (IP address varies by environment)  

# ifconfig
inet addr:192.168.16.130

 

From your local PC’s browser, access http://192.168.16.130/ to verify that Apache is running normally.

Installation is complete when the browser displays successfully.  

Configure Apache auto-startup

Enable Apache auto-startup.

When auto-startup is enabled, Apache will automatically start when CentOS boots.

# chkconfig --add httpd
# chkconfig httpd on
# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

Firewall configuration verification

Open port 80 (default) that httpd listens on.

# vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

Restart the firewall.

# service iptables restart
Applying firewall rules:                                  [  OK  ]
Setting chain policy to ACCEPT filter                    [  OK  ]
Unloading iptables modules                                [  OK  ]
Applying iptables firewall rules:                        [  OK  ]
# service iptables start

 

Install OpenSSL from source code

# cd /usr/local/src
# wget -c http://www.openssl.org/source/openssl-1.0.0d.tar.gz
# tar zxvf openssl-1.0.0d.tar.gz
# cd openssl-1.0.0d.tar.gz
# ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl -fPIC
# make
# make install

 

【Reference】

apache2.2 initial configuration

Installing CentOS on VMware Player. Building Practice Web Server 4

Installing apache2.2.15 from source on CentOS[Linux] | QUALL - blog

Apache Server Construction (Source Compile) | Home Server Construction

Installing Apache2 from Source

That’s all from the Gemba.