BigSurの phpenv インストール

自分個人の開発はPHP+Laravelが主流になっているけれど、そろそろPHPのVersion管理が必要だなーと思っていたので、phpenvを入れることにした。しかし、一筋縄にいかなかった。

結論

これでインストール。先人のみなさまのお力をお借りしました。
※Console Logから不要部分を削除していますが、何か必要なものまで削除してたらご指摘ください。

% mkdir temp
% cd temp
% git clone https://github.com/CHH/phpenv.git

Cloning into 'phpenv'...
remote: Enumerating objects: 399, done.
remote: Total 399 (delta 0), reused 0 (delta 0), pack-reused 399
Receiving objects: 100% (399/399), 68.21 KiB | 2.27 MiB/s, done.
Resolving deltas: 100% (164/164), done.

% phpenv/bin/phpenv-install.sh
Installing phpenv in /Users/satossy/.phpenv
Cloning into '/Users/satossy/.phpenv'...
remote: Enumerating objects: 2886, done.
remote: Total 2886 (delta 0), reused 0 (delta 0), pack-reused 2886
Receiving objects: 100% (2886/2886), 562.66 KiB | 3.23 MiB/s, done.
Resolving deltas: 100% (1801/1801), done.
Success.

export PATH="(HomeDIrectoryが入ります)/.phpenv/bin:$PATH"
eval "$(phpenv init -)"

Add above line at the end of your ~/.bashrc and restart your shell to use phpenv.

% vi ~/.zshrc 
(上記のexportとevalを追加します。.bashrcと書いてあるけど、お手元の環境に合わせて。BigSurだと ~/.zshrc に書き込みます)

% source ~/.zshrc 

% git clone git://github.com/CHH/php-build.git $HOME/.phpenv/plugins/php-build
Cloning into '/Users/satossy/.phpenv/plugins/php-build'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 9460 (delta 1), reused 1 (delta 1), pack-reused 9457
Receiving objects: 100% (9460/9460), 1.19 MiB | 1.52 MiB/s, done.
Resolving deltas: 100% (7053/7053), done.

% brew install re2c openssl bison libxml2 autoconf automake icu4c libjpeg libpng libmcrypt libiconv tidy-html5 libzip
〜〜〜省略〜〜〜

% PHP_BUILD_CONFIGURE_OPTS="--with-bz2=$(brew --prefix bzip2) --with-iconv=$(brew --prefix libiconv)"  phpenv install 7.4.15
[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 7.4.15 into /Users/satossy/.phpenv/versions/7.4.15
[Skipping]: Already downloaded and extracted https://secure.php.net/distributions/php-7.4.15.tar.bz2
[Preparing]: /var/tmp/php-build/source/7.4.15
[Compiling]: /var/tmp/php-build/source/7.4.15
[xdebug]: Installing version 3.0.2
[Downloading]: http://xdebug.org/files/xdebug-3.0.2.tgz
[xdebug]: Compiling xdebug in /var/tmp/php-build/source/xdebug-3.0.2
[xdebug]: Installing xdebug configuration in /Users/satossy/.phpenv/versions/7.4.15/etc/conf.d/xdebug.ini
[xdebug]: Cleaning up.
Makefile:228: warning: overriding commands for target `test'
Makefile:132: 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.7.4.15.20210306163748.log or rebuild with '--verbose' option
[Success]: Built 7.4.15 successfully.

その後新しいShellを立ち上げて確認。

% php -v 
WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Dec 21 2020 21:33:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies

% cd temp 
% php -v
PHP 7.4.15 (cli) (built: Mar  6 2021 16:42:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
   with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies
   with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans
% 

謝辞

先人のみなさま、本当にありがとうございました。m(__)m


この記事が気に入ったらサポートをしてみませんか?