>> HOME >> CentOS 4 MENU >> Webサーバー (Apache)
Apache とは世界で最も普及している Web Server(ホームページを公開する機能)で無料で入手する事ができます。
Apache には 1.3系と 2.0系が公開されており、主な違いは 2.0系が マルチスレッド で動作すると言うことらしいです。

1. Apache のインストール
1 ) httpd のインストール
2 ) PHP のインストール
2. Apache の設定
1 ) httpd 設定ファイル /etc/httpd/conf/httpd.conf の編集
3. CGIを実行するPerlのシンボリックリンクを貼る(FreeのCGIを使用する際の対応)
4. Apache の起動
1 ) httpd の起動
2 ) httpd の自動起動設定
5. Apache の動作確認
1 ) Windowsクライアントから実施(ブラウザ)
2 ) テストページの削除
6. 公開前の準備
1. Apache のインストール
1 ) httpd のインストール
[root@linux ~]# yum -y install httpd 
Repository dag is listed more than once in the configuration
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for httpd to pack into transaction set.
httpd-2.0.52-22.ent.cento 100% |=========================|  62 kB    00:00
---> Package httpd.i386 0:2.0.52-22.ent.centos4 set to be updated
--> Running transaction check
--> Processing Dependency: apr >= 0.9.4-24.2 for package: httpd
--> Processing Dependency: httpd-suexec for package: httpd
--> Processing Dependency: libaprutil-0.so.0 for package: httpd
--> Processing Dependency: libapr-0.so.0 for package: httpd
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for apr to pack into transaction set.
apr-0.9.4-24.5.c4.1.i386. 100% |=========================| 7.5 kB    00:00
---> Package apr.i386 0:0.9.4-24.5.c4.1 set to be updated
---> Downloading header for apr-util to pack into transaction set.
apr-util-0.9.4-21.i386.rp 100% |=========================| 5.2 kB    00:00
---> Package apr-util.i386 0:0.9.4-21 set to be updated
---> Downloading header for httpd-suexec to pack into transaction set.
httpd-suexec-2.0.52-22.en 100% |=========================|  21 kB    00:00
---> Package httpd-suexec.i386 0:2.0.52-22.ent.centos4 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 httpd                   i386       2.0.52-22.ent.centos4  base              887 k
Installing for dependencies:
 apr                     i386       0.9.4-24.5.c4.1  base               88 k
 apr-util                i386       0.9.4-21         base               51 k
 httpd-suexec            i386       2.0.52-22.ent.centos4  base               28 k

Transaction Summary
=============================================================================
Install      4 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 1.0 M
Downloading Packages:
(1/4): apr-0.9.4-24.5.c4. 100% |=========================|  88 kB    00:00
(2/4): httpd-2.0.52-22.en 100% |=========================| 887 kB    00:02
(3/4): apr-util-0.9.4-21. 100% |=========================|  51 kB    00:00
(4/4): httpd-suexec-2.0.5 100% |=========================|  28 kB    00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: apr                          ######################### [1/4]
  Installing: apr-util                     ######################### [2/4]
  Installing: httpd                        ######################### [3/4]
  Installing: httpd-suexec                 ######################### [4/4]

Installed: httpd.i386 0:2.0.52-22.ent.centos4
Dependency Installed: apr.i386 0:0.9.4-24.5.c4.1 apr-util.i386 0:0.9.4-21 httpd-suexec.i386
0:2.0.52-22.ent.centos4
Complete!
2 ) PHP のインストール
[root@linux ~]# yum -y install php 
Repository dag is listed more than once in the configuration
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php to pack into transaction set.
php-4.3.9-3.15.i386.rpm   100% |=========================|  23 kB    00:00
---> Package php.i386 0:4.3.9-3.15 set to be updated
--> Running transaction check
--> Processing Dependency: php-pear for package: php
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-pear to pack into transaction set.
php-pear-4.3.9-3.15.i386. 100% |=========================|  33 kB    00:00
---> Package php-pear.i386 0:4.3.9-3.15 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 php                     i386       4.3.9-3.15       update            1.3 M
Installing for dependencies:
 php-pear                i386       4.3.9-3.15       update            266 k

