Homebrew将PHP从PHP5升级到PHP7
在PHP7的轻松交流活动#1开始之前,我简单了解了一下并同时安装了PHP7,并做了一些事情。(因为我想到参加了PHP7的学习会,却没有安装PHP7,觉得很奇怪。)
总结
-
- Homebrew
-
- Yosemite
- 以前まではphp5.5を入れてたっぽい?初心者のころに買ったmacだからよくわからぬ
我試著放進去。
$ brew update
$ brew install homebrew/php/php70
$ brew install homebrew/php/php70
==> Tapping homebrew/php
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-php'...
remote: Counting objects: 575, done.
remote: Compressing objects: 100% (354/354), done.
remote: Total 575 (delta 384), reused 250 (delta 220), pack-reused 0
Receiving objects: 100% (575/575), 238.43 KiB | 347 KiB/s, done.
Resolving deltas: 100% (384/384), done.
Tapped 555 formulae (591 files, 1M)
==> Installing php70 from homebrew/php
Error: Formulae found in multiple taps:
* homebrew/php/php53
* josegonzalez/php/php53
Please use the fully-qualified name e.g. homebrew/php/php53 to refer the formula.
错误。
如果你调查了,就请untap它吧。
brew untap josegonzalez/php
brew tap --repair
brew update
brew install homebrew/php/php70
==> Installing php70 from homebrew/php
Error: Cannot install homebrew/php/php70 because conflicting formulae are installed.
php55: because different php versions install the same binaries.
Please `brew unlink php55` before continuing.
Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.
再一次出错。
移除php55。
$ brew unlink php55
Unlinking /usr/local/Cellar/php55/5.5.22... Error: Permission denied - /usr/local/lib/php/.channels
哎呀。出错了。。。
这次是unlink产生的错误,所以需要用sudo来处理。
$ sudo brew unlink php55
好的,我们走吧。
我要安装。
$ brew install homebrew/php/php70
==> Installing php70 from homebrew/php
==> Installing dependencies for homebrew/php/php70: libpng, freetype, get
==> Installing homebrew/php/php70 dependency: libpng
==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.21.yosemite.bott
######################################################################## 100.0%
==> Pouring libpng-1.6.21.yosemite.bottle.tar.gz
? /usr/local/Cellar/libpng/1.6.21: 17 files, 1.2M
==> Installing homebrew/php/php70 dependency: freetype
==> Downloading https://homebrew.bintray.com/bottles/freetype-2.6.2.yosemite.bot
######################################################################## 100.0%
==> Pouring freetype-2.6.2.yosemite.bottle.tar.gz
? /usr/local/Cellar/freetype/2.6.2: 60 files, 2.4M
==> Installing homebrew/php/php70 dependency: gettext
==> Downloading https://homebrew.bintray.com/bottles/gettext-0.19.7.yosemite.bot
######################################################################## 100.0%
==> Pouring gettext-0.19.7.yosemite.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
OS X provides the BSD gettext library and some software gets confused if both are in the library path.
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/gettext/lib
CPPFLAGS: -I/usr/local/opt/gettext/include
==> Summary
? /usr/local/Cellar/gettext/0.19.7: 1,929 files, 16.6M
==> Installing homebrew/php/php70 dependency: icu4c
==> Downloading https://homebrew.bintray.com/bottles/icu4c-56.1.yosemite.bottle.
######################################################################## 100.0%
==> Pouring icu4c-56.1.yosemite.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
OS X provides libicucore.dylib (but nothing else).
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/icu4c/lib
CPPFLAGS: -I/usr/local/opt/icu4c/include
==> Summary
? /usr/local/Cellar/icu4c/56.1: 244 files, 63.7M
==> Installing homebrew/php/php70 dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2f.yosemite.bot
######################################################################## 100.0%
==> Pouring openssl-1.0.2f.yosemite.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
This formula is keg-only, which means it was not symlinked into /usr/local.
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
==> Summary
? /usr/local/Cellar/openssl/1.0.2f: 466 files, 11.9M
==> Installing homebrew/php/php70
==> Downloading https://homebrew.bintray.com/bottles-php/php70-7.0.2.yosemite.bo
######################################################################## 100.0%
==> Pouring php70-7.0.2.yosemite.bottle.10.tar.gz
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
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 at login:
ln -sfv /usr/local/opt/php70/*.plist ~/Library/LaunchAgents
Then to load homebrew/php/php70 now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
==> Summary
? /usr/local/Cellar/php70/7.0.2: 331 files, 49.3M
好像出来了吧?
$ php -v
PHP 7.0.2 (cli) (built: Jan 7 2016 10:40:21) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
既然这样,还是将路径添加到bashrc文件中比较好,所以添加进去。
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
看起来可以。如果发生问题,再重新考虑。