Mac OS X 10.9 MavericksにPHP開発環境を構築
MacBookPro Retina13"を買ったのでPHPの開発環境を構築。
Homebrew
公式ページに書いてあるインストール方法で素直にインストール。
http://brew.sh/index_ja.html
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
PATHを通す。.zshrcに以下を記述。
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
バージョンを確認。
$ brew -v Homebrew 0.9.5
Apache
homebrew/dupes を追加。
$ brew tap homebrew/dupes
インストール。
$ brew install httpd
バージョンの確認
$ httpd -v Server version: Apache/2.2.26 (Unix) Server built: Nov 14 2013 01:09:48
httpd.confの編集。
/usr/local/etc/apache2/httpd.conf に以下を追加
# conf.d以下の.confをすべて読み込む Include /usr/local/etc/apache2/conf.d/*.conf
ディレクトリを作成。その下に設定ファイル追加。
$ mkdir /usr/local/etc/apache2/conf.d $ vi /usr/local/etc/apache2/conf.d/mine.conf # ServerName localhost:80 AddType application/x-httpd-php .php DirectoryIndex index.html index.php
起動。
$ sudo apachectl start
DocumentRootは以下。
/usr/local/Cellar/httpd/2.2.26/share/apache2/htdocs
logは以下。
PostgreSQL
brewでインストール。
$ brew install postgresql
UTF-8で初期化。
$ initdb /usr/local/var/postgres -E utf8
手動で起動。
$ postgres -D /usr/local/var/postgres
データベース一覧を取得して起動を確かめる。
$ psql -l
環境変数PGDATAを設定しておく。
.zshrcに以下を記述。
export PGDATA=/usr/local/var/postgres
自動起動を設定。
$ cp /usr/local/Cellar/postgresql/9.3.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/ $ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
PHP
phpenvとphp-buildでPHPのバージョンを切り替えられるようにする。
phpenv
$ brew tap josegonzalez/homebrew-php $ brew install phpenv
以下を.zshrcに追記
export PATH=$PATH:$HOME/.phpenv/bin eval "$(phpenv init -)"
php-build
phpenvのプラグインとしてインストール。
git clone https://github.com/CHH/php-build/ ~/.phpenv/plugins/php-build cp ~/.phpenv/plugins/php-build/bin/phpenv-install ~/.phpenv/plugins/php-build/bin/rbenv-install sed -i -e "s/# Provide phpenv completions/# Provide rbenv completions/g" ~/.phpenv/plugins/php-build/bin/rbenv-install
インストールオプションを変更
$ vi ~/.phpenv/plugins/php-build/share/php-build/default_configure_options # --with-pear #withoutから変更 --with-apxs2=/usr/local/sbin/apxs #追加
必要なライブラリをインストール。
$ brew install re2c $ brew install jpeg $ brew install mcrypt $ brew install libpng $ brew install libtool
5.3.19を試しにインストール。
$ phpenv install 5.3.19
こんなエラーになります。
----------------- | BUILD ERROR | ----------------- Here are the last 10 lines from the log: ----------------------------------------- "_sk_shift", referenced from: _load_all_certs_from_file in openssl.o "_sk_value", referenced from: _zif_openssl_csr_new in openssl.o _zif_openssl_pkcs7_verify in openssl.o _php_openssl_parse_config in openssl.o _php_openssl_sockop_set_option in xp_ssl.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [libs/libphp5.bundle] Error 1 -----------------------------------------
opensslをインストール。
$ brew install openssl $ brew link openssl --force
もう一度。
$ phpenv install 5.3.19 [Success]: Built 5.3.19 successfully.
やりました。
Apacheのモジュールを退避。
$ cp /usr/local/Cellar/httpd/2.2.26/libexec/libphp5.so ~/.phpenv/versions/5.3.19/
phpenvを更新。
$ phpenv rehash
バージョンを確認。
php -v PHP 5.3.19 (cli) (built: Dec 2 2013 12:23:15) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
phpenv-apache-version
このままだとApacheの読み込むPHPのバージョンは切り替えるのが面倒なので、プラグインを導入して手軽に切り替えられるようにする。
インストール。
$ git clone https://github.com/garamon/phpenv-apache-version ~/.phpenv/plugins/phpenv-apache-version
以下のコマンドで切り替え。
$ phpenv apache-version {version}
phpinfoでバージョンを確認。
きっとTimezoneの設定で警告が出ているので、設定をしておく。
$ vi /.phpenv/versions/{version}/etc/php.ini # date.timezone =Asia/Tokyo