phpenvを使ってPHP 8.3系をインストールしたメモ。
8.2系のインストールメモは下記リンク先。
nmtysh.hatenablog.com
環境
前提
- Homebrewがインストールされていること
phpenvのインストール
git clone https://github.com/phpenv/phpenv.git ~/.phpenv echo 'export PATH="$HOME/.phpenv/bin:$PATH"' >> ~/.zshenv echo 'eval "$(phpenv init -)"' >> ~/.zshrc exec $SHELL -l git clone https://github.com/php-build/php-build $(phpenv root)/plugins/php-build git clone https://github.com/madumlao/phpenv-aliases.git $(phpenv root)/plugins/phpenv-aliases git clone https://github.com/ngyuki/phpenv-composer.git $(phpenv root)/plugins/phpenv-composer git clone https://github.com/matayoshi/phpenv-update-all.git $(phpenv root)/plugins/phpenv-update-all
依存パッケージのインストール
brew update brew upgrade brew install pkg-config openssl@3 bzip2 libpng libjpeg libiconv icu4c \ oniguruma tidy-html5 libzip autoconf
PHP 8.3の最新バージョンを調べる
2023/12/23時点では、8.3.1が最新ですが、php-buildには未マージのため、8.3.0をインストールします。
$ phpenv update-all $ phpenv install --list | grep 8.3 (略) 8.3.0 (略)
PHP 8.3のビルドとインストール
通信環境やPCスペック等で変わりますが、手元の環境だと10分程度かかりました。
$ PKG_CONFIG_PATH="/usr/local/opt/openssl@3/lib/pkgconfig:/usr/local/opt/jpeg/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig" \ PHP_BUILD_CONFIGURE_OPTS="--with-bz2=/usr/local/opt/bzip2 --with-iconv=/usr/local/opt/libiconv" \ PHP_BUILD_XDEBUG_ENABLE=off \ PHP_BUILD_EXTRA_MAKE_ARGUMENTS="-j5" \ phpenv install 8.3.0 [Info]: Loaded extension plugin [Info]: Loaded apc Plugin. [Info]: Loaded composer Plugin. [Info]: Loaded github Plugin. [Info]: Loaded uprofiler Plugin. [Info]: Loaded xdebug Plugin. [Info]: Loaded xhprof Plugin. [Info]: Loaded zendopcache Plugin. [Info]: php.ini-production gets used as php.ini [Info]: Building 8.3.0 into /Users/user/.phpenv/versions/8.3.0 [Downloading]: https://www.php.net/distributions/php-8.3.0.tar.bz2 [Preparing]: /var/tmp/php-build/source/8.3.0 [Compiling]: /var/tmp/php-build/source/8.3.0 [xdebug]: Installing version 3.3.1 [Downloading]: http://xdebug.org/files/xdebug-3.3.1.tgz [xdebug]: Compiling xdebug in /var/tmp/php-build/source/xdebug-3.3.1 [xdebug]: Installing xdebug configuration in /Users/user/.phpenv/versions/8.3.0/etc/conf.d/xdebug.ini [XDebug]: XDebug is commented out in . Remove the ";" to enable it. [xdebug]: Cleaning up. Makefile:245: warning: overriding commands for target `test' Makefile:136: warning: ignoring old commands for target `test' [Info]: Enabling Opcache... [Info]: Done [Info]: The Log File is not empty, but the Build did not fail. Maybe just warnings got logged. You can review the log in /tmp/php-build.8.3.0.20231223200005.log or rebuild with '--verbose' option [Success]: Built 8.3.0 successfully. 8.3 => 8.3.0
phpenv-aliases を入れているので、自動的にエイリアス( 8.3 => 8.3.0
)が設定されます。
$ phpenv shell 8.3 8.3 $ phpenv rehash Download composer.phar ... Move composer.phar to /Users/user/.phpenv/versions/8.3/composer $ php -v PHP 8.3.0 (cli) (built: Dec 23 2023 20:05:56) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.0, Copyright (c) Zend Technologies with Zend OPcache v8.3.0, Copyright (c), by Zend Technologies
ビルドしたPHPをVisual Studio Codeで使うための設定
ビルドしたPHPをvscodeで利用する場合は php.validate.executablePath
に ${env:HOME}/.phpenv/shims/php
あるいは ${env:HOME}/.phpenv/versions/8.3/bin/php
を指定します。
.phpenv/shims/php
の場合は phpenv global (version)
や .php-version
を参照して使用するPHPのバージョンを判断してくれるようです。
{ "php.validate.executablePath": "${env:HOME}/.phpenv/shims/php" }