Transaction Summary
=============================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 1.6 M
Downloading Packages:
(1/2): php-pear-4.3.9-3.1 100% |=========================| 266 kB    00:00
(2/2): php-4.3.9-3.15.i38 100% |=========================| 1.3 MB    00:04
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: php                          ######################### [1/2]
  Installing: php-pear                     ######################### [2/2]

Installed: php.i386 0:4.3.9-3.15
Dependency Installed: php-pear.i386 0:4.3.9-3.15
Complete!
2. Apache の設定
1 ) httpd 設定ファイル /etc/httpd/conf/httpd.conf の編集
[root@linux ~]# vi /etc/httpd/conf/httpd.conf 

#
# Don't give away too much information about all the subcomponents
# we are running.  Comment out this line if you don't mind remote sites
# finding out what major optional modules you are running
#
# Server HTTP 応答ヘッダでOS名を表示しないようにする
ServerTokens Prod
  :
  :
#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
# サーバがクライアントに送るエラーメッセージに含める電子メールのアドレスを指定
ServerAdmin webmaster@mountainbigroad.jp

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work.  See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make 
# redirections work in a sensible way.
#
# サーバが自分自身を示すときに使うホスト名とポートを指定
ServerName mountainbigroad.jp:80
  :
  :
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/html">

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
    # SSIの許可(コマンドExec含む)、CGIの許可、シンボリックリンク許可
    Options Includes ExecCGI FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    # .htaccessの許可
    AllowOverride All

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>
  :
  :
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
# 414 Error(Request URI Too Large)はログに記録しない
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

#
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here.  Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
#
# CustomLog logs/access_log common
# ログの記録内容変更(worm、Local からのアクセスはログに記録しない)
SetEnvIf Request_URI "default\.ida" no_log
SetEnvIf Request_URI "cmd\.exe" no_log
SetEnvIf Request_URI "root\.exe" no_log
SetEnvIf Request_URI "Admin\.dll" no_log
SetEnvIf Request_URI "NULL\.IDA" no_log
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" no_log
SetEnvIf Remote_Addr 192.168. no_log
CustomLog logs/access_log combined env=!no_log
  :
  :
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of:  On | Off | EMail
#
# エラーページ等でApacheのバージョンを表示しない
ServerSignature Off
  :
  :
#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

#
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/var/www/cgi-bin">
    # /var/www/cgi-bin/ 以下も .htaccess を許可
    #AllowOverride None
    AllowOverride All
    Options None
    Order allow,deny
    Allow from all
</Directory>
  :
  :
#
# Specify a default charset for all pages sent out. This is
# always a good idea and opens the door for future internationalisation
# of your web site, should you ever want it. Specifying it as
# a default does little harm; as the standard dictates that a page
# is in iso-8859-1 (latin1) unless specified otherwise i.e. you
# are merely stating the obvious. There are also some security
# reasons in browsers, related to javascript and URL parsing
# which encourage you to always set a default char set.
#
# デフォルトキャラセットを無効にする
AddDefaultCharset Off
  :
  :
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
# CGIスクリプトを実行できる様にする
AddHandler cgi-script .cgi .pl
3. CGIを実行するPerlのシンボリックリンクを貼る(FreeのCGIを使用する際の対応)
[root@linux ~]# ln -s /usr/bin/perl /usr/local/bin/perl 

[root@linux ~]# whereis perl 
perl: /usr/bin/perl /usr/local/bin/perl /usr/share/man/man1/perl.1.gz
4. Apache の起動
1 ) httpd の起動
[root@linux ~]# service httpd start 
httpdを起動中:                                             [  OK  ]
2 ) httpd の自動起動設定
[root@linux ~]# chkconfig httpd on 
[root@linux ~]# chkconfig --list httpd 
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
5. Apache の動作確認
1 ) Windowsクライアントから実施(ブラウザ)
Windowsクライアントより [http://サーバのアドレス/] でアクセスして以下の様な画面が表示されればOKです。
Welcome Apache httpd Server
2 ) テストページの削除
確認で使用したページ関連は、今後必要ないので削除します。
[root@linux ~]# rm -f /etc/httpd/conf.d/welcome.conf 
[root@linux ~]# rm -f /var/www/error/noindex.html 
6. 公開前の準備
ホームページを外部に公開するには、ルータの設定で ポート番号80番(HTTP World Wide Web) を開けてください。
また、外部よりDNS名でアクセスするには、ドメイン名の取得を行っている必要があります。