LoginSignup
19
20

More than 5 years have passed since last update.

Macでphpenvによるphpのインストールにハマりにハマった件

Posted at

MacのPHPを別のバージョンに切り替えたいなぁということがあったので
phpenvを使ってインストールしようとしたら BUILD ERROR と怒られました。

ログを見てそれぞれ対処ましたが、むっちゃ時間がかかったので
今後のためにここに残していきます。

遭遇したエラーたち

bisonのバージョンが対応してないと怒られてます。bisonってなにさ...

configure: WARNING: This bison version is not supported for ...

re2cってのがなかったんでしょうか...

configure: WARNING: You will need re2c 0.13.4 or later if ...

mcrypt.hがない?インストールするのはlibcmryptでいいのかな?

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

上の3つに対応したら別のエラーが出た(しんどい)

    _Nullable

とか

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

とか

最初のエラー

phpのインストールになんでこんなエラーが出るのかがわからないけど、とりあえず一つづつ対応するしかないですよね

-----------------------------------------
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.
-----------------------------------------

bison対応

とりあえずバージョンが違うようなのでアップデートを試みます
やり方を調べるとbrewを使ってインストールするといいらしいが
単純にインストールするだけではダメでした。
bisonのバージョンが高すぎてphpのビルドに失敗します。

PHP :: Bug #69055 :: Bison 3.0.2 not supported : https://bugs.php.net/bug.php?id=69055

調べるとバージョンは2.7じゃないとだめみたいだけど
Homebrewはデフォルトでバージョン指定ができなくなっているので設定をかえます。
こちらの記事を参考にさせていただきました。
Macのbrewで旧バージョンのアプリをインストールする - Qiita

brew tap homebrew/versions
brew search bison

ログの結果が参考サイトと違ったけど、ログの記述に合わせて次のコマンドを実行

brew install bison@2.7

ログの言う通りにパスを通します。zshをつかっているので~/.zshrcに設定してますが、他のシェルを使ってるなら置き換えてください。

echo 'export PATH="/usr/local/opt/bison@2.7/bin:$PATH"' >> ~/.zshrc

これでbisonについては怒られなくなりました。

re2c対応

字句解析ツール?PHPのビルドに必要とのことなのでとりあえずインストール
これはすんなり怒られなくなりました。

brew install re2c

libmcrypt対応

ログを見ると

mcrypt.h not found. Please reinstall libmcrypt.

とりあえずlibmcrypt入れろと言われてるので入れます

brew install libmcrypt

これで怒られなくなると思ったら、よくわからんログ吐いてBuildできません。

-----------------------------------------
          _Nullable
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/stdio.h:475:6: note: insert '_Nonnull' if the pointer should never be null
FILE    *funopen(const void *,
        ^
          _Nonnull
/var/tmp/php-build/source/5.6.9/ext/openssl/openssl.c:44:10: fatal error: 'openssl/evp.h' file not found
#include <openssl/evp.h>
         ^
330 warnings and 1 error generated.
make: *** [ext/openssl/openssl.lo] Error 1
-----------------------------------------

まったく意味がわからないので調べると次の記事が参考になりました。ありがとうございます。
phpenvでPHPをインストールする。

opensslは入ってたのでとりあえずlibxml2なるものをインストールします

brew install libxml2

ログの言う通りパスを設定します。設定先は使ってるシェルに合わせます

echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.zshrc

これで解決かと思いきやまた違うメッセージ(心が折れかかる)

-----------------------------------------
                                                    _Nonnull
352 warnings generated.
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
-----------------------------------------

次の記事に助けられました。ありがとうございます。
phpenv+php-build環境によるphpバージョン管理~Mac(Yosemite)編~

autoconfというのが必要みたいなのでインストール。記事にならってついでにautomakeも入れました。

brew install autoconf
brew install automake

結果

ものすごい時間かかりますができました。

phpenv install 5.6.9
  ... 割愛 ...
[Success]: Built 5.6.9 successfully.

涙がでますね。

19
20
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
19
20