You only have to uncomment:
#LoadModule php5_module libexec/apache2/libphp5.so
This is gone:
# AddModule mod_php5.c
The statement in 3 was changed to:
<IfModule mime_module>
#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig /private/etc/apache2/mime.types
#
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
#
# 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
# For type maps (negotiated resources):
#AddHandler type-map var
#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml
</IfModule>
Extra MIME types can either be added to the file /private/etc/apache2/mime.types or by using an AddType directive as commented on above.
バンドルされている PHP の使用法
PHP は、OS X バージョン 10.0.0 以降の Mac に標準添付されています。 デフォルトのウェブサーバで PHP を有効にするには、Apache 設定ファイル httpd.conf で数行のコメントを解除する必要があります。 一方、CGI や CLI はデフォルトで有効になっています (ターミナルから簡単に利用できます)。
PHP を有効にするには以下の手順を使用してください。 これは、ローカルの開発環境を手早く設定する方法を示したものです。 常に PHP を最新バージョンに更新することを 強く推奨します。 多くのソフトウェアでは、新しいバージョンでは多くのバグが修正されています。 また機能追加もされています。PHP も同様です。 詳細は、適切な MAC OS X インストールドキュメントを参照ください。 以下の手順は初心者を対象としたもので、 まずデフォルトの設定で動作させるための手順を示しています。 すべてのユーザが、新しいパッケージ版をコンパイルしてインストールすることを推奨します。
標準的なインストール方法は mod_php を使用するものです。Mac OS X 上の Apache web server (デフォルトのウェブサーバで、System Preferences からアクセスできます) 上に、mod_php を組み込むには次のようにします。
-
Apache の設定ファイルを開きます。デフォルトでは
/etc/httpd/httpd.conf にあります。
Finder あるいは Spotlight
を使用してこれを見つけることは難しいでしょう。
このファイルはプライベート設定されており、その所有者は
root ユーザだからです。
注意: Unix ベースのテキストエディタ、たとえば nano を用いて、ターミナルでこのファイルを開きます。このファイルの所有者は root なので、sudo コマンドを使用して (root として) 開く必要があります。つまり、ターミナル上で sudo nano /etc/httpd/httpd.conf と入力します (その後、パスワードを聞かれます)。 覚えておくべき nano コマンドは次のとおりです。^w (検索)、 ^o (保存) そして ^x (終了)。 ここで ^ は Ctrl キーを表します。
-
テキストエディタで、次のような行 (これらのふたつの行は並んでいないこともあります。 それぞれをファイル中で探してください) のコメントをはずします (# を削除します)。
パスに注意しましょう。将来 PHP をビルドする際には 上のファイルは移動するかコメントアウトする必要があります。# LoadModule php4_module libexec/httpd/libphp4.so # AddModule mod_php4.c
-
指定した拡張子 (例: .php .html および .inc) が PHP でパースされるようにします。
以下のような行が httpd.conf にあれば (Mac Panther 以降にはあります)、 PHP を有効にするだけで .php ファイルが自動的に PHP で処理されます。
<IfModule mod_php4.c> # If php is turned on, we respect .php and .phps files. AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps # Since most users will want index.php to work we # also automatically enable index.php <IfModule mod_dir.c> DirectoryIndex index.html index.php </IfModule> </IfModule> - DirectoryIndex でデフォルトインデックスファイルが読み込まれるようにします。 これも httpd.conf で設定します。典型的なパターンは index.php および index.html でしょう。デフォルトでは index.php が有効になります。上で見たような設定がすでにあるからです。 これを適切に調整しましょう。
- php.ini の場所を設定するか、デフォルトを使用します。 Mac OS X におけるデフォルトの場所は /usr/local/php/php.ini で、 phpinfo() をコールするとこの情報を表示します。 php.ini を使用しない場合は、PHP はすべてデフォルト値を使用します。 php.ini ファイルはどこにおけばいいのですか? が、関連する FAQ です。
- DocumentRoot を配置あるいは設定します。 これは、すべてのウェブファイルのルートディレクトリとなります。 このディレクトリ内のファイルはウェブサーバで処理されるようになるので、 PHP ファイルは PHP でパースしてからブラウザに出力されます。 典型的なデフォルトのパスは /Library/WebServer/Documents ですが、これは httpd.conf で別の場所にすることができます。 また、各ユーザの DocumentRoot は /Users/yourusername/Sites となります。
-
phpinfo() ファイルを作成します。
phpinfo() 関数は、PHP についての情報を表示します。 DocumentRoot 内に、次のような PHP コードを含むファイルを作成してください。
<?php phpinfo(); ?> - Apache を再起動し、先ほど作成した PHP ファイルを読み込みます。 再起動するには、シェルで sudo apachectl graceful を実行するか、あるいは OS X System Preferences で "Personal Web Server" オプションを使用して停止/起動します。 デフォルトでは、ローカルファイルをブラウザで読み込むには http://localhost/info.php のような URL を指定します。 あるいは、各ユーザディレクトリの DocumentRoot の場合は http://localhost/~yourusername/info.php のようになります。
CLI (あるいは旧バージョンの CGI) は、php という名前で、おそらく /usr/bin/php にあります。 ターミナルを開き、PHP マニュアルの Open up the terminal, read the PHP をコマンドラインから使用する を読んだうえで php -v を実行してみましょう。 これは、PHP バイナリのバージョンを表示します。 phpinfo() をコールしても、この情報を取得できます。
バンドルされている PHP の使用法
15-Nov-2008 02:36
15-Nov-2008 02:20
In the newest version of Leopard (at least as early as 10.5.5, which I'm running), Apache’s .conf file moved from /private/etc/httpd/httpd.conf to /private/etc/apache2/httpd.conf.
24-Oct-2008 02:36
Additionally, it seems that the default installation of php on Mac OS X (10.5 tested) does not point to the default location of the mysql.sock file that is installed in a standard MySQL 5.0 installation.
This prevents php working with locally hosted MySQL databases.
Adding the following line to the /private/etc/apache2/other/php5.conf file did the trick:
php_value mysql.default_socket /tmp/mysql.sock
(make sure you put it in between the </IfModule> statements)
21-Oct-2008 05:28
I am using MacOSX 10.5.4 and only enabling the mod_php5 wasn't enough to get the PHP support. I had to add following block before I could use php on machine -
<IfModule mod_php5.c>
# If php is turned on, we respect .php and .phps files.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
# Since most users will want index.php to work we
# also automatically enable index.php
<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
15-Dec-2007 03:19
As of Leopard the instructions here are out of date. To enable the bundled PHP in Leopard you need to edit /etc/apache2/httpd.conf. There is a line commented out that loads php5_module. Uncomment it and restart the web server. That should be all you need to do to get PHP support to work.
