LoginSignup
2
4

More than 5 years have passed since last update.

Yum をつかって Apache HTTP Server 2.2 をインストールする

Posted at

[!NOTE]
この記事は 2013/10/13 に momoto.github.io へ投稿した内容を Qiita へ移行してきたものです

 パッケージ管理システムの Yum をつかって、Apache HTTP Server 2.2.15 をインストールします。OS は CentOS 6 を使用しています。

 RHEL 6 互換の CentOS の標準リポジトリでは httpd パッケージで Apache HTTP Server が提供されています。パッケージの情報は yum info <パッケージ名> で調べることができます。 パッケージ情報が示すとおり、httpd パッケージ (i686) からインストールできる Apache のバージョンは 2.2.15 になります。

$ yum info httpd

Available Packages
Name        : httpd
Arch        : i686
Version     : 2.2.15
Release     : 29.el6.centos
Size        : 828 k
Repo        : updates
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
            : web server.

 インストールには yum install <パッケージ名> を実行するだけで、パッケージ管理システムが依存関係を解決し、必要なパッケージと共にインストールが完了します。

$ sudo yum install httpd
Setting up Install Process

...

Installed:
  httpd.i686 0:2.2.15-29.el6.centos

Dependency Installed:
  apr.i686 0:1.3.9-5.el6_2                    apr-util.i686 0:1.3.9-3.el6_0.1
  apr-util-ldap.i686 0:1.3.9-3.el6_0.1        httpd-tools.i686 0:2.2.15-29.el6.centos
  mailcap.noarch 0:2.1.31-2.el6

Complete!

 httpd パッケージが提供しているファイルは rpm -ql httpd で一覧を得られますが、出力は 300 行以上に及ぶためディレクトリごとにファイルの役割をみてみます。

$ rpm -ql httpd | gawk -F/ '{print "/"$2"/"$3}' | uniq -c
     10 /etc/httpd
      1 /etc/logrotate.d
      2 /etc/rc.d
      2 /etc/sysconfig
     66 /usr/lib
      8 /usr/sbin
     12 /usr/share
      1 /var/cache
      1 /var/lib
      1 /var/log
      1 /var/run
    252 /var/www

表) httpdパッケージが提供するファイルやディレクトリの概要

ファイルまたはディレクトリ 説明
/etc/httpd/ conf/httpd.conf など設定ファイルを格納しているディレクトリ(サーバルート)
/etc/logrotate.d/httpd httpd のログローテーションの設定
/etc/rc.d/init.d/{htcacheclean, httpd} httpd と htcachecleanの起動スクリプト
/etc/sysconfig/{htcacheclean, httpd} prefork か worker の切り替え等、サービスの設定ファイル
/usr/lib/httpd/modules/mod_*.so Apache モジュールの共有ライブラリファイル
/usr/sbin/{apachectl, httpd} Apache 各種コマンドの実行ファイル
/usr/share/{doc/, man/} Apache のドキュメントや man ページ
/var/cache/mod_proxy/ mod_disk_cache の CacheRoot ディレクトリ
/var/lib/dav/ mod_dav のロックデータベースディレクトリ
/var/log/httpd/ httpd のログを格納するディレクトリ
/var/run/httpd/ httpd のプロセス ID ファイルを格納するディレクトリ
/var/www/ HTML ファイル等のコンテンツを格納しているディレクトリ(/var/www/html がデフォルトのドキュメントルート)

 httpd-2.2.15-29.el6.centos.i686 では、実行ファイルの httpd (prefork) と httpd.worker はそれぞれ次のようにコンパイルされています。

$ /usr/sbin/httpd -V
...
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

$ /usr/sbin/httpd.worker -V
...
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/worker"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

 service ユーティリティをつかって httpd を起動させたあと、curl でウェブサーバの動作を確認してみます。

$ sudo service httpd start
                                                           [  OK  ]
$ curl -D - -s -o /dev/null localhost
HTTP/1.1 403 Forbidden
Date: Sun, 13 Oct 2013 09:08:07 GMT
Server: Apache/2.2.15 (CentOS)
Accept-Ranges: bytes
Content-Length: 5039
Connection: close
Content-Type: text/html; charset=UTF-8

 デフォルトの設定のままでは DocumentRoot (/var/www/html) のDirectoryIndex (index.html) が見つからず、/etc/httpd/conf.d/welcome.conf では Options -Indexes が設定されているため、 HTTP ステータスコードは 403 Forbidden 、メッセージボディには /var/www/error/noindex.html を応答しています。

 /var/www/html/index.html を作成したあとに再度リクエストしてみると 200 OK を応答するようになります。

$ echo '<html><body>It works!</body></html>' | sudo tee /var/www/html/index.html
<html><body>It works!</body></html>
$ curl -D - localhost
HTTP/1.1 200 OK
Date: Sun, 13 Oct 2013 09:12:35 GMT
Server: Apache/2.2.15 (CentOS)
Last-Modified: Sun, 13 Oct 2013 09:12:16 GMT
ETag: "20584-24-4e8a167dd7f45"
Accept-Ranges: bytes
Content-Length: 36
Connection: close
Content-Type: text/html; charset=UTF-8

<html><body>It works!</body></html>

参考

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4