- Home ›
- Apache入門 ›
- PHP利用のための設定 ›
- HERE
拡張子の登録
広告
PHPで使う拡張子(.php)とPHPを関連付けます。例えば「http://www.example.com/sample.php」というファイルへアクセスがあった場合に、「sample.php」に記載されている内容をそのままブラウザに返すのではなく、「sample.php」ファイルに記載されているPHPスクリプトを実行した上でその結果を返すようになります。
「httpd.conf」ファイルで「AddType」で検索して下さい。デフォルトでは383行目付近に次のような記述があります。
<IfModule mime_module>
...
...
#
# 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
...
...
</IfModule>
上記の一番最後に次の2行を追加して下さい。
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
追加した結果は次のようになります。
<IfModule mime_module>
...
...
#
# 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
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
...
...
</IfModule>
これで拡張子が「.php」のファイルへアクセスがあった場合にPHPプログラムとして処理した結果を返すようになります。
( Written by Tatsuo Ikura )

AdminWeb