CentOSにApache HTTPDをインストールする。

まずは必要なバージョンのソースファイルをダウンロードし、解凍します。

cd /usr/local/src/

wget http://ftp.jaist.ac.jp/pub/apache//httpd/httpd-2.2.17.tar.gz

tar zxvf httpd-2.2.17.tar.gz


解凍したディレクトリに移動し、コンパイルを行います。

cd httpd-2.2.17/

./configure --prefix=/usr/local/httpd --enable-rewrite=shared
make
make install

上記は /usr/local/httpdディレクトリにインストールし、mod_rewrite モジュールもインストールします。


起動スクリプトを作成します。

cp /usr/local/src/httpd-2.2.17/build/rpm/httpd.init /etc/rc.d/init.d/httpd

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


以下のように修正します。

#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# httpd        Startup script for the Apache Web Server
#
# chkconfig: 235 85 15
# description: The Apache HTTP Server is an efficient and extensible  \
#             server implementing the current HTTP standards.
# processname: httpd
# pidfile: /var/run/httpd/httpd.pid
# config: /usr/local/httpd/conf/httpd.conf
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
#  implementing the current HTTP standards.
### END INIT INFO

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

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# 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=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

httpd=/usr/local/httpd/bin/httpd
prog=httpd
pidfile=/var/run/httpd/httpd.pid
lockfile=/var/lock/subsys/httpd
RETVAL=0

# check for 1.3 configuration
check13 () {
        CONFFILE=/usr/local/httpd/conf/httpd.conf
        GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
        GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
        GONE="${GONE}AccessConfig|ResourceConfig)"
        if grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
                echo
                echo 1>&2 " Apache 1.3 configuration directives found"
                echo 1>&2 " please read @docdir@/migration.html"
                failure "Apache 1.3 config directives test"
                echo
                exit 1
        fi
}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        check13 || exit 1
#        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        daemon $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
stop() {
        echo -n $"Stopping $prog: "
#        killproc -p ${pidfile} $httpd
        killproc $httpd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
        echo -n $"Reloading $prog: "
        check13 || exit 1
#        killproc -p ${pidfile} $httpd -HUP
        killproc $httpd -HUP
        RETVAL=$?
        echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        if ! test -f ${pidfile}; then
            echo $prog is stopped
            RETVAL=3
        else
            status -p {$pidfile} $httpd
            RETVAL=$?
        fi
        ;;
  restart)
       stop
       start
       ;;
  condrestart)
        if test -f ${pidfile} && status -p ${pidfile} $httpd >&/dev/null; then
                stop
                start
        fi
        ;;
  reload)
        reload
        ;;
  configtest)
        LANG=$HTTPD_LANG $httpd $OPTIONS -t
        RETVAL=$?


動作確認を行います。

/etc/rc.d/init.d/httpd start


問題がなければ chkconfig に登録します。

chkconfig --add httpd
chkconfig httpd on