LoginSignup
15
11

More than 5 years have passed since last update.

MacでPHP環境を整備

Last updated at Posted at 2016-06-08
  • 自分の環境はHomebrewを導入しているので、今回はHomebrewを通してphpenvを入れます。
  • が、なかなかうまく行かず手こずった…。

phpenv

インストール

  • 先にhomebrew/phpをtap

    $ brew tap homebrew/php
    
  • phpenvインストール

    $ brew install phpenv
    

パス設定

  • インストール先へパスを通す

    $ echo 'export PHPENV_ROOT=${HOME}/.phpenv'     >> ~/.bash_profile
    $ echo 'export PATH=${PHPENV_ROOT}/bin:${PATH}' >> ~/.bash_profile
    $ echo 'eval "$(rbenv init -)"'                  >> ~/.bash_profile
    $ source ~/.bash_profile
    
  • 確認

    $ phpenv --version
    rbenv 1.0.0-21-g9fdce5d
    

php-build

  • phpenvのプラグイン。
    • brew経由だと/usr/local/bin/php-buildにインストールされ、上記で入れたphpenvとは連携されなくなってしまう。
  • gitからcloneする。

    $ git clone git://github.com/CHH/php-build.git $HOME/.phpenv/plugins/php-build
    

php

事前準備

  • 必要なライブラリを入れておく。これもbrewで。

    $ brew install gcc re2c libmcrypt autoconf automake libiconv
    
    • これやってないと、インストールしようとするPHPのバージョンによっては各所で怒られる(た)。

      
      -----------------
      |  BUILD ERROR  |
      -----------------
      
      Here are the last 10 lines from the log:
      
      -----------------------------------------
      configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 2.3, min: 204, excluded: 3.0).
      configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
      configure: error: mcrypt.h not found. Please reinstall libmcrypt.
      -----------------------------------------
      
      
      • とかとか。

PHP拡張モジュール無効化

  • 自分の場合、最低限の構成でインストールしたかったので、configure optionを全て無効に設定した。

    $ cd ~/.phpenv/plugins/php-build/share/php-build/
    $ cp default_configure_options default_configure_options-origin
    $ echo '--disable-all' > default_configure_options-disable-all
    $ cp default_configure_options-disable-all default_configure_options
    

インストール

  • インストール可能バージョンの確認

    $ phpenv install --list
    
    • ずらずらバージョンが表示される。
  • インストール実行

    $ phpenv install 5.6.9
    

デフォルトバージョン指定

  • デフォルトで使用するバージョンを指定する

    phpenv global 5.6.9
    
  • 確認

    $ php --version
    
    
    • VersionがインストールしたものになっていればOK。
    $ echo '<?php phpinfo();' | php
    
    • phpinfo()をコールして情報が表示されればOK。
15
11
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
15
11