CentOSでApacheのインストールと設定

httpdパッケージをインストールします。

$ sudo yum -y install httpd
$ yum info httpd
Loaded plugins: fastestmirror
Installed Packages
Name       : httpd
Arch       : x86_64
Version    : 2.2.3
Release    : 45.el5.centos
Size       : 3.3 M
Repo       : installed
Summary    : Apache HTTP Server
URL        : http://httpd.apache.org/
License    : Apache Software License
Description: The Apache HTTP Server is a powerful, efficient, and extensible
           : web server.
$ sudo cp /etc/httpd/httpd.conf /etc/httpd/httpd.conf.org

設定ファイルは/etc/httpd/httpd.confです。

# sudo vi /etc/httpd/httpd.conf

ServerTokens Prod               #レスポンスヘッダにOSのバージョンを表示させない
ServerAdmin anmino@localhost
ServerName 192.168.54.10
Options -Indexes FollowSymLinks #ファイル一覧ページを表示しない
AllowOverride All               #.htaccessを許可
ServerSignature Off             #エラー画面でApacheのバージョン非表示

設定ファイルの文法チェックをする。

$ sudo apachectl configtest 
Syntax OK

Apacheを起動させ、サービスに登録。

$ sudo service httpd start
httpd を起動中:                                            [  OK  ]
$ sudo chkconfig httpd on
$ sudo chkconfig --list
httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

ファイアーウォールの設定と再起動

$ sudo vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
$ sudo service iptables restart