Saturday, August 1, 2009

Installing Apache2 on Linux



Step1: Get tar.gz packages for apache

Download appropriate package
#wget http://apache.mirror.facebook.net/httpd/httpd-2.2.11.tar.gz

Step2: Configure and Install Apache

#tar -xvxf httpd-2.2.11.tar.gz
# mv httpd-2.2.11 /usr/local/
#cd /usr/local/httpd-2.2.11
#./configure
#make
#make install

By default apache will install on /usr/local/apache2


Step3: Configure Apche to start automatically on reboot

# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

Add the fllowing lines to /etc/init.d/httpd

#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve
# HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache/logs/httpd.pid
# config: /usr/local/apache/conf/httpd.conf
#
Then execute the below commands

# chmod 755 /etc/init.d/httpd
# chkconfig --add httpd
# chkconfig --level 35 httpd on


Note [ If you need a more detailed feedback we can use the below scrip as startup script]


#!/bin/bash
# httpd Startup script for the Apache HTTP Server
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server. It is used to serve
# HTML files and CGI.
# processname: httpd
# config: /usr/local/apache2/conf/httpd.conf
# pidfile: /var/run/apache2.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/apache2.pid}
lockfile=${LOCKFILE-/var/lock/subsys/apache2}
RETVAL=0

start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc $httpd -HUP
RETVAL=$?
fi
echo
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac

exit $RETVAL





Step4: Add path variabled if required

Create a file /etc/profile.d/apache2

# touch /etc/profile.d/apache2
# chmod +x /etc/profile.d/apache2
#vi /etc/profile.d/apache2

#***** Set Env Variables for Apche

APACHE_HOME=/usr/local/apache2
export APACHE_HOME
export PATH=$APACHE_HOME/bin:$PATH



Logout from shell to get this updated


End Of the Document
*******************************************
Courtesy: http://olex.openlogic.com

No comments:

Post a Comment