はじめての自宅サーバ構築 - Fedora/CentOS - Last Update 2010/02/03
It opened to 2004/09/19. Visitors
Pageviews
Today(IP/PV)
4,747,753
20,125,113
985/3,678
動作確認 [ FC1 / FC2 / FC3 / FC4 / FC5 / FC6 / Fedora7 / Fedora8 / Fedora9 / Fedora10 / Fedora11 / Fedora12 / CentOS4 / CentOS5 ]
  1. apacheとは・・・
  2. apacheとPHPのインストール
  3. apacheの設定
  4. CGIを実行するPerlのシンボリックリンクを貼る(FreeのCGIを使用する際の対応)
  5. apacheの起動
  6. OSの再起動を行なった時にapacheを自動的に起動するように設定する
  7. apache動作の確認
  8. 各機能の動作確認
    自作のHTMLを表示する。
    SHTML(SSI)をの動作確認を行なう。
    CGIの動作確認を行なう。
    PHPの動作確認を行なう。
  9. 公開前の準備
  10. こんな時は・・・
    Webサーバ(apache)が正常動作しない
    バーチャルホストなど、ちょとした事を行いたい

■ apacheとは・・・

Apacheとは世界で最も普及しているWeb Server(ホームページを公開する機能)、で無料で入手する事ができます。
Apacheには1.3系と2.0系が公開されており、主な違いは2.0系がマルチスレッドで動作すると言うことです。
公式サイトにも記載されていますが、Apacheの名称由来は"A PAtCHy server"、パッチだらけのサーバという事らしいです。
Apacheは日々進化?しており、マイナーのバージョンがよく上がります。一昔前は、由来通り機能バグ等でバージョンがコロコロと上がっていましたが、現在はセキュリティ重視でバージョンが上がっているそうです。

■ apacheとPHPのインストール

apache(httpd)のインストール
# yum -y install httpd


PHPのインストール
# yum -y install php

■ apacheの設定

設定ファイルの編集
# vi /etc/httpd/conf/httpd.conf

管理者のメールアドレスを設定する
#
# 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@kajuhome.com


サーバ名を設定する
#
# 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 kajuhome.com:80


ドキュメントルートの指定
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"


ドキュメントルートの設定(ここから)
#
# 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

</Directory>
ドキュメントルートの指定(ここまで)


#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents.  The MultiViews Option can be used for the
# same purpose, but it is much slower.
#
URLの最後が「/」でアクセスされた時の優先表示ファイル名(左から優先され表示される)
DirectoryIndex index.shtml index.html index.htm index.html.var


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


ログの記録内容変更
#
# 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
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


デフォルトキャラセットを無効にする
#
# 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


CGIスクリプトを実行できる様にする
#
# 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.)
#
AddHandler cgi-script .cgi


「cgi-bin」のディレクトリ位置を無効にする

以下が有効であると[http://サーバのアドレス/cgi-bin/xxxxx.cgi]等でアクセスした場合、
「/var/www/cgi-bin/」ディレクトリ内の「xxxxx.cgi」が実行されます。
当サイトでの各紹介ページのCGIディレクトリは「/var/www/html/cgi-bin/」としているので、
以下を無効にしないと不具合(ページが見つかりません等)となってしまいます。

#
# 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">
#    AllowOverride None
#    Options None
#    Order allow,deny
#    Allow from all
#</Directory>

■ CGIを実行するPerlのシンボリックリンクを貼る(FreeのCGIを使用する際の対応)

現在のPerlの位置
# which perl
/usr/bin/perl
シンボリックリンク設定
# ln -s /usr/bin/perl /usr/local/bin/perl
変更後のPerlの位置
# which perl
/usr/local/bin/perl

■ apacheの起動

apache(httpd)を起動する
# /etc/rc.d/init.d/httpd start
httpd を起動中:                                            [  OK  ]

■ OSの再起動を行なった時にapacheを自動的に起動するように設定する

起動時にapache(httpd)を起動する
# chkconfig httpd on
設定内容を確認
# chkconfig --list httpd
httpd           0:オフ  1:オフ  2:オン  3:オン  4:オン  5:オン  6:オフ

■ apache動作の確認

クライアントより[http://サーバのアドレス/]でアクセスして下記の様な画面が表示されれば動作しています。

■ 各機能の動作確認

■ 自作のHTMLを表示する。

下記の試験用「htmlソース」を作成します。
テスト用のHTMLを作成
# vi /var/www/html/index.html
<html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=EUC-JP">
        <title>テストページ</title>
        </head>

        <body>
        HTML(html)表示テスト
        </body>
</html>

作成したHTMLを本来のオーナ・グループにする
# chown apache:apache /var/www/html/index.html
クライアントより[http://サーバのアドレス/]でアクセスして下記の様な画面が表示されれば動作しています。

■ SHTML(SSI)をの動作確認を行なう。

下記の試験用「shtmlソース」を作成します。
テスト用のSHTMLを作成
# vi /var/www/html/index.shtml
<html>
        <head>
        <META http-equiv="Content-Type" content="text/html; charset=EUC-JP">
        <title>テストページ</title>
        </head>

        <body>
        SHTML(SSI)表示テスト<BR>
        <!--#echo var="DATE_LOCAL" -->
        </body>
</html>

作成したSHTMLを本来のオーナ・グループにする
# chown apache:apache /var/www/html/index.shtml
クライアントより[http://サーバのアドレス/]または[http://サーバのアドレス/index.shtml]でアクセスして下記の様な画面が表示されれば動作しています。

■ CGIの動作確認を行なう。

下記の試験用「cgiスクリプト」を作成します。
テスト用のCGIを作成
# vi /var/www/html/test.cgi
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<META http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-JP\">";
print "<title>テストページ</title>\n";
print "</head>\n";
print "<body>\n";
print "CGI表示テスト\n";
print "</body>\n";
print "</html>\n";

作成したCGIスクリプトを本来のオーナ・グループにする
# chown apache:apache /var/www/html/test.cgi

作成したCGIスクリプトを実行可能にする(パーミッション変更)
# chmod 750 /var/www/html/test.cgi
クライアントより[http://サーバのアドレス/test.cgi]でアクセスして下記の様な画面が表示されれば動作しています。

■ PHPの動作確認を行なう。

下記の試験用「phpスクリプト」を作成します。
テスト用のPHPを作成
# vi /var/www/html/test.php
<?php
    phpinfo();
?>

作成したphpスクリプトを本来のオーナ・グループにする
# chown apache:apache /var/www/html/test.php
クライアントより[http://サーバのアドレス/test.php]でアクセスして下記の様な画面が表示されれば動作しています。

■ 公開前の準備

ホームページを外部に公開するに当たって、ルータの設定が必要です。
ルータのポート開閉は、ご自分のルータ取扱説明書をご覧ください。
DNS名で接続するには事前にドメイン名の取得を行っている必要があります。(以下は代表的なものであり、また、当サイトが使用させて頂いております)

■ こんな時は・・・

■ Webサーバ(apache)が正常動作しない

CGIスクリプトやページ表示などが表示されない場合などは以下のページを参照ください。

■ バーチャルホストなど、ちょとした事を行いたい

ちょっとしたTIP集を用意してありますので以下をご参考ください。

■ 広告

ページ先頭へ

Copyright(©)2004-2010 First home server construction. All Right Reserved.