PHP5 のインストール


# apt-get update ← APTデータベース更新

※ Apache1.3系との違いはphp5-apache → php5-apache2になった所です。

# apt-get install php5 php5-apache2 php5-devel php5-pear php5-mysql ← インストール

apache2 MPMをworker → prefork に変更

PHPをインストールしたのですが、どうも動いてくれませんでした。
apache2 MPMをworker → prefork に変更する事で、すんなり動くようになりました。

# update-alternatives --config apache2 ← 設定

There are 4 alternatives which provide `apache2'.

 Selection    Alternative
-----------------------------------------------
 +    1        /usr/sbin/apache2.worker
 *    2        /usr/sbin/apache2.prefork
      3        /usr/sbin/apache2.threadpool
      4        /usr/sbin/apache2.perchild

Press enter to keep the default[*], or type selection number: 2 ← preforkを選択

PHPの設定


※ 下記の設定は、スクリプトをEUCで保存して、シフトJISでブラウザに出力する場合の設定です。

※ 注意
PHP5.1.4からphp.iniの場所が/etc/php.iniから/etc/php5/php.iniへ変わっているようです。

# vi /etc/php5/php.ini ← 設定ファイル編集

output_buffering = On ← 出力バッファを有効に

output_handler = mb_output_handler ← 出力時に使用するハンドラ関数を指定

error_reporting = E_ALL & ~E_NOTIC ← ;を削除

;error_reporting = E_ALL ← ;を追加

magic_quotes_gpc = Off

default_charset = Shift_JIS ← HTTPヘッダ charset を設定

mbstring.language = Japanese ← 言語のデフォルトを日本語に

mbstring.internal_encoding = EUC-JP ← 内部文字コードをEUCに(JISの場合SJIS)

mbstring.http_input = auto ← HTTP入力の文字コード

mbstring.http_output = SJIS ← HTTP出力文字コードをシフトJISに

mbstring.encoding_translation = On ← HTTP入力文字コードへの変換を有効に

mbstring.detect_order = auto ← 文字コード自動検出の優先順を自動に

mbstring.substitute_character = none; ← 処理できない文字の代替文字

※ 注意
最近の設定ファイルの最下部には [Vine] という項目がある場合があり、上記設定と重複する部分がありますので、
どちらかに「;」を付けてコメントアウトしてください。


# /etc/rc.d/init.d/apache2 restart ← 設定が終了したら再起動

httpdを停止中:                         [  OK  ]
httpdを起動中:                         [  OK  ]

動作確認


<?php
phpinfo();
?>

上記を記述したファイルを test.php という名前で保存してホームディレクトリ(ドキュメントルート)に保存してください。
デフォルトのドキュメントルートは、
/var/www/html
になっています。/var/www/html/test.php に設置

Apache2の設定


Apacheの設定は /etc/apache2/conf/httpd.conf の設定で行います。
(/etc/httpd/conf の場合もあるので注意が必要!)

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

Apacheを実行するグループとユーザー
User apache
Group apache

管理者のメールアドレスの設定

ServerAdmin webmaster@xxxxx.com ←管理者のメールアドレス

サーバ名称の設定

ServerName xxxxx.com ← 取得したドメイン

ドキュメントルートの設定
ドキュメントルートとは、サーバのルート(例えばhttp://xxxxx.com/)が
要求された時に表示するHTMLを入れておくディレクトリの事です。

DocumentRoot /home/httpd/html ← デフォルトではこれになってます

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory /home/httpd/html>

#
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
CGI(ExecCGI)、SSI(Includes)を有効にし、フォルダの中身を見せたくないので Indexes を削除

   Options Indexes Includes FollowSymLinks MultiViews
     ↓
   Options ExecCGI Includes FollowSymLinks MultiViews ← CGI、SSIを有効化
                                          (Optionsのオプションは下記を参照)
#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#

   AllowOverride All ← .htaccessの有効化
                  (AllowOverrideのオプションは下記を参照)

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

#
# DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index. Separate multiple entries with spaces.
#
DirectoryIndex index.html index.htm index.shtml index.php index.cgi ← インデックスファイルを設定

#
# AccessFileName: The name of the file to look for in each directory
# for access control information.
#
AccessFileName .htaccess ← # があれば削除(.htaccessが有効になっているか確認)

ホストネームでのログ収集

HostnameLookups Off ← DNSの逆牽きで負荷が重くなるのでOFF


WebDAVの脆弱性を狙った攻撃への対策
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

※ 追記 (wormからのアクセスをログに記録しない対策)
SetEnvIf Request_URI "cmd\.exe" nolog
SetEnvIf Request_URI "root\.exe" nolog
SetEnvIf Request_URI "Admin\.dll" nolog
SetEnvIf Request_URI "NULL\.IDA" nolog
SetEnvIf Request_URI "^/_mem_bin/" nolog
SetEnvIf Request_URI "^/_vti_bin/" nolog
SetEnvIf Request_URI "^/c/" nolog
SetEnvIf Request_URI "^/d/" nolog
SetEnvIf Request_URI "^/msadc/" nolog
SetEnvIf Request_URI "^/MSADC/" nolog
SetEnvIf Request_URI "^/scripts/" nolog
SetEnvIf Request_URI "^/default.ida" nolog

※ 追記 (gif,jpg,png,ico,cssへのアクセスをログに記録しない対策)
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" nolog

※ 追記 (内部からのアクセスをログに記録しない対策)
SetEnvIf Remote_Addr 192.168.11. nolog

上記以外のアクセスをログに記録するようにする
#CustomLog
logs/access_log common ← # を付ける

CustomLog /var/log/httpd/access_log combined env=!nolog ← # を削除してenv=!nolog を追記


ServerSignature Off ← OffでエラーページでApacheのバージョンを非表示

ServerTokens ProductOnly ← 追記(エラーページでOS名を非表示)


#ScriptAlias
/cgi-bin/ /home/httpd/cgi-bin/ ← # を追記

# If you want to use server side includes, or CGI outside
# ScriptAliased directories, uncomment the following lines.
#
# To use CGI scripts:
#
AddHandler cgi-script .cgi .pl ← # を削除し「.pl」を追記(CGIスクリプトの拡張子の関連付け)

AddHandler image/gif .gif ← 追記(cgiディレクトリで画像表示を可にする)
AddHandler image/jpeg .jpg ← 追記(cgiディレクトリで画像表示を可にする)
AddHandler image/png .png ← 追記(cgiディレクトリで画像表示を可にする)

#
# To use server-parsed HTML files
#
AddType text/html .shtml ← # を削除(SSIの拡張子「.shtml」の関連付け)
AddHandler server-parsed .shtml ← # を削除(SSIの拡張子「.shtml」の関連付け)

設定が終わったら、保存してください。

# /etc/rc.d/init.d/httpd restart ← Apache再起動で設定反映
httpdを停止中:       [ OK ]
httpdを起動中:       [ OK ]

OKが出れば正常に作動しています。

※ Options は有効にするサーバのオプションを指定します。
All MultiViewを除くすべて有効。
ExecCGI CGIプログラムの実行許可。
FollowSymLink シンボリックリンクに従う。
Includes SSIの許可。
IncludesNoExec SSI は許可、CGI の #Exec と #include は禁止。
Indexes ディレクトリにアクセスがあった場合、にindex.html等のファイルがないと、
インデックスリストが自動作成され表示されます
MultiViews マルチビューのサーチを許可(例えば、.../Fileのリクエスト時に このファイルが存在しない場合、サーバは.../File.*をサーチ)。
None すべて禁止。

※ AllowOverride は.htaccess のオプションです
All ユーザーの.htaccess指定を優先利用する
AuthConfig ユーザー認証のコントロールコマンドのみ記述を許可
FileInfo ドキュメントタイプ関係のコマンドのみ記述を許可
Indexes ディレクトリインデックス関係のコマンドのみ記述を許可
Limit ユーザーのアクセスコントロール関係のコマンドのみ記述を許可
Options Optionsやディレクトリ設定関係のコマンドのみ記述を許可
None ユーザーの.htaccessをを認めない

ディレクトリのアクセス権変更

/home/httpd の所有権がデフォルトでは root になっている為FTPで接続できないので、
所有権を実際にアップロードするユーザー名とグループ名に変更します。

実際にFTPで接続するユーザーに/home/httpd/html の所有権を変更する

# chown -R ユーザー名:グループ名 /home/httpd/html


Perlコマンドを/usr/local/bin/perlでもアクセスできるように設定

Vine Linux の場合Perlコマンドは、#!/usr/bin/perlですが、/usr/local/bin/perlでもアクセスできるようにします。

# ln -s /usr/bin/perl /usr/local/bin/perl ← /usr/local/bin/perlから/usr/bin/perlへリンクをはる

# whereis perl ← /usr/local/bin/perlが有るか確認
perl: /usr/bin/perl /usr/local/bin/perl /usr/share/man/man1/perl.1.gz

Apache接続テスト

これだけの設定でApacheはもう作動しています。

Lan 内からテストしてみる。

ブラウザから以下のURLで確認してください。

Lan 内のPCから確認 → http://192.168.11.2 (サーバー機のIP)

ダイナミックDNSやDiCE等の設定が終わっているなら取得したドメインでテストしてみる

この場合、外部からもちゃんと見れるかプロクシ等を利用してテストしてみるのもいいかもしれません。


ブラウザでtest.php にアクセスして以下のような画面が出てくれば正常に動作してます。
最終更新:2007年07月03日 12:10