22
10

More than 3 years have passed since last update.

macOS Catalina で phpenv のビルドエラーに対処する

Posted at

先日、macOS CatalinaがリリースされたのでCatalinaにアップデートしました。

普段、phpを利用し開発を行っている為、phpenv(anyenv経由)でphpのバージョン管理を行っています。

ビルドエラー

phpenvでphp7.3.9をインストールしようとしたところ、以下のzlibに関するエラーが出てしまいました。

$phpenv install -v 7.3.9

checking for ZLIB support... yes
checking if the location of ZLIB install directory is defined... /usr
configure: error: Cannot find zlib

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

Here are the last 10 lines from the log:

-----------------------------------------
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... /usr
configure: error: Cannot find zlib
-----------------------------------------

The full Log is available at '/tmp/php-build.7.3.9.20191029190313.log'.
[Warn]: Aborting build.

Catalina以前は [MacOS Mojave]pyenvでpythonのインストールがzlibエラーで失敗した時の対応 で対応出来たのですが、CatalinaではmacOS SDK headerが存在しない為、この方法は利用できません。

対処法

phpenvにはコンパイルオプションを指定するファイル default_configure_options が用意されています。

これを編集しzlib含む各ライブラリのディレクトリを指定してあげればコンパイルが通ります。

以下、私の場合の例

--without-pear
--with-gd
--enable-sockets
# jpeg-dirの変更
--with-jpeg-dir=/usr/local/opt/libjpeg
# png-dirの変更
--with-png-dir=/usr/local/opt/libpng
--enable-exif
--enable-zip
--with-zlib
# zlib-dirの変更
--with-zlib-dir=/usr/local/opt/zlib
# bz2-dirの指定
--with-bz2=/usr/local/opt/bzip2
--enable-intl
--with-kerberos
--with-openssl
--enable-soap
--enable-xmlreader
--with-xsl
--enable-ftp
--enable-cgi
# curl-dirの指定
--with-curl=/usr/local/opt/curl
# tidy-dirの指定
--with-tidy=/usr/local/opt/tidy-html5
--with-xmlrpc
--enable-sysvsem
--enable-sysvshm
--enable-shmop
--with-mysqli=mysqlnd
--with-pdo-mysql=mysqlnd
--with-pdo-sqlite
--enable-pcntl
# readline-dirの指定
--with-readline=/usr/local/opt/readline
--enable-mbstring
--disable-debug
--enable-fpm
--enable-bcmath
--enable-phpdbg
# 以下2行追加
--with-iconv=/usr/local/opt/libiconv
--with-libedit=/usr/local/opt/libedit

# の行は変更箇所が分かりやすいよう追記したので、ファイル編集時はコメント不要です

ただし、 libedit については↑で指定しても上書きされてしまう為、環境変数 PHP_BUILD_CONFIGURE_OPTS の指定が必要になります。

PHP_BUILD_CONFIGURE_OPTS="--with-libedit=$(brew --prefix libedit)" phpenv install -v 7.3.9

PHP 7.3 向けの対応

PHP7.3は --without-libzip オプションが無いとmac内のlibzipライブラリを探す為、付属のlibzipを利用するようオプションを付与する必要があります。

参考: PHP7.3.8をインストールしようとしたらハマった話

まとめ

default_configure_options を各環境に合わせて修正しよう

22
10
1

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
22
10