[Mac] macOS Sierra に brew で phpunit をインストールする
2017/10/09 23:01
  • macOS Sierra に brew で phpunit をインストールしたときにドハマりしたので対応をまとめました。
    失敗編が多くてグダグダになってしまっていますが我慢してください…w

    brew install する

    いきなりですが、 brew install します。

    $ brew install phpunit
    Warning: You are using OS X 10.12.
    We do not provide support for this pre-release version.
    You may encounter build failures or other breakages.
    ==> Installing phpunit from homebrew/php
    ==> Installing dependencies for homebrew/php/phpunit: gettext, icu4c, libxml2, unixodbc, php71
    ==> Installing homebrew/php/phpunit dependency: gettext
    

    一応インストールが始まるのですが、Warning がでています。OS X 10.12 にはプレリリースバージョンを提供していないのでビルドエラー起きるかもね♥ってことらしいです。なんのこっちゃ。(´・ω・`)

    php 7.1 のインストールで失敗する

    依存関係にあるパッケージを順調にインストールしていっていましたが、以下のように php7.1 のインストールでコケていましました。

    ...
    ...
    ==> Installing homebrew/php/phpunit dependency: php71
    ==> Downloading https://php.net/get/php-7.1.8.tar.bz2/from/this/mirror
    ==> Downloading from https://secure.php.net/distributions/php-7.1.8.tar.bz2
    ######################################################################## 100.0%
    ==> ./configure --prefix=/usr/local/Cellar/php71/7.1.8_20 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/7.1 --with-config-file-path=/usr/local/
    Last 15 lines from /Users/xxxx/Library/Logs/Homebrew/php71/01.configure:
    checking for Kerberos support... /usr
    checking whether to use system default cipher list instead of hardcoded value... no
    checking for krb5-config... /usr/bin/krb5-config
    checking for RAND_egd... no
    checking for pkg-config... no
    checking for OpenSSL version... >= 1.0.1
    checking for CRYPTO_free in -lcrypto... yes
    checking for SSL_CTX_set_ssl_version in -lssl... yes
    checking for PCRE library to use... bundled
    checking whether to enable PCRE JIT functionality... yes
    checking whether to enable the SQLite3 extension... yes
    checking bundled sqlite3 library... yes
    checking for ZLIB support... yes
    checking if the location of ZLIB install directory is defined... no
    configure: error: Cannot find libz
    
    READ THIS: https://git.io/brew-troubleshooting
    If reporting this issue please do so at (not Homebrew/brew):
      https://github.com/Homebrew/homebrew-php/issues
    
    These open issues may also help:
    Cannot install php71-redis https://github.com/Homebrew/homebrew-php/issues/4061
    php71-stemmer https://github.com/Homebrew/homebrew-php/pull/3630
    homebrew/php/php71: this formula has no --with-httpd option so it will be ignored! https://github.com/Homebrew/homebrew-php/issues/4494
    PHP 7.1 installation  brew install php71 --with-httpd24 fails https://github.com/Homebrew/homebrew-php/issues/4192
    Warning: You are using OS X 10.12.
    We do not provide support for this pre-release version.
    You may encounter build failures or other breakages.
    

    brew upgrade する

    どうやら homebrew の状態が古いのが原因のようなので、アップグレードします。

    $ brew upgrade
    Warning: You are using OS X 10.12.
    We do not provide support for this pre-release version.
    You may encounter build failures or other breakages.
    

    結局同じ警告が出て何もできません。
    homebrew の upgrade のバグが原因っぽいです。
    以下を参考にして手動で最新化します。
    macOS 10.12 (Sierra) にしてから brew upgrade が実行されない

    $ cd $(brew --repo); git fetch; git reset --hard origin/master
    remote: Counting objects: 90033, done.
    remote: Compressing objects: 100% (22780/22780), done.
    remote: Total 90033 (delta 65537), reused 89491 (delta 65052), pack-reused 0
    Receiving objects: 100% (90033/90033), 20.06 MiB | 4.38 MiB/s, done.
    Resolving deltas: 100% (65537/65537), completed with 287 local objects.
    From https://github.com/Homebrew/brew
       0123e04fa..56458f03f  master     -> origin/master
     * [new tag]             0.1        -> 0.1
     ...
     ...
     * [new tag]             1.3.3      -> 1.3.3
     * [new tag]             1.3.4      -> 1.3.4
     * [new tag]             1.3.5      -> 1.3.5
    warning: unable to unlink CODEOFCONDUCT.md: Permission denied
    error: unable to unlink old '.gitignore': Permission denied
    error: unable to unlink old '.travis.yml': Permission denied
    error: unable to create file CHANGELOG.md: Permission denied
    error: unable to create file CODE_OF_CONDUCT.md: Permission denied
    error: unable to create file CONTRIBUTING.md: Permission denied
    error: unable to unlink old 'LICENSE.txt': Permission denied
    error: unable to unlink old 'README.md': Permission denied
    fatal: cannot create directory at 'completions': Permission denied
    

    権限がない…らしいので以下を実行。
    $ sudo git reset --hard origin/master
    

    再度 brew upgrade する

    $ brew upgrade
    Error: /usr/local is not writable. You should change the
    ownership and permissions of /usr/local back to your
    user account:
      sudo chown -R $(whoami) /usr/local
    Warning: Calling BottleSpecification.revision is deprecated!
    Use BottleSpecification.rebuild instead.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/autoconf.rb:10:in `block in <class:Autoconf>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling BottleSpecification.revision is deprecated!
    Use BottleSpecification.rebuild instead.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/jpeg.rb:9:in `block in <class:Jpeg>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling fails_with :llvm is deprecated!
    There is no replacement.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:29:in `<class:Libxml2>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling fails_with :llvm is deprecated!
    There is no replacement.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:29:in `<class:Libxml2>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling fails_with :llvm is deprecated!
    There is no replacement.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:29:in `<class:Libxml2>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling fails_with :llvm is deprecated!
    There is no replacement.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:29:in `<class:Libxml2>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling BottleSpecification.revision is deprecated!
    Use BottleSpecification.rebuild instead.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/makedepend.rb:9:in `block in <class:Makedepend>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling fails_with :llvm is deprecated!
    There is no replacement.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/mysql.rb:35:in `<class:Mysql>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling fails_with :llvm is deprecated!
    There is no replacement.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/mysql.rb:35:in `<class:Mysql>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling fails_with :llvm is deprecated!
    There is no replacement.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/mysql.rb:35:in `<class:Mysql>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling fails_with :llvm is deprecated!
    There is no replacement.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/mysql.rb:35:in `<class:Mysql>'
    Please report this to the homebrew/core tap!
    
    Warning: Calling BottleSpecification.revision is deprecated!
    Use BottleSpecification.rebuild instead.
    /usr/local/Library/Taps/homebrew/homebrew-core/Formula/wget.rb:11:in `block in <class:Wget>'
    Please report this to the homebrew/core tap!
    

    なんかよくわからないけど /usr/local 以下に権限がないらしい…なんでだろう。。言われたままに以下を実行します。
    $ sudo chown -R $(whoami) /usr/local
    

    この後、再度 $ brew upgrade を叩くと、正常にアップグレードでき、上記警告が解消されます。

    もう一度 brew install phpunit する

    homebrew の準備ができましたので、改めて phpunit をインストールします。
    phpunit をインストールする
    $ brew install phpunit
    

    できた!ヾ(*´∀`*)ノキャッキャ

    phpunit を実行してみる

    $ phpunit 
    PHPUnit 6.3.0 by Sebastian Bergmann and contributors.
    
    This version of PHPUnit is supported on PHP 7.0 and PHP 7.1.
    You are using PHP 5.6.30 (/usr/bin/php).
    

    brew install phpunitphp71 もインストールされていたのでなぜこのエラーがでるのかわからない…
    Warning: homebrew/php/php71 7.1.8_20 is already installed, it's just not linked.
    You can use `brew link php71` to link this version.
    

    ↑このメッセージを完全に見落としていました。(´・ω・`)

    とりあえず symlink をつくる

    $ brew link php71
    Linking /usr/local/Cellar/php71/7.1.8_20... 17 symlinks created
    

    php のバージョンを確認する
    $ php -v
    PHP 5.6.30 (cli) (built: Feb  7 2017 16:18:37) 
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    

    …まじっすか(´;ω;`)

    ここまできて、もう一度ログを見直して php71 にパスを通していないことに気が付きました。

    ✩✩✩✩ PHP CLI ✩✩✩✩
    
    If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file:
      export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH"
    
    

    php71 にパスを通す

    ~/.bash_profile にパスを追記する

    $ echo 'export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH"'  >> ~/.bash_profile
    $ source ~/.bash_profile
    

    php のバージョンを確認する
    $ php -v
    dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
      Referenced from: /usr/local/opt/php71/bin/php
      Reason: image not found
    Abort trap: 6
    

    ここからが地獄でした。

    ロードできなかったライブラリをアップグレードしていく

    まずは libreadline をアップグレードします。
    $ brew upgrade readline
    

    ぼくのケースではこの後も続々とロードできないライブラリがでてきました。

    $ php -v
    dyld: Library not loaded: /usr/local/opt/libpng/lib/libpng16.16.dylib
      Referenced from: /usr/local/opt/php71/bin/php
      Reason: Incompatible library version: php requires version 48.0.0 or later, but libpng16.16.dylib provides version 38.0.0
    Abort trap: 6
    
    $ brew upgrade libpng
    

    $ php -v
    dyld: Library not loaded: /usr/local/opt/freetype/lib/libfreetype.6.dylib
      Referenced from: /usr/local/opt/php71/bin/php
      Reason: Incompatible library version: php requires version 21.0.0 or later, but libfreetype.6.dylib provides version 19.0.0
    Abort trap: 6
    
    $ brew upgrade freetype
    

    $ php -v
    PHP 7.1.8 (cli) (built: Aug  7 2017 15:02:45) ( NTS )
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    

    やっとインストールできました…
    $ phpunit --version
    PHPUnit 6.3.0 by Sebastian Bergmann and contributors.
    
    

    以上です。なぜか色々とハマってしまいました…(´・ω・`)

    人気ブログランキングへ ブログランキング・にほんブログ村へ
    ↑応援よろしくお願いします!m(_ _)m

  • <2017/10/09 23:01>
  • サーバー
  • PHPphpunitbrewhomebrewMacSierra
  • 新しい記事へ
    今月やりたいことリスト(2017年10月)

    古い記事へ
    JPG, PNG画像を適切に圧縮できるWebサービス

profile picture

自己紹介的な何か

@wkmettyでついったーやってます。時々。 6年間勤めたゲーム会社を2018年2月に退職しフリーランスのプログラマに。 WordPress Core, WP-CLI コントリビューター。 お仕事募集中です。