LoginSignup
43
36

More than 3 years have passed since last update.

MacOS に anyenv + phpenv で PHP 7.4.1 をインストールする

Last updated at Posted at 2020-01-09

MacOS に anyenv + phpenv を使って PHP 7.4.1 をインストールしてみました。
@dounokouno さんの macOS に phpenv で PHP 7.4 をインストールする を大いに参考にしましたが、環境の違いなのか PHP のバージョンの違いなのか、依存パッケージを幾つか追加でインストールする必要があったので、その差分をメモします。

環境

  • MacOS: 10.15.2
  • zsh: 5.7.1
  • anyenv: 1.1.1
  • phpenv: v0.9.0-rc.1
  • php-build: v0.11.0dev

先に結論

多分これでいけると思います。

$ anyenv install phpenv  # 既に phpenv をインストール済みの場合は不要
$ brew install autoconf bzip2 icu4c krb5 libedit libiconv libjpeg libpng libxml2 libzip oniguruma openssl@1.1 pkg-config tidy-html5
$ PKG_CONFIG_PATH="/usr/local/opt/krb5/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/opt/libedit/lib/pkgconfig:/usr/local/opt/libjpeg/lib/pkgconfig:/usr/local/opt/libpng/lib/pkgconfig:/usr/local/opt/libxml2/lib/pkgconfig:/usr/local/opt/libzip/lib/pkgconfig:/usr/local/opt/oniguruma/lib/pkgconfig:/usr/local/opt/openssl@1.1/lib/pkgconfig:/usr/local/opt/tidy-html5/lib/pkgconfig" PHP_BUILD_CONFIGURE_OPTS="--with-bz2=/usr/local/opt/bzip2 --with-iconv=/usr/local/opt/libiconv" phpenv install 7.4.1

PHP のビルドエラー

macOS に phpenv で PHP 7.4 をインストールする の内容に加えて libziponigurumatidy-html5 をインストールし、 PKG_CONFIG_PATH にライブラリのパスを追加してビルドしました。

libzip

ビルドエラー時に出力されたログは以下のとおりです。

configure: WARNING: unrecognized options: --with-png-dir, --with-icu-dir
configure: error: Package requirements (libzip >= 0.11) were not met:

No package 'libzip' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBZIP_CFLAGS
and LIBZIP_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

oniguruma

ビルドエラー時に出力されたログは以下のとおりです。

configure: WARNING: unrecognized options: --with-png-dir, --with-icu-dir
configure: error: Package requirements (oniguruma) were not met:

No package 'oniguruma' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ONIG_CFLAGS
and ONIG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

tidy-html5

ビルドエラー時に出力されたログは以下のとおりです。

configure: WARNING: unrecognized options: --with-png-dir, --with-icu-dir
configure: error: Cannot find libtidy

Xdebug のビルドエラー

Xdebug のコンパイル時にエラーが発生し、以下のログが出力されました。

configure: WARNING: unrecognized options: --with-png-dir, --with-libxml-dir, --with-icu-dir
configure: WARNING: unrecognized options: --with-png-dir, --with-libxml-dir, --with-icu-dir
warning: unsupported relocation in debug_info section.
note: while processing /private/var/tmp/php-build/source/7.4.1/ext/opcache/.libs/zend_accelerator_util_funcs.o
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: ext/opcache/.libs/opcache.a(shared_alloc_shm.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: ext/opcache/.libs/opcache.a(shared_alloc_shm.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: /var/tmp/php-build/source/7.4.1/modules/opcache.a(shared_alloc_shm.o) has no symbols
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.

結構悩みましたが、最終的に同じような箇所で発生したビルドエラーの対処に関する 記事 を発見。
対処として autoconf をインストールしているようだったので、試しに真似してみると成功しました...。

動作確認

以下のようにバージョンが表示できれば問題ないと思います。

$ phpenv shell 7.4.1
phpenv shell 7.4.1
7.4.1
$ php -v
PHP 7.4.1 (cli) (built: Jan  9 2020 09:17:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.1, Copyright (c), by Zend Technologies
    with Xdebug v2.9.0, Copyright (c) 2002-2019, by Derick Rethans
43
36
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
43
36