Apacheのインストール

Apacheのインストールは何回もやってたのに、initスクリプトがsrcの中にあるなんて知らなかった。。。
今までこんなことやってたのが超恥ずかしい。

今まで:恥ずかしくもapachectlにchkconfig記述してた

cd /etc/init.d
ln -s /usr/local/apache2/bin/apachectl apache2

vi /usr/local/apache2/bin/apachectl


# chkconfig: 35 85 15
# description: Apache httpd Web server



/sbin/chkconfig apache2 on
/sbin/chkconfig --list apache2
apache2         0:off   1:off   2:on    3:on    4:on    5:on    6:off

Apacheのインストールまとめ

せっかくなので、いつも忘れるからインストールをまとめてみた。CentOS5.2。


なんも入れてないとこからスタートするので、コンパイラとopenssl入れる。

yum install gcc openssl-devel

Apache2.2.11をソースからインストール。
PHPを使う場合、MPMはpreforkが良い。
ウノウラボ by Zynga Japan: Apache MPM の基礎をしっかりと理解しよう!

cd /usr/local/src
wget http://ftp.riken.jp/net/apache/httpd/httpd-2.2.11.tar.gz
tar xzvf httpd-2.2.11.tar.gz
cd httpd-2.2.11
./configure \
--with-mpm=prefork \
--enable-ssl=shared \
--with-ssl=/usr \
--enable-rewrite=shared \
--enable-so \
--enable-mods-shared=most

make
make install


Apacheのユーザとグループ作る

/usr/sbin/groupadd webgroup
/usr/sbin/adduser -s /bin/false -M -g webgroup webuser

最低限設定。

vi /usr/local/apache2/conf/httpd.conf


User webuser
Group webgroup

ServerTokens Prod
ServerSignature Off


ログのローテーション。logrotateをつかう。
設定したら-dでテスト(テストではログファイルは変更されない)。
設定ファイルに間違いがあった場合、errorがでる。

vi /etc/logrotate.d/apache2
# access_log, error_log, ssl_request_log
/usr/local/apache2/logs/*_log {
        daily
        missingok
        rotate 90
        ifempty
        create 0644 root root
        postrotate
                /bin/kill -HUP `cat /usr/local/apache2/logs/httpd.pid` 2> /dev/null
        endscript
}



/usr/sbin/logrotate -dv /etc/logrotate.d/apache2


80と443ポート開けて確認(CentOS5.2では親切にも開いていない)

/sbin/iptables -I RH-Firewall-1-INPUT 10 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
/sbin/iptables -I RH-Firewall-1-INPUT 11 -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT

/etc/init.d/iptables save
/etc/init.d/iptables restart

/sbin/iptables -L -v --line-number


自動起動設定
build/rpm/httpd.init にあったなんてー!!

sed -e 's/^# chkconfig:.*/# chkconfig: 2345 85 15/' \
-e 's/\/etc\/httpd/\/usr\/local\/apache2/' -e 's/\/usr\/sbin/\/usr\/local\/apache2\/bin/' \
/usr/local/src/httpd-2.2.11/build/rpm/httpd.init > /etc/init.d/apache2

chown root.root /etc/init.d/apache2
chmod 755 /etc/init.d/apache2

/sbin/chkconfig apache2 on
/sbin/chkconfig apache2 --list
apache2         0:off   1:off   2:on    3:on    4:on    5:on    6:off

/etc/init.d/apache2 start


コレでオッケー。