Homebrew 是 macOS 上最流行的套件管理工具,它透過 GitHub 託管適合 Mac 的編譯配置與補丁,讓開發工具的安裝變得輕鬆簡單。由於 macOS 內建 Ruby,安裝 Homebrew 非常方便,它也會順帶安裝 Git。官方網站:https://brew.sh
在終端機執行以下指令即可完成安裝:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
安裝完成後,可透過以下指令查看版本資訊:
brew -v # 輸出範例:Homebrew 0.9.5
為了安裝特定版本的 PHP,需要先加入對應的套件來源:
brew update brew tap homebrew/dupes brew tap homebrew/php brew tap josegonzalez/homebrew-php
使用 brew options php55 可查看所有可用的編譯選項。若系統已安裝 curl、libxslt、openssl 等套件,選項中會提示是否使用 Homebrew 版本的擴充功能:
brew options php55 # 顯示選項如 --with-homebrew-curl、--with-fpm、--with-debug 等
以下指令會安裝 PHP 5.5.15 並啟用常用擴充功能(如 MSSQL、OpenSSL、libxslt、cURL、FPM、Debug、GMP、IMAP、Tidy、libmysql)。安裝完成後,php.ini 與 php-fpm.ini 位於 /usr/local/etc/php/5.5/ 目錄下。
brew install php55 --with-mssql --with-homebrew-openssl --with-homebrew-libxslt --with-homebrew-curl --with-fpm --with-debug --with-gmp --with-imap --with-tidy --with-libmysql
安裝過程會自動下載並編譯相依套件(如 curl、freetds、gmp),最終輸出安裝摘要:
==> Summary /usr/local/Cellar/php55/5.5.15: 477 files, 43M, built in 3.9 minutes
若出現 configure: error: Cannot find OpenSSL's <evp.h> 錯誤,請執行以下指令更新 Xcode 命令列工具:
xcode-select --install
安裝完成後,需將 Homebrew 的 bin 與 sbin 路徑加入 PATH,以取代系統內建的 PHP:
echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile echo 'export PATH=/usr/local/sbin:$PATH' >> ~/.bash_profile source ~/.bash_profile
驗證版本:
php -v # 輸出:PHP 5.5.15 (cli) (built: Aug 14 2014 15:37:16) (DEBUG)
使用 brew search php55- 可列出所有可用的 PHP 5.5 擴充套件。以下範例安裝多個常用擴充功能:
brew install php55-imagick php55-igbinary php55-ev php55-gmagick php55-geoip php55-memcache php55-memcached php55-thrift php55-xdebug php55-sphinx composer
檢查設定檔語法:
php-fpm -t php-fpm -c /usr/local/etc/php/5.5/php.ini -y /usr/local/etc/php/5.5/php-fpm.conf -t
啟動服務並設定開機自動啟動:
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist # 檢查 9000 連接埠 lsof -i:9000
設定開機自動啟動(安裝提示中已說明):
ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
Zend Guard Loader (Runtime for PHP 5.4) 最高支援至 PHP 5.4,PHP 5.5 需使用 Zend Guard Loader for PHP 5.5 或改用 ionCube Loader。
Homebrew 目前未提供 Aircrack-ng,建議改用 MacPorts 安裝:
sudo port install aircrack-ng