Apacheの設定ファイルを書き換える。
PHPも最初からMacOS Xにインストールされていますので、設定ファイルの書き換えなどを行えば動作させる事が出来ます。
まず、Apacheの設定ファイルを書き換えます。Perlの時と同じように「/etc/httpd/httpd.conf」をを書き換えるとマルチユーザで使用している場合、全ユーザに適用され、「/etc/httpd/users/username.conf」(usernameは、ユーザ名が入ります)の場合は、各ユーザ別に適用されます。ここでは、username.confを書き換える方法を説明します。「/etc/httpd/users/username.conf」にある自分の設定ファイルのパーミッションを"664"に変更し、テキストエディターのmiなどで開きます。初めてこの設定ファイルを開いた場合は、次のようになっているはずです。
<Directory "/Users/username/Sites/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
私の設定ファイルは、「MacOS Xでサーバーごっこ 1」でのPerlやSSIの設定が加わって、次のようになっています。
<Directory "/Users/toshio/Sites/">
AddType text/html .shtml
AddHandler server-parsed .shtml
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
Options Indexes MultiViews ExecCGI FollowSymLinks Includes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
これに、次のような設定を加えます。なお、順序などは関係ありません。
(追加部分を赤く示します。)
<Directory "/Users/toshio/Sites/">
AddType text/html .shtml
AddHandler server-parsed .shtml
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php
Options Indexes MultiViews ExecCGI FollowSymLinks Includes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
※ 以前、AddType application/x-httpd-php-sourcd
.phpsと表記しておりましたが、指摘をいただき間違いに気がつきましたので修正しました。また、ディレクトリにアクセスした際、index.phpを認識するように、DirectoryIndex
index.phpを追加しました。(2002/10/12 追記)
変更したら、保存し、パーミッションを元の"644"に戻しておきましょう。