LoginSignup
63
45

More than 5 years have passed since last update.

Macのphpenv(php-build)でビルドしようとしたら出るエラーと解決まとめ

Last updated at Posted at 2019-01-11

Mac(Mojave)でPHPをビルドしようとしたらかなり行き詰まったので、
ついでに出てくるErrorとWarningを片っ端から書いてみようじゃないかという記事。

今回はPHP7.3.0, 5.6.40, 5.5.38をビルドします。
この辺りがインストールできれば7.2, 7.1, 7.0, 5.4はインストールできるみたいです。
5.3.xはビルドできないのですがそれについては省略。

TL;DT

列挙したら本当に長くなったのでまとめました。
これのコピペで大丈夫だと思います。

# php7.3.0のビルドに必要
brew install bison re2c libxml2 libjpeg libpng icu4c libzip autoconf automake
echo 'export PATH="/usr/local/opt/bison/bin:$PATH"' >> ~/.bash_profile
exec $SHELL -l

# Mojaveなら必要
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

#php5.6.40のビルドには追加で必要
brew install libmcrypt

#php5.5.38のビルドにはあると良さそう
brew install bison@2.7
echo 'export PATH="/usr/local/opt/bison@2.7/bin:$PATH"' >> ~/.bash_profile
exec $SHELL -l

php7.3.0(7.x)

configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 2.3, min: 204, excluded: ).

bisonのバージョンが低いと言われていますね。
brew install bison しましょう。

configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.

re2cのバージョンが低いと言われています。
brew install re2c でOK。

configure: error: Cannot find OpenSSL's

また、OpenSSLのenp.hが見つかりませんと出ていますがlibxml2が必要です。 これが一つ目の罠です

brew install libxml2 します。

configure: error: Cannot find zlib

zlibが見つからないと言われますが、MojaveだとmacOS SDK headerがないらしいです。
https://polidog.jp/2018/11/28/mojave_phpenv/

Mojave環境でビルドするときの最大の罠です。
(ググってもXcode-select installしろという記事ばかりひっかかりました)

上記の記事にもある通り、下記のコマンドでヘッダーをインストールしましょう
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

configure: error: jpeglib.h not found.

libjpegをインストールしましょう。

configure: error: png.h not found.

libpngをインストールしましょう

configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

icu4cをインストールしましょう

configure: error: Please reinstall the libzip distribution

libzipをインストールしましょう。

note: insert '_Nonnull' if the pointer should never be null

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
int     sigvec(int, struct sigvec *, struct sigvec *);
                                                   ^
                                                    _Nullable
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/signal.h:106:48: note: insert '_Nonnull' if the pointer should never be null
int     sigvec(int, struct sigvec *, struct sigvec *);
                                                   ^
                                                    _Nonnull
211 warnings generated.
ld: warning: directory not found for option '-L/usr/local/opt/zlib/lib'
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
-----------------------------------------

automake と autoconfをインストールするとBUILD ERRORとしてはでなくなるっぽいです。
(でもビルドログ見たらやっぱり出てるっぽい。謎)

[Success]: Built 7.3.0 successfully.

これで7.3.0のビルドがBUILD ERRORなしでできるようになったと思います。

5.6.40 インストール

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

libmcryptをインストールしましょう。

[Success]: Built 5.6.40 successfully.

これで5.6.40のビルドがBUILD ERRORなしでできるようになると思います。

5.5.38 インストール

そのままビルドしてもビルドできるのですが、
実はビルドログに下記のようなWARNINGが出ているのでもう一手間加えておくと良いかもしれません。

configure: WARNING: bison versions supported for regeneration of the Zend/PHP parsers: 2.4 2.4.1 2.4.2 2.4.3 2.5 2.5.1 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7 (found: 3.2).

php5.5のビルドにbisonが3.xではperserが再作成できないらしいです。
brew install bison@2.7して echo 'export PATH="/usr/local/opt/bison@2.7/bin:$PATH"' >> ~/.bash_profile
しましょう。

以前はbrewからインストールできる2.7.1ではこの警告が消えなかったのですが、
いつのまにかbison2.7.1でも問題なくなったようです。
やったね!

[Success]: Built 5.5.38 successfully.

これで5.5.38のビルドが特にBUILD ERRORなしでできるようになると思います。

その他

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
Error: You have not agreed to the Xcode license. Please resolve this by running:
  sudo xcodebuild -license accept
Error: You have not agreed to the Xcode license. Please resolve this by running:
  sudo xcodebuild -license accept
configure: error: in `/var/tmp/php-build/source/7.3.0':
configure: error: C compiler cannot create executables
See `config.log' for more details
-----------------------------------------

一度もxCodeを起動してないと出るかも。
先にHomebrewをインストールしていれば一緒にインストールされるので滅多に見ないです。

以下情報提供に基づく追記

configure: error: C++ preprocessor "/lib/cpp" fails sanity check

phpenv install 7.3.4
(...)
configure: error: in `/var/tmp/php-build/source/7.3.4':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check

どうやら依存関係のicu4cがclang系でビルドされているにもかかわらずgnu系でビルドしようとするのが原因のようです。
以下のようにフラグを設定するとうまくビルドできました。

 CC='/usr/bin/gcc' CXX='/usr/bin/g++' CXXFLAGS='/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/' CXXCPP='/Library/Developer/CommandLineTools/usr/bin/cpp -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/' phpenv install 7.3.4

thx @Akashi_SN

まとめ

Mojaveになってzlibが見つからないエラーがマジで罠で、数日悩みました。
他にもやるたびに悩むので一度まとめてみたかった次第。
参考になればと思います。
また、こんなエラーが出るなどあればコメントいただければ嬉しいです。

63
45
4

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
63
45