DEV

mac - phpを7.0にバージョンアップ

macは、10.11.5、El Capitanです。

現在のバージョンを確認

$ php -v
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_mysql.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_mysql.dll, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_mysqli.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_mysqli.dll, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_pdo_mysql.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_pdo_mysql.dll, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_pdo_sqlite.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_pdo_sqlite.dll, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/php_sqlite3.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20121212/php_sqlite3.dll, 9): image not found in Unknown on line 0
PHP 5.5.34 (cli) (built: Apr 22 2016 19:16:58)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

なんかWarningがたくさん出ている。

PHP7.0をインストール

$ curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0

インストール成功した。

PATH設定

$ export PATH=/usr/local/php5/bin:$PATH

PHPバージョン確認

$ php -v
PHP 7.0.6 (cli) (built: May 24 2016 23:07:51) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0RC3, Copyright (c) 2002-2015, by Derick Rethans

PHP 7.0.6になった。


追記:

brewでphp7をインストールする

上記のPHPを削除する

$ sudo rm -rf /usr/local/bin/php5
$ sudo rm -rf /usr/local/bin/php5-7.0.6-20160524-231014/

.bash_profileを修正する

$ vim ~/.bash_profile

下記を削除する

#php7
PATH=/usr/local/php5/bin:$PATH
PATH=/usr/local/php5/sbin:$PATH

修正を反映する

$ source ~/.bash_profile

brewのリポジトリを追加する

$ brew tap homebrew/dupes
$ brew tap homebrew/php

php7をインストールする

$ brew install php70
中略
The php.ini file can be found in:
/usr/local/etc/php/7.0/php.ini
✩✩✩✩ Extensions ✩✩✩✩
If you are having issues with custom extension compiling, ensure that
you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
PATH="/usr/local/bin:$PATH"
PHP70 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.
✩✩✩✩ PHP CLI ✩✩✩✩
If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell's equivalent configuration file:
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
✩✩✩✩ FPM ✩✩✩✩
To launch php-fpm on startup:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
The control script is located at /usr/local/opt/php70/sbin/php70-fpm
OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
PATH="/usr/local/sbin:$PATH"
You may also need to edit the plist to use the correct "UserName".
Please note that the plist was called 'homebrew-php.josegonzalez.php70.plist' in old versions
of this formula.
To have launchd start homebrew/php/php70 now and restart at login:
brew services start homebrew/php/php70
==> Summary
🍺 /usr/local/Cellar/php70/7.0.6: 332 files, 49.2M

.bash_profileを修正する

下記を最後に追加する。

PATH="/usr/local/sbin:$PATH"

バージョン確認

$ php -v
PHP 7.0.6 (cli) (built: Apr 29 2016 04:21:39) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
$ php-fpm -v
PHP 7.0.6 (fpm-fcgi) (built: Apr 29 2016 04:21:42)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies