homebrew/phpがdeprecatedになってしまった件

More than 1 year has passed since last update.

いつものようにbrewでphpを7.0から7.1に切り替えたりしようとして躓いた。

% brew link php71

Warning: php@7.1 is keg-only and must be linked with --force
Note that doing so can interfere with building software.

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

% php -v
PHP 7.0.29 (cli) (built: Apr 12 2018 03:13:39) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.29, Copyright (c) 1999-2017, by Zend Technologies

% brew unlink php70
Unlinking /usr/local/Cellar/php@7.0/7.0.29_1... 25 symlinks removed

% brew link php71
Warning: php@7.1 is keg-only and must be linked with --force
Note that doing so can interfere with building software.

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

% 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 --force php71
Linking /usr/local/Cellar/php@7.1/7.1.14_25... 17 symlinks created

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

% php -v
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-intl/intl.so' - dlopen(/usr/local/opt/php71-intl/intl.so, 9): Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.60.dylib
Referenced from: /usr/local/opt/php71-intl/intl.so
Reason: image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-intl/intl.so' - dlopen(/usr/local/opt/php71-intl/intl.so, 9): Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.60.dylib
Referenced from: /usr/local/opt/php71-intl/intl.so
Reason: image not found in Unknown on line 0
PHP 7.1.14 (cli) (built: Feb 2 2018 08:41:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

う、、うん。まあよくあるよね。いったん全部消して入れ直そう。

あれ、brew removeも--forceつけないととか言ってくる。

なんとか一通り削除して入れ直す。

% brew install php71 php71-mcrypt php71-intl php71-memcached

Error: No available formula with the name "php71-mcrypt"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow

Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.
brew install php71 php71-mcrypt php71-intl php71-memcached 2.29s user 0.94s system 62% cpu 5.131 total

えwどうしたhomebrew。formula先月消しただとw

% brew search php71

==> Searching local taps...
==> Searching taps on GitHub...
==> Searching blacklisted, migrated and deleted formulae...
It was migrated from homebrew/php to homebrew/core.

homebrew/php から homebrew/core に移行した、と?

たしかにhomebrew/php/php71からphp@71とかに変わってる。

Githubを確認。

https://github.com/Homebrew/homebrew-php

image.png

deprecated!!!

とりあえず動くようにしたい。

% brew install php@7.1

Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/php@7.1-7.1.16_1.sierra.bottle.tar.gz
Already downloaded: /Users/masayuki.ishikawa/Library/Caches/Homebrew/php@7.1-7.1.16_1.sierra.bottle.tar.gz
==> Pouring php@7.1-7.1.16_1.sierra.bottle.tar.gz
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set php_ini /usr/local/etc/php/7.1/php.ini system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set php_dir /usr/local/share/pear@7.1 system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set doc_dir /usr/local/share/pear@7.1/doc system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set ext_dir /usr/local/lib/php/pecl/20160303 system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set bin_dir /usr/local/opt/php@7.1/bin system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set data_dir /usr/local/share/pear@7.1/data system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set cfg_dir /usr/local/share/pear@7.1/cfg system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set www_dir /usr/local/share/pear@7.1/htdocs system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set man_dir /usr/local/share/man system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set test_dir /usr/local/share/pear@7.1/test system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear config-set php_bin /usr/local/opt/php@7.1/bin/php system
==> /usr/local/Cellar/php@7.1/7.1.16_1/bin/pear update-channels
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so

<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.1/

This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.zshrc

For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/php@7.1/lib
CPPFLAGS: -I/usr/local/opt/php@7.1/include

To have launchd start php@7.1 now and restart at login:
brew services start php@7.1
Or, if you don't want/need a background service you can just run:
php-fpm
==> Summary
🍺 /usr/local/Cellar/php@7.1/7.1.16_1: 514 files, 67MB
brew install php@7.1 3.84s user 4.29s system 63% cpu 12.835 total

% 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 install php71しただけでPATHもhomebrewが使用する/usr/local/bin/に入れてくれていたのに、よしなにやってくれなくなった。

.zshrcに入れる前に確認してみる。

% export PATH="/usr/local/opt/php@7.1/bin:$PATH"

% export PATH="/usr/local/opt/php@7.1/sbin:$PATH"

% php -v
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-igbinary/igbinary.so' - dlopen(/usr/local/opt/php71-igbinary/igbinary.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-igbinary/igbinary.so' - dlopen(/usr/local/opt/php71-igbinary/igbinary.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-intl/intl.so' - dlopen(/usr/local/opt/php71-intl/intl.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-intl/intl.so' - dlopen(/usr/local/opt/php71-intl/intl.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-mcrypt/mcrypt.so' - dlopen(/usr/local/opt/php71-mcrypt/mcrypt.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-mcrypt/mcrypt.so' - dlopen(/usr/local/opt/php71-mcrypt/mcrypt.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-memcached/memcached.so' - dlopen(/usr/local/opt/php71-memcached/memcached.so, 9): image not found in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library '/usr/local/opt/php71-memcached/memcached.so' - dlopen(/usr/local/opt/php71-memcached/memcached.so, 9): image not found in Unknown on line 0
PHP 7.1.16 (cli) (built: Apr 12 2018 03:25:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.16, Copyright (c) 1999-2018, by Zend Technologies

うーん。前に入れていたライブラリたちだ。邪魔しちゃってる。

% ll /usr/local/etc/php/7.1/conf.d/

total 48
drwxr-xr-x 7 masayuki.ishikawa admin 238B 4 25 16:07 ./
drwxr-xr-x 11 masayuki.ishikawa admin 374B 4 25 15:16 ../
-rw-r--r-- 1 masayuki.ishikawa admin 300B 2 5 11:04 ext-igbinary.ini
-rw-r--r-- 1 masayuki.ishikawa admin 303B 2 28 16:40 ext-intl.ini
-rw-r--r-- 1 masayuki.ishikawa admin 59B 2 28 16:40 ext-mcrypt.ini
-rw-r--r-- 1 masayuki.ishikawa admin 4.0K 2 5 11:04 ext-memcached.ini
-rw-r--r-- 1 masayuki.ishikawa admin 76B 4 25 16:07 ext-opcache.ini

もういいや。これ消しちゃえ。

% rm -rf /usr/local/etc/php/7.1/conf.d/*

zsh: sure you want to delete all the files in /usr/local/etc/php/7.1/conf.d [yn]? y

% php -v
PHP 7.1.16 (cli) (built: Apr 12 2018 03:25:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

とりあえずWarningは消えた。

ライブラリは。。。またぶつかったら解決しよう。

p.s.

2018/3/31のcommitでhomebrew/phpがdeprecate tapされたのを確認した。

https://github.com/Homebrew/homebrew-php/commit/3adb72d1cf5005849b16705243d940cf52287051#diff-04c6e90faac2675aa89e2176d2eec7d8

あとbashの人は本文中のzshrcをbashrcとかに読み替えてね。