Apacheのインストールと設定

さくらVPSではデフォルトでapacheはインストールされていない。なので、早速インストールする。

インストール

yumでインストールするのがお作法のようなので、それにしたがう。

$ sudo yum -y install httpd
$ rpm -q httpd
httpd-2.2.3-53.el5.centos.3

インストールされたバージョンは2.2.3のようである。ちょっと古いね。

起動

$ sudo /usr/sbin/apachectl start

ブラウザからアクセスして無事テストページが表示されることを確認。

OS起動時にApacheを起動するようにする

$ sudo /sbin/chkconfig httpd on
$ /sbin/chkconfig --list|grep httpd
httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

runlevel 2から起動するようになっているけど、まあいいや。

ログ出力ディレクトリのパーミッション変更

ログ出力ディレクトリが作業用ユーザでアクセスできないのは不便なので変更する。

$ sudo chmod a+rX /var/log/httpd

httpd.confの設定

/etc/httpd/conf/httpd.confを編集する。修正点は以下の通り。

  • access_logのフォーマットを common の形式にする
  • server-status を有効にする
  • UserDirを有効にする(.htaccessも有効にする)
===================================================================
RCS file: httpd.conf,v
retrieving revision 1.1
diff -c -r1.1 httpd.conf
*** httpd.conf	2012/01/02 13:26:49	1.1
--- httpd.conf	2012/01/02 14:51:57
***************
*** 214,220 ****
  # information (ExtendedStatus On) or just basic information (ExtendedStatus
  # Off) when the "server-status" handler is called. The default is Off.
  #
! #ExtendedStatus On
  
  #
  # If you wish httpd to run as a different user or group, you must run
--- 214,220 ----
  # information (ExtendedStatus On) or just basic information (ExtendedStatus
  # Off) when the "server-status" handler is called. The default is Off.
  #
! ExtendedStatus On
  
  #
  # If you wish httpd to run as a different user or group, you must run
***************
*** 352,365 ****
      # of a username on the system (depending on home directory
      # permissions).
      #
!     UserDir disable
  
      #
      # To enable requests to /~user/ to serve the user's public_html
      # directory, remove the "UserDir disable" line above, and uncomment
      # the following line instead:
      # 
!     #UserDir public_html
  
  </IfModule>
  
--- 352,365 ----
      # of a username on the system (depending on home directory
      # permissions).
      #
!     #UserDir disable
  
      #
      # To enable requests to /~user/ to serve the user's public_html
      # directory, remove the "UserDir disable" line above, and uncomment
      # the following line instead:
      # 
!     UserDir public_html
  
  </IfModule>
  
***************
*** 367,384 ****
  # Control access to UserDir directories.  The following is an example
  # for a site where these directories are restricted to read-only.
  #
! #<Directory /home/*/public_html>
! #    AllowOverride FileInfo AuthConfig Limit
! #    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
! #    <Limit GET POST OPTIONS>
! #        Order allow,deny
! #        Allow from all
! #    </Limit>
! #    <LimitExcept GET POST OPTIONS>
! #        Order deny,allow
! #        Deny from all
! #    </LimitExcept>
! #</Directory>
  
  #
  # DirectoryIndex: sets the file that Apache will serve if a directory
--- 367,384 ----
  # Control access to UserDir directories.  The following is an example
  # for a site where these directories are restricted to read-only.
  #
! <Directory /home/*/public_html>
!     AllowOverride All
!     Options MultiViews Indexes
!     <Limit GET POST OPTIONS>
!         Order allow,deny
!         Allow from all
!     </Limit>
!     <LimitExcept GET POST OPTIONS>
!         Order deny,allow
!         Deny from all
!     </LimitExcept>
! </Directory>
  
  #
  # DirectoryIndex: sets the file that Apache will serve if a directory
***************
*** 498,504 ****
  # define per-<VirtualHost> access logfiles, transactions will be
  # logged therein and *not* in this file.
  #
! #CustomLog logs/access_log common
  
  #
  # If you would like to have separate agent and referer logfiles, uncomment
--- 498,504 ----
  # define per-<VirtualHost> access logfiles, transactions will be
  # logged therein and *not* in this file.
  #
! CustomLog logs/access_log common
  
  #
  # If you would like to have separate agent and referer logfiles, uncomment
***************
*** 511,517 ****
  # For a single logfile with access, agent, and referer information
  # (Combined Logfile Format), use the following directive:
  #
! CustomLog logs/access_log combined
  
  #
  # Optionally add a line containing the server version and virtual host
--- 511,517 ----
  # For a single logfile with access, agent, and referer information
  # (Combined Logfile Format), use the following directive:
  #
! #CustomLog logs/access_log combined
  
  #
  # Optionally add a line containing the server version and virtual host
***************
*** 900,911 ****
  # with the URL of http://servername/server-status
  # Change the ".example.com" to match your domain to enable.
  #
! #<Location /server-status>
! #    SetHandler server-status
  #    Order deny,allow
  #    Deny from all
  #    Allow from .example.com
! #</Location>
  
  #
  # Allow remote server configuration reports, with the URL of
--- 900,911 ----
  # with the URL of http://servername/server-status
  # Change the ".example.com" to match your domain to enable.
  #
! <Location /server-status>
!     SetHandler server-status
  #    Order deny,allow
  #    Deny from all
  #    Allow from .example.com
! </Location>
  
  #
  # Allow remote server configuration reports, with the URL of