MacPorts で PHP5 をインストールする

% sudo port install php52 +apache2 +mysql5 +pear +readline +sockets +t1lib +tidy

Suhosin のパッチを当てたものでインストールをしてみると、エラーが出てインストールができないので、Suhosin の適用はしていない。

--->  Applying patches to php52
Error: Target org.macports.patch returned: shell command "/usr/bin/gzip -dc "/opt/local/var/macports/distfiles/php5/suhosin-patch-5.2.11-0.9.7.patch.gz" | ( cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_php52/work/php-5.2.13" && /usr/bin/patch -p1 )" returned error 1
Command output: Hunk #2 succeeded at 1389 (offset 15 lines).
Hunk #3 succeeded at 1430 (offset 15 lines).
Hunk #4 succeeded at 1527 (offset 15 lines).
Hunk #5 succeeded at 1689 (offset 15 lines).
Hunk #6 succeeded at 1833 (offset 15 lines).
Hunk #7 succeeded at 1886 (offset 15 lines).
Hunk #8 succeeded at 1947 (offset 15 lines).
patching file main/php.h
patching file main/php_config.h.in
patching file main/php_logos.c
patching file main/snprintf.c
patching file main/spprintf.c
patching file main/suhosin_globals.h
patching file main/suhosin_logo.h
patching file main/suhosin_patch.c
patching file main/suhosin_patch.h
patching file main/suhosin_patch.m4
patching file sapi/apache/mod_php5.c
Hunk #1 succeeded at 953 (offset 2 lines).
patching file sapi/apache2filter/sapi_apache2.c
Hunk #1 succeeded at 568 (offset 2 lines).
patching file sapi/apache2handler/sapi_apache2.c
Hunk #1 succeeded at 377 (offset 7 lines).
patching file sapi/cgi/cgi_main.c
Hunk #1 FAILED at 1801.
1 out of 1 hunk FAILED -- saving rejects to file sapi/cgi/cgi_main.c.rej
patching file sapi/cli/php_cli.c
Hunk #1 FAILED at 801.
1 out of 1 hunk FAILED -- saving rejects to file sapi/cli/php_cli.c.rej
patching file win32/build/config.w32

Error: Status 1 encountered during processing.
Before reporting a bug, first run the command again with the -d flag to get complete output.

PHP5 を Apache 2 で有効にする

Apache 2 が PHP5 のモジュールを読み込むように httpd.conf に設定する。

% cd /opt/local/apache2/modules
% sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
[activating module `php5' in /opt/local/apache2/conf/httpd.conf]

次の一行を手動で httpd.conf に書き込む。

AddType application/x-httpd-php .php

最後に、php.ini を有効にする。今回は開発環境なので、

% sudo cp /opt/local/etc/php5/php.ini-dist /opt/local/etc/php5/php.ini

そして、Apache 2 を再起動し、phpinfo で PHP5 が有効になっていることをブラウザで確認する。

% sudo /opt/local/apache2/bin/apachectl configtest
Syntax OK
% sudo /opt/local/apache2/bin/httpd -k restart