ukoasis blog

homebrewでphp5.5環境を構築

Oct 14, 2013

自分のPHP脳は5.3くらいで止まっていて、5.4、5.5で入った機能は ( ´_ゝ`)フーン位しか知らずちょっと見てみようと思う
まずはジェネレータがおもろそうだなと思ってのでphp5.5を導入! optionの見方とか直ぐに忘れるので備忘録的に記述します

前提

  • homebrewはインストール済み
  • tapでhomebrew-phpは追加済み

手順

  • コンパイル時のオプションを確認
brew options php55
----
--32-bit
	Build 32-bit only.
--homebrew-apxs
	Build against apxs in Homebrew prefix
--with-cgi
	Enable building of the CGI executable (implies --without-apache)
--with-debug
	Compile with debugging symbols
--with-fpm
	Enable building of the fpm SAPI executable (implies --without-apache)
--with-gmp
	Build with gmp support
--with-homebrew-libxslt
	Include LibXSLT support via Homebrew
--with-homebrew-openssl
	Include OpenSSL support via Homebrew
--with-imap
	Include IMAP extension
--with-intl
	Include internationalization support
--with-libmysql
	Include (old-style) libmysql support
--with-mssql
	Include MSSQL-DB support
--with-pgsql
	Include PostgreSQL support
--with-thread-safety
	Build with thread safety
--with-tidy
	Include Tidy support
--without-apache
	Build without shared Apache 2.0 Handler module
--without-bz2
	Build without bz2 support
--without-mysql
	Remove MySQL/MariaDB support
--without-pcntl
	Build without Process Control support
--without-pear
	Build without PEAR

自分の場合、以下の利用用途でこんなオプションにしました

  • nginx使いたい
  • 取得したHTMLを加工したい
  • Symfony2使うかも・・

brew install php55 --with-fpm --with-intl --with-tidy

上記コマンド実施でしばしコンパイル待ち・・ つらつらWarningが出ましたが完了時にまとめて表示されるのでそれを確認

☆☆☆☆ PEAR ☆☆☆☆

If pear complains about permissions, 'Fix' the default PEAR permissions and config:
    chmod -R ug+w /usr/local/Cellar/php55/5.5.4/lib/php
    pear config-set php_ini /usr/local/etc/php/5.5/php.ini

✩✩✩✩ Extensions ✩✩✩✩

If you are having issues with custom extension compiling, ensure that
you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:

      PATH="/usr/local/bin:$PATH"

PHP55 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.

✩✩✩✩✩ INTL Support ✩✩✩✩✩

icu4c is broken as of mxcl/homebrew#03ed757c, so you will need to install intl as
a separate extension:

    brew install php55-intl

✩✩✩✩ FPM ✩✩✩✩

To launch php-fpm on startup:
    * If this is your first install:
        mkdir -p ~/Library/LaunchAgents
        cp /usr/local/Cellar/php55/5.5.4/homebrew-php.josegonzalez.php55.plist ~/Library/LaunchAgents/
        launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist

    * If this is an upgrade and you already have the homebrew-php.josegonzalez.php55.plist loaded:
        launchctl unload -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist
        cp /usr/local/Cellar/php55/5.5.4/homebrew-php.josegonzalez.php55.plist ~/Library/LaunchAgents/
        launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist

The control script is located at /usr/local/Cellar/php55/5.5.4/sbin/php55-fpm

Mountain Lion comes with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:

  PATH="/usr/local/sbin:$PATH"

You may also need to edit the plist to use the correct "UserName".

Please note that the plist was called 'org.php-fpm.plist' in old versions
of this formula.

To have launchd start php55 at login:
    ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents
Then to load php55 now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
Warning: Could not link php55. Unlinking...
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link php55'

上記に沿って以下の様に実行しました

  • php54インストール済みの自分の環境ではbrew linkでエラーが出てるのでphp54をunlinkしてから再度実行
brew unlink php54
brew link php55
  • PEARをインストールしてるので権限周りの修正
chmod -R ug+w /usr/local/Cellar/php55/5.5.4/lib/php
pear config-set php_ini /usr/local/etc/php/5.5/php.ini
  • icu4cライブラリが壊れてる?せいでintlオプションがエラーなので別途インストール
brew install php55-intl
  • php-fpmは現状自動起動不要なのでplistのコピーのみ

環境によって実行ユーザを変更しておく必要あるが、自分の環境では不要なのでそのまま

cp /usr/local/Cellar/php55/5.5.4/homebrew-php.josegonzalez.php55.plist ~/Library/LaunchAgents/
  • phpのwarningが出まくるのでtimezoneの設定追加
vim /usr/local/etc/php/5.5/php.ini
----
;date.timezone =  
↓
date.timezone = 'Asia/Tokyo'
  • 確認
php -v
----
PHP 5.5.4 (cli) (built: Oct 14 2013 12:19:49)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies

とりあえず素の環境はできたので今後、必要な設定は適宜追加していく