LoginSignup
5
8

More than 1 year has passed since last update.

dylib が見つからないから始まる PHP インストール地獄

Last updated at Posted at 2019-02-15

brew あるものをインストールしたら、PHP が起動しなくなっちゃいました。そこから始まった PHP インストール地獄の話です。

環境は macOS Catalina 10.15.7 で、brew でインストールした PHP と、phpbrew で別バージョンを使えるようにしています。

ことの始まり

brew であるものをインストールしました。その際に homebrew を update したんですが、その後 php がエラーを吐いて起動しなくなっちゃいました。

$ php -v
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib
  Referenced from: /usr/local/bin/php
  Reason: image not found
zsh: abort      php -v

まずそれを修復しました。

参考: https://qiita.com/yasu_yyy/items/2f6a6b0bc562f082d999

$ brew upgrade php

これで、php のバージョンが最新版 (7.4.12) になって、エラーが出なくなりました。


追記:以前に書いた解決策では、エラーに出会いながらなんとかインストールまでもっていった記録を書いたのですが、ちゃんと設定すればでないエラーを場当たり的につぶしていました。
自分でも、なんでこんなに面倒くさいんだ。という疑問があったのにそこに蓋をしていたのがいけなかったと反省しています。
場当たり的な対策をした記録は、後ろの方に残しておきます。

解決方法

  • lookup-prefix を指定する
  • openssl の指定をする

の2つの対策をすれば、phpbrew のインストールは簡単になります

lookup-prefix を指定する

私の環境では homebrew をつかっているため、次の設定が必要でした。

phpbrew lookup-prefix homebrew

PHPBrew の README にも書かれていますが、これをしなかったおかげで、たくさんの ...がない というエラーに出会ってしまっていました。そしてそれに対して +bz2="$(brew --prefix bzip2)" みたいなことをいっぱい書かなければならなくなってしまいました。

上記のコマンドを実行することで、基本的に "$(brew --prefix は必要なくなります。

libsodium

また Symfony4 を使おうとしたときに libsodium が必要なようでした。
+sodium とかやってみましたが、そんな Variant はないようでして、--with-sodium オプションを加えてやる必要がありました。

phpbrew install 7.4.12 +default +dbs +debug +openssl +bz2 +zlib +iconv +intl -- --with-sodium

PHP 8.0 のコンパイルエラー

PHP 8.0 をインストールしたときにコンパイルエラーが発生しました。

PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
make: *** [ext/phar/phar.phar] Bus error: 10

こちらの記事 を参考にして --with-external-pcre オプションを追加するとコンパイルが通りました。

phpbrew install 8.0.11 +default +dbs +debug +openssl +bz2 +zlib +iconv +intl -- --with-sodium --with-external-pcre

以下は、上記を追記する前の記述です、たった一つのコマンド実行を忘れてたために、あほな苦労をしている愚か者を見ることができます。

phpbrew で PHP 7.2 をインストール

開発中のシステムは 7.2 なので、phpbrew で 7.2 をインストールすることにします。

$ phpbrew install 7.2 +default +dbs

evp.h が見つからないエラー

configure でエラーが発生しています。

Error: Configure failed:
The last 5 lines in the log file:
checking for Kerberos support... no

checking whether to use system default cipher list instead of hardcoded value... no

checking for RAND_egd... no

checking for pkg-config... no

configure: error: Cannot find OpenSSL's <evp.h>

evp.h が見つからないということなので、openssl の場所を指定してやるといいようです。

参考: https://github.com/phpbrew/phpbrew/issues/646

$ phpbrew install 7.2 +default +dbs -- --with-openssl=/usr/local/opt/openssl

または

$ phpbrew install 7.2 +default +dbs +openssl=/usr/local/opt/openssl

BZip2 がないというエラー

Error: Configure failed:
The last 5 lines in the log file:
checking if the location of ZLIB install directory is defined... no

checking whether to enable bc style precision math functions... yes

checking for BZip2 support... yes

checking for BZip2 in default path... not found

configure: error: Please reinstall the BZip2 distribution

zlib2 は入っているんですよねぇ。

phpbrew のこちらの issueを参考にしてパラメータを加えます。わらしべ長者のようにだんだんオプションが増えていきます。

You can use brew --prefix bzip2 to get the path to bzip2 if you installed it with homebrew. Here's how I'm compiling PHP 7.1 on macOS 10.14:

$ phpbrew install 7.2 +default +dbs +openssl=/usr/local/opt/openssl +bz2="$(brew --prefix bzip2)"

参考: https://github.com/phpbrew/phpbrew/issues/966

cURL がない

Error: Configure failed:
The last 5 lines in the log file:
checking for cURL support... yes

configure: WARNING: Fallback: search for curl headers and curl-config

checking for cURL in default path... not found

configure: error: Please reinstall the libcurl distribution -

      easy.h should be in <curl-dir>/include/curl/

これは単純に入ってなかったのでインストールすることにします。

$ brew install curl

libzip がない

Error: Configure failed:
The last 5 lines in the log file:
checking whether to enable zend-test extension... no

checking for zip archive read/writesupport... yes

checking pcre install prefix... /usr/local

checking libzip... no

checking for the location of zlib... configure: error: zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located

最後のを頼りにして、BZip2 のときの issue を見直して、オプションを加えました。

$  phpbrew install 7.2 +default +dbs +openssl=/usr/local/opt/openssl +bz2="$(brew --prefix bzip2)" +zlib="$(brew --prefix zlib)"

結果

===> phpbrew will now build 7.2.11
===> Loading and resolving variants...
        :
        :
        :
To use the newly built PHP, try the line(s) below:

    $ phpbrew use php-7.2.11

Or you can use switch command to switch your default php to php-7.2.11:

    $ phpbrew switch php-7.2.11

Enjoy!

やっとインストールできました。

毎度毎度、とっても面倒くさい phpbrew 。開発環境はどんどん Docker に切り替えていきたいですね。

最終的なコマンドライン

iconv や xdebug 入れないとだったので、最終的には次のようになりました。

$ phpbrew install 7.2 +default +dbs +debug +openssl=/usr/local/opt/openssl +bz2="$(brew --prefix bzip2)" +zlib="$(brew --prefix zlib)" +iconv="$(brew --prefix libiconv)"
5
8
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
5
8