Full-stack Engineer's blog

Install php7.1.9 with phpenv on MacOS

日本語 | English

I tried to install php7.1.9 with phpenv on MacOS(Sierra/10.12.3), but some errors occurred. This article is a note of it.

Install phpenv

Brew didin't support to install phpenv itself. So I installed it manually like below.

$ cd
$ git clone https://github.com/CHH/phpenv.git
$ cd phpenv/bin
$ ./phpenv-install.sh
# ---> $HOME/.phpenv  is created.

# clean up 
$ cd 
$ rm -rf phpenv

Set PATH for phpenv command.

$ echo 'export PATH="$HOME/.phpenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(phpenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ phpenv versions
* system (set by /Users/XXXX/.phpenv/version)

phpenv install 7.1.9

Clone php-build repository in order to build php later.

$ git clone https://github.com/CHH/php-build.git ~/.phpenv/plugins/php-build

Check installable php version list.

$ phpenv install --list
Available versions:
~~~ .... ~~~

This time, I'm installing version 7.1.9.

$ phpenv install 7.1.9

~~~ .... ~~~


Here are the last 10 lines from the log:

configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 2.3, min: 204, excluded: ).
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
configure: error: OpenSSL version 1.0.1 or greater required.

As the error above says, some packages are missing.
Install them with brew comannd like below.

$ brew install gcc re2c libmcrypt autoconf automake libiconv bison openssl libxml2 jpeg libpng
$ brew link --force bison
$ brew link --force openssl
$ brew link --force libxml2

Try install php 7.1.9 again.

$ phpenv install 7.1.9
[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.1.9 into /Users/XXXX/.phpenv/versions/7.1.9
[Skipping]: Already downloaded and extracted https://secure.php.net/distributions/php-7.1.9.tar.bz2
[Preparing]: /var/tmp/php-build/source/7.1.9
[Compiling]: /var/tmp/php-build/source/7.1.9
[Success]: Built 7.1.9 successfully.

It seems to be succeeded.
Let's check php 7.1.9 behavior.

$ phpenv versions
* system (set by /Users/XXXX/.phpenv/version)
$ phpenv global 7.1.9
$ php -v
PHP 7.1.9 (cli) (built: Sep 16 2017 15:51:12) ( NTS )

That' all.