VineLinux3.x/Apache2.0/インストールおよび設定 のバックアップ(No.7)


概要

WebサーバであるApache2をインストールします。
Vine Plusにrpmが用意されていますが、そのパッケージだとなぜかphpが動かないので、ここではソースからインストールします。オプションを指定しないとpreforkでコンパイルされるみたいなので、workerオプションをつけて入れてみました。apache2は動作モードがいろいろあるみたいで、preforkはapache1と同じ非マルチスレッドでworkerはマルチスレッドらしい。

SSL対応にする場合、openssl-develをあらかじめインストールしておく。

# apt-get install openssl-devel
パッケージリストを読みこんでいます... 完了
依存情報ツリーを作成しています... 完了
以下のパッケージが新たにインストールされます:
  openssl-devel
アップグレード: 0 個, 新規インストール: 1 個, 削除: 0 個, 保留: 1 個
1649kB のアーカイブを取得する必要があります。
展開後に 3788kB のディスク容量が追加消費されます。
取得:1 http://updates.vinelinux.org 3.1/i386/updates openssl-devel 0.9.7d-0vl3.1 [1649kB]
1649kB を 1s 秒で取得しました (1276kB/s)
変更を適用しています...
Preparing...               ########################################### [100%]
   1:openssl-devel         ########################################### [100%]
完了

apache2のダウンロード

# wget http://www.apache.jp/dist/httpd/httpd-2.0.54.tar.gz
--13:25:20--  http://www.apache.jp/dist/httpd/httpd-2.0.54.tar.gz
           => `httpd-2.0.54.tar.gz'
www.apache.jp をDNSに問いあわせています... 210.188.224.37
www.apache.jp[210.188.224.37]:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 7,508,193 [application/x-gzip]
[==============================================>] 7,508,193    473.65K/s    ETA 00:00

13:25:36 (470.85 KB/s) - `httpd-2.0.54.tar.gz' を保存しました [7508193/7508193]

解凍

# tar zxf httpd-2.0.54.tar.gz 

インストール

# cd httpd-2.0.54
# ./configure --with-mpm=worker --enable-so --enable-ssl --enable-dav --enable-dav-fs --enable-rewrite --with-ssl=/usr

configureオプションは適宜行ってください。--with-mpm=worker でマルチスレッドになります。

# make
# make install

標準では、/usr/local/apache2 にインストールされます。アンインストールする場合はこのディレクトリを消すだけでいいらしい。

cgiファイルのためのシンボリックリンク

# ln -s /usr/bin/perl /usr/local/bin/perl

DocumentRoot の作成

# mkdir /home/httpd
# mkdir /home/httpd/html

設定ファイルの編集

# vi /usr/local/apache2/conf/httpd.conf
User nobody
Group nobody

ServerAdmin [email protected]

ServerName example.com:80

HostnameLookups On

DocumentRoot "/home/httpd/html"

<Directory "/home/httpd/html">

DirectoryIndex index.shtml index.html index.php

LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

SetEnvIf Remote_Addr 192.168.0. homelog nolog
SetEnvIf Remote_Addr 127.0.0.1 homelog nolog
SetEnvIf Request_URI "default.ida" wormlog nolog
SetEnvIf Request_URI "root.exe" wormlog nolog
SetEnvIf Request_URI "cmd.exe" wormlog nolog
SetEnvIf Request_URI "Admin.dll" wormlog nolog
SetEnvIf Request_URI "sumthin" wormlog nolog
CustomLog logs/home.log common env=homelog
CustomLog logs/worm.log common env=wormlog
CustomLog logs/access.log combined env=!nolog

ScriptAlias /cgi-bin/ "/home/httpd/cgi-bin/"

<Directory "/home/httpd/cgi-bin/">

AddHandler cgi-script .cgi

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

起動確認

# /usr/local/apache2/bin/apachectl start

とやれば起動します。

# /usr/local/apache2/bin/apachectl stop

とやれば終了します。

動作の確認

/home/httpd/html に適当にindex.htmlを置いて、クライアントよりhttp://[サーバーのIPアドレス]/でアクセスする。表示されればOK。

起動スクリプトの作成

/etc/rc.d/init.d/に起動スクリプトapache2を作ります。
srcには付いてないので、vineのrpmパッケージからパクります。
apache2へのパスを修正します。

# vi /etc/rc.d/ini.d/apache2
#!/bin/bash
#
# 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: apache2
# pidfile: /usr/local/apache2/logs/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=""

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
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 /usr/share/doc/apache2-2.0.50/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
	if [ ! -f /usr/local/apache2/bin/httpd ] ; then
	  echo "test update alternatives"
	  /sbin/update-alternatives --auto apache2
	fi

        daemon $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /usr/local/apache2/logs/accept.lock
        return $RETVAL
}
stop() {
	echo -n $"Stopping $prog: "
	killproc $httpd
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f /usr/local/apache2/logs/accept.lock /usr/local/apache2/logs/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 /usr/local/apache2/logs/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

保存したら、実行権限を与えます。

# chmod 755 /etc/rc.d/init.d/apache2

これで、

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

とやれば起動できます。

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

とやれば停止できます。

自動起動するために、

# setup

を実行して、システムサービスの設定でapache2にチェックをいれ、ブート時に起動するようにします。

外部からアクセスできるように、ルータに穴を空ける

サーバマシンの80番ポートにアクセスできるように、ポートマッピング設定(ルータにより呼び名が異なる)を行う。

コメント

コメントはありません。 Apache2/コメント?

お名前: