はじめに
PHPBrew を使って Mac に PHP 5.2.17 を入れようとしたらコケたので解決手順をメモ.いまどき,こんなに古い PHP をビルドしたい人はいないと思うが,大人の事情でビルドしなきゃいけない人もいるんです.
以下の環境に,
- OS X Yosemite 10.10
- Homebrew
以下の環境をつくる.
- MySQL
- PHPBrew
- PHP 5.2.17 (with PHP-FPM)
準備
MySQL のインストール
MySQL をインストール.
$ brew install mysql
...略
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
To connect:
mysql -uroot
To reload mysql after an upgrade:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
と書いてあるので,自分の環境に合わせて MySQL サーバの起動を行う.
続いて,初期設定を行う.
$ mysql_secure_installation
PHPBrew のインストール
PHP のビルドに必要なパッケージ1をインストール.
$ brew install automake autoconf curl pcre re2c mhash libtool icu4c gettext jpeg libxml2 mcrypt gmp libevent
$ brew link icu4c --force
$ brew link openssl --force
公式ドキュメントには書いてないけど,libxml2-2.7.8
もインストール.今回の古い PHP のビルドで使います(新しい PHP は新しい libxml2
に対応しているのだが…).
$ brew install homebrew/versions/libxml278
PHPBrew をインストール.
$ brew install phpbrew
初期設定.
$ phpbrew init
.bashrc
とか .zshrc
に以下の行を追加.
[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc
PHP のビルド
いよいよ PHP 5.2.17 をビルドしていきます.
ビルドファイルにバグ修正パッチとか PHP-FPM 追加パッチを当てて2,
$ phpbrew update --old
$ phpbrew download --mirror http://museum.php.net/php5/ 5.2.17
$ cd ~/.phpbrew/build/php-5.2.17/
$ curl -s "https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt" | patch -p0
$ curl -s "https://bugs.php.net/patch-display.php?bug_id=54736&patch=debian_patches_disable_SSLv2_for_openssl_1_0_0.patch&revision=1305414559&download=1" | patch -p1
$ curl -s "http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz" | gunzip -c | patch -p1
ビルド3.
$ CXX=g++ phpbrew --debug install --old 5.2.17 +default +fpm +mysql -- --enable-force-cgi-redirect --enable-fastcgi --with-libxml-dir=/usr/local/Cellar/libxml278/2.7.8 --with-mysql --with-mysqli --with-pdo-mysql
使用する PHP のバージョンを切り替え.
$ phpbrew switch 5.2.17
PHP-FPM は以下で動作します.
$ phpbrew fpm start
$ phpbrew fpm stop
脚注
-
https://github.com/phpbrew/phpbrew/issues/478#issuecomment-83869028 ↩
-
Mac 標準の gcc でビルドしないとオプションがなくてビルドがコケるので,Homebrew とかの gcc に変更している人は要注意. ↩