kuniku’s diary

はてなダイアリーから移行(旧 d.hatena.ne.jp/kuniku/)、表示がおかしな箇所はコメントをお願いします。記載されている内容は日付およびバージョンに注意してください。直近1年以上前は古い情報の可能性が高くなります。

centos5.3にapacheのインストール

既にApacheがインストールされていないか確認する
http://itochif.com/contents/Linux/centos5/web/apache_00100.html
より

# rpm -qa httpd
httpd-2.2.3-11.el5_1.centos.3 #このようにhttpd-*.*.*-**.****と表示されれば、Apacheはインストールされています

アンインストールする場合

yum remove httpd

Apacheのインストール
# yum -y install httpd
でインストールできるけども、これじゃちょっともの足りない&バージョンが古いので

http://d.hatena.ne.jp/aiueo88/20090901/1251787696
のように、最新版のソースをダウンロードして 自分でいろいろやってみようってことで。

ディレクトリを移動
# cd /usr/local/src/
ファイルをダウンロード
# wget http://www.meisei-u.ac.jp/mirror/apache/httpd/httpd-2.2.14.tar.gz
ファイルを解凍
tar -xzvf httpd-2.2.14.tar.gz

とそのままやると、以下のようにエラーとなる。

[root@localhost src]# cd httpd-2.2.14
[root@localhost httpd-2.2.14]# ./configure --enable-module=so --enable-ssl --enable-rewrite
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu

Configuring Apache Portable Runtime library ...

checking for APR... reconfig
configuring package in srclib/apr now
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
Configuring APR library
Platform: i686-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.3.9
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/httpd-2.2.14/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
configure failed for srclib/apr

コンパイル環境である

# yum -y install gcc

# yum -y install openssl-devel

を実行してから

./configure ・・・・・
を実行する。

起動スクリプトの作成

インストールしたところ
cd /usr/local/src/httpd-2.2.14

  • ファイルの作成(コピー)

# cp build/rpm/httpd.init /etc/rc.d/init.d/httpd

  • ファイルの編集

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

↓コピーした直後のhttpd内を

apachectl=/usr/sbin/apachectl
httpd=${HTTPD-/usr/sbin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/log/httpd/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
# check for 1.3 configuration
check13 () {
CONFFILE=/etc/httpd/conf/httpd.conf

↓のように書き換える

apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
CONFFILE=/usr/local/apache2/conf/httpd.conf

実行権限の付与とマシン起動時のApache自動起動

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

# chkconfig --add httpd

# chkconfig httpd on

httpd.confの記述ミスを確認する。

# /usr/local/apache2/bin/apachectl configtest

Syntax OK
と表示されれば問題なし。

Apacheの起動

# service httpd start
もしくは
# /etc/rc.d/init.d/httpd restart

  • ブラウザから見られるか確認

・ローカルから見られる。
・外部から見られない。
の場合は
portが開放されていない。マシンとルーターの両方でportを公開する必要がある。

    • ルールを確認

# iptables -L

で現在のパケットフィルタの設定を確認する
(パスが通っていなければ /sbin/iptables

    • ルールをクリア

# iptables -F

※クリアなので、all公開なので注意。

ただし、ここまでのコマンドだけでは保存はされないのでマシン再起動するともとに戻る。

  • iptablesの設定変更をするうえで、参考にできるサイト

http://d.hatena.ne.jp/simiken/20080418/1208483656

    • ファイルを編集する

# vi /etc/sysconfig/iptables

以下のように編集してみる。

# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT <<----ここ port80を開放
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT <<----ここ port8080を開放
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT <<----ここ port22を開放

-A FORWARD -j RH-Firewall-1-INPUT
・・・

    • 設定を保存したら再起動

[root@localhost conf]# service iptables restart
ファイアウォールルールを適用中: [ OK ]
チェインポリシーを ACCEPT に設定中filter [ OK ]
iptables モジュールを取り外し中 [ OK ]
iptables ファイアウォールルールを適用中: [ OK ]
iptables モジュールを読み込み中ip_conntrack_netbios_ns ip_c[ OK ]_ftp

http://fedorasrv.com/iptables.shtml

http://d.hatena.ne.jp/uriyuri/20080704/1215164085

アプリ入れたり、いろいろ試したりするならいっそのこと↑のような なんでもありにしておくほうがよいかも。
運用するわけじゃなく開発用だし。