Upgrading PHP on MacOS

Log — Tags: , , , — Posted by Starck on March 29, 2013


使用 Brew 讓在 MacOS 安裝管理套件變得容易許多, 而 HomeBrew-PHP 則是讓你在 MacOS 上安裝 PHP 和管理 extensions 的 Brew 套件.


安裝 Brew:

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

如果之前已經安裝過 Brew, 依據習慣, 我會將 Brew 更新到最後的版本:

brew update

brew upgrade


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 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

** 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:

如果使用 FPM, 請在 Terminal 下達:


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:

(c) 2024 Starck Lin | powered by WordPress