13
14

More than 5 years have passed since last update.

MacOSX + phpenv + php-build + pyrus の環境構築メモ

Posted at

phpenv のインストール

$ sudo brew install phpenv
Password:
Warning: You have Xcode 4.1, which is outdated.
Please install Xcode 4.3.
Error: phpenv is a head-only formula
Install with `brew install --HEAD phpenv

--HEADつけなかったら怒られたので--HEADをつけてインストール

$ sudo brew install --HEAD phpenv

これでインストールが完了したので、$HOME/.phpenv ができた。
ただ、権限がrootになってしまっているので、自分に直す。

$ sudo chown -R $USER $HOME/.phpenv

あとは.bashrcに環境変数と初期化の設定をする。

# phpenv
if [ -f ${HOME}/.phpenv/bin/phpenv ]; then
    export PATH=${PATH}:${HOME}/.phpenv/bin
    eval "$(phpenv init -)"
fi

php-build のインストール

$ sudo brew install php-build

これでインストール完了。

php-build で php をインストール

インストール可能なphpのバージョンを確認する。

$ php-build --definitions
5.2.17
5.3.10
5.3.2
5.3.6
5.3.8
5.3.9
5.3.9RC3
5.3.9RC4
5.3snapshot
5.4.0
5.4.0RC1
5.4.0RC2
5.4.0RC3
5.4.0RC4
5.4.0RC5
5.4.0RC6
5.4.0RC7
5.4.0RC8
5.4.0alpha3
5.4.0beta1
5.4.0beta2
5.4snapshot

5.3.9 をインストールしてみる。

$ php-build 5.3.9 ~/.phpenv/versions/5.3.9
Loaded pyrus Plugin.
Loaded xdebug Plugin.
php.ini-production gets used as php.ini

Building 5.3.9 into /Users/yhino/.phpenv/versions/5.3.9

    [Downloading]:  http://www.php.net/distributions/php-5.3.9.tar.bz2
    [Preparing]:  /var/tmp/php-build/source/5.3.9

BUILD ERROR
configure: warning: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers. configure: error: jpeglib.h not found.

The full Log is available here /tmp/php-build.5.3.9.20120424131015.log

必要なライブラリがなくて怒られた。
なので、必要なライブラリを入れる。

$ sudo brew install re2c
$ sudo brew install jpeg
$ sudo brew install mcrypt

ライブラリがそろったので再度インストール。

$ php-build 5.3.9 ~/.phpenv/versions/5.3.9
Loaded pyrus Plugin.
Loaded xdebug Plugin.
php.ini-production gets used as php.ini

Building 5.3.9 into /Users/yhino/.phpenv/versions/5.3.9

    [Skipping]:  Already downloaded and extracted http://www.php.net/distributions/php-5.3.9.tar.bz2
    [Preparing]:  /var/tmp/php-build/source/5.3.9
    [Compiling]:  /var/tmp/php-build/source/5.3.9
    [Pyrus]:  Downloading from http://pear2.php.net/pyrus.phar
    [Pyrus]:  Installing executable in /Users/yhino/.phpenv/versions/5.3.9/bin/pyrus
    [XDebug]:  Downloading http://xdebug.org/files/xdebug-2.1.3.tgz
    [XDebug]:  Compiling in /var/tmp/php-build/source/xdebug-2.1.3
    [XDebug]:  Installing XDebug configuration in /Users/yhino/.phpenv/versions/5.3.9/etc/conf.d/xdebug.ini
    [XDebug]:  Cleaning up.
    [Info]:  The Log File is not empty, but the Build did not fail. Maybe just warnings got logged. You can review the log in /tmp/php-build.5.3.9.20120424170154.log
    [Success]:  Built 5.3.9 successfully.

インストール完了。

phpenv で php を切り替えてみる

システムで入れてある php のバージョンを確認。

$ php -v 
PHP 5.3.8 with Suhosin-Patch (cli) (built: Nov 15 2011 15:33:15) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

切り替え可能な php のバージョンを確認。

$ phpenv versions 
  5.3.9

切り替えてみる。

$ phpenv global 5.3.9
$ phpenv version
5.3.9 (set by /Users/yhino/.phpenv/version)
$ phpenv rehash

ターミナルを開き直してバージョン確認。

$ php -v
PHP 5.3.9 (cli) (built: Apr 24 2012 17:09:13) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.1.3, Copyright (c) 2002-2012, by Derick Rethans

出来た。

pyrus で phpunit をインストール

pyrus でインストールする。

$ pyrus install pear.phpunit.de/PHPUnit
Pyrus version 2.0.0a4 SHA-1: 72271D92C3AA1FA96DF9606CD538868544609A52
Using PEAR installation found at /Users/yhino/.phpenv/versions/5.3.9/share/pyrus/.pear
Sorry, the channel "pear.phpunit.de" is unknown.
Do you want to add this channel and continue?
Please choose:
  yes
  no
[yes] : yes
Discovery of channel pear.phpunit.de successful
Sorry, pear.phpunit.de/PHPUnit references an unknown channel pear.symfony-project.com for pear.symfony-project.com/YAML
Do you want to add this channel and continue?
Please choose:
  yes
  no
[yes] : 
Discovery of channel pear.symfony-project.com successful
Downloading pear.phpunit.de/PHPUnit
___省略___
Installed pear.phpunit.de/PHPUnit-3.6.10
Installed pear.phpunit.de/File_Iterator-1.3.1
Installed pear.phpunit.de/Text_Template-1.1.1
Installed pear.phpunit.de/PHP_CodeCoverage-1.1.2
Installed pear.phpunit.de/PHP_Timer-1.0.2
Installed pear.phpunit.de/PHPUnit_MockObject-1.1.1
Installed pear.symfony-project.com/YAML-1.0.6
Installed pear.phpunit.de/PHP_TokenStream-1.1.3
Optional dependencies that will not be installed, use --optionaldeps:
pear.phpunit.de/PHP_Invoker depended on by pear.phpunit.de/PHPUnit

インストールした phpunit を使えるようにする。

$ phpenv rehash

これで使えるようになりました。

参考にしたページ

13
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
14