Upgrading PHP on MacOS
所需工具
使用 Brew 讓在 MacOS 安裝管理套件變得容易許多, 而 HomeBrew-PHP 則是讓你在 MacOS 上安裝 PHP 和管理 extensions 的 Brew 套件.
Brew
安裝 Brew:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
如果之前已經安裝過 Brew, 依據習慣, 我會將 Brew 更新到最後的版本:
brew update
brew upgrade
Installation
Tap the homebrew/dupes repository into your brew installation:
brew tap homebrew/dupes
Tap the repository into your brew installation:
brew tap josegonzalez/homebrew-php
安裝參數說明
brew options php54
安裝 php 5.4
brew install php54
安裝時可能會出現的問題
jpeg8-d:
jpeg8-d is already installed, it's just not linked Could not symlink file: /usr/local/Cellar/jpeg/8d/bin/wrjpgcom Target /usr/local/bin/wrjpgcom already exists. You may need to delete it. To force the link and delete this file, do: brew link --overwrite formula_name
解法:
brew link --overwrite jpeg
Apache httpd.conf 設定
先檢查 /usr/local/Cellar/php54/
下的 php 版本號是多少, 例如: 5.4.12
1 2 3 4 |
# /etc/apache2/httpd.conf # Swapping from PHP53 to PHP54 # LoadModule php5_module /usr/local/Cellar/php53/5.3.20/libexec/apache2/libphp5.so LoadModule php5_module /usr/local/Cellar/php54/5.4.12/libexec/apache2/libphp5.so |
** Update 2013-08-07 **
在 Moutain Lion Server 下, 修改 php module 讀取路徑要到
/Library/Server/Web/Config/apache2/httpd_server_app.conf
** Update 2013-10-26 **
After updating Mavericks Server, please also upgrade to the latest Xcode and make sure you re-install Command-line Tools:
xcode-select --install
Edit
/Library/Server/Web/Config/apache2/httpd_server_app.conf
:
1 2 |
# LoadModule php5_module libexec/apache2/libphp5.so LoadModule php5_module /usr/local/opt/php54/libexec/apache2/libphp5.so |
如果使用 FPM, 請在 Terminal 下達:
1 2 3 |
cp /usr/local/Cellar/php54/5.4.12/homebrew-php.josegonzalez.php54.plist ~/Library/LaunchAgents/ launchctl unload -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php53.plist launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php54.plist |
Command-line
If you would like to swap the PHP you use on the command line, you should update the $PATH
variable in either your .bashrc
or .bash_profile
:
1 2 3 |
# Swapping from PHP53 to PHP54 # export PATH="$(brew --prefix josegonzalez/php/php53)/bin:$PATH" export PATH="$(brew --prefix josegonzalez/php/php54)/bin:$PATH" |
Pingback: Starck Lin » 最常用的 SublimeText Plugins 和 Key Bindings()