Apache 2.0.45インストール

 Apache2をDSOオプション付きでインストールする方法を解説する。

1.インストール

1-1ソースファイルの展開

/usr/local/srcなどにApache2のソース・ファイルをコピーし、解答する。

# cd /usr/local/src
# tar zxvf httpd-2.0.59.tar.gz

1-2 configureスクリプトの実行

展開してできたソース・ディレクトリに移動し、DSOモジュールを有効にするオプションをつけてconfigureスクリプトを実行。

# cd httpd-2.0.59
# ./configure --enable-so

なお、SSLを有効にしたい場合は、以下のオプションを付けてconfigureスクリプトを実行する

# cd httpd-2.0.59
# ./configure --enable-so --enable-ssl

1-3 コンパイル、インストール

configureが無事終了したら、コンパイル、インストールを行う。

# make
# make install

 Apache2はApache1.xと違い、/usr/local/apache2にインストールされる。

2.Apache2環境設定

 インストールが終わったら、環境設定を行う。ソースからインストールした場合、Apacheの環境設定ファイルhttpd.conf/usr/local/apache2/confの中にある。
 ServerAdmin、ServerNameなどを設定しておく。

User nobody
Group nobody
ServerAdmin エラーメッセージに表示させるメールアドレス
ServerName ホスト名:80 ←コメント解除し、修正


その他、DocumentRootやCGI関係などを必要に応じて設定する

 また、エラーメッセージなどを日本語で表示させるよう、以下のパラメータを修正する。

DefaultLanguage ja ←コメント解除し、修正
LanguagePriority ja en da nl et fr de el it ko no pl pt pt-br ltz ca es sv tw

3.自動起動の設定

 Apache2には、RPM版Apacheの起動スクリプトのサンプルが用意されている。それを/etc/rc.d/init.d/にコピーする。

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

 そのままでは利用できないので、コピーした/etc/rc.d/init.d/httpdをviで開き、次のように修正する。

#!/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.
#
#
# 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: /var/run/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf

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

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

# 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.

# 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
RETVAL=0

# check for 1.3 configuration
check13 () {
        CONFFILE=/usr/local/apache2/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
        daemon $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
        return $RETVAL
}
stop() {
        echo -n $"Stopping $prog: "
        killproc $httpd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid
}
reload() {
        echo -n $"Reloading $prog: "
        check13 || exit 1
        killproc $httpd -HUP
        RETVAL=$?
        echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart)
        if [ -f /var/run/httpd.pid ] ; 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

 ランレベルごとのシンボリック・リンクを作成する。また、自動起動の設定を行う。

# chkconfig --add httpd
# chkconfig httpd on

4.Apacheの起動・停止

Apacheを起動する。

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

Apacheを停止する。

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

Apacheの状態を確認する。

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

5.起動後の確認

 Linuxサーバを再起動し、クライアントからブラウザでhttp://LinuxサーバのIPアドレス/を入力し、Apacheの画面が出るかどうか確かめよう。

 なお、SSLを有効にしてコンパイルした場合、mod_sslが組み込まれるが、SSL関係の設定を一切行っていないため、今の状態では使えない。SSLを使うための設定は別ページで解説する。

6.その他

 ブラウザからhttp://LinuxサーバのIPアドレス/manual/を開くと、Apache2のマニュアルが日本語で表示される。ここにはさまざまな説明、設定方法が載っているため、ここを読んで勉強しよう。

 また、インストール時にコピーされるドキュメントやCGIファイルなど、必要なければ削除しよう。

# rm -f /usr/local/apache2/cgi-bin/*
# rm -rf /usr/local/apache2/htdocs/manual
# rm -f /usr/local/apache2/htdocs/*


[ BACK ]