HomebrewでPHP7.2をインストール


環境


  • macOS Siera 10.12.6


インストール済みのPHPバージョン

$ php -v

PHP 5.6.30 (cli) (built: Oct 29 2017 20:30:32)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies


インストール

Formulaを探す。

$ brew search php72

==> Formulae
php@7.2

$ brew install php@7.2

==> Installing dependencies for php@7.2: apr, openssl, apr-util, argon2, aspell, autoconf, brotli, c-ares, libidn, libmetalink, libssh2, jansson, jemalloc, libev, libevent, nghttp2, openldap, rtmpdump, curl-openssl, libtool, unixodbc, freetds, libpng, freetype, gettext, libffi, pcre, glib, gmp, icu4c, jpeg, libpq, libsodium, libzip, readline, sqlite, tidy-html5 and webp
==> Installing php@7.2 dependency: apr
==> Downloading https://homebrew.bintray.com/bottles/apr-1.6.5.sierra.bottle.tar
######################################################################## 100.0%
==> Pouring apr-1.6.5.sierra.bottle.tar.gz
==> Caveats


確認

$ php -v

PHP 5.6.30 (cli) (built: Oct 29 2017 20:30:32)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

ターミナルを再起動後、改めて確認するも変化なし。


シンボリックリンクの作成

$ brew link php72 --force

Linking /usr/local/Cellar/php@7.2/7.2.15... 25 symlinks created

If you need to have this software first in your PATH instead consider running:
echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profile


パスを通す

$ echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile

$ echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profile


再び確認

ターミナルを再起動後、確認。

$ php -v

PHP 7.2.15 (cli) (built: Feb 26 2019 10:47:19) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.15, Copyright (c) 1999-2018, by Zend Technologies

おしまい。