[Updated 4/6/2018]由于Homebrew/php自來水在2018年3月底被棄用,并將所有PHP公式轉移到Homebrew/core,舊的brew tap homebrew/dupes、brew tap homebrew/versions、brew tap homebrew/homebrew-php都會報以下錯誤:
Warning: homebrew/dupes was deprecated. This tap is now empty as all its formulae were migrated.
安裝mac+nginx+mysql可看之前的文章,php安裝和安裝擴展,如memcached、redis等則不可在用brew search php查看擴展brew install php70-memcached這種方式安裝擴展了。看圖:

image.png
安裝php
brew install php56
安裝php擴展(難點)
不推薦用 pecl 的方式安裝 PHP 擴展。以 php-redis 擴展為例,下載源碼包來進行安裝:
wget https://pecl.php.net/get/redis-3.1.3.tgz # 下載源碼包
tar -zxvf redis-3.1.3.tgz # 解壓
cd redis-3.1.3
phpize # 生成編譯配置
./configure # 編譯配置檢測
make # 編譯
make install # 安裝
如我安裝的路徑:
image.png
注意:看清你安裝的路徑
安裝memcach、memcached(php5.幾版本的需要安裝[memcached-2.2.0.tgz](http://pecl.php.net/get/memcached-2.2.0.tgz) 才不會報錯)、mongo、mongodb可去pecl搜搜下載對應的包。下載下來直接解壓安裝包,建議把安裝包放到php@5.6同一級目錄中(如:/usr/local/Cellar)解壓了文件就可以跳過之前安裝的兩步,直接 cd …進入生成編輯配置。
安裝遇到的錯誤
1.錯誤configure:error:請重新安裝pkg-config分配
報錯信息:Checking for pkg-config… /usr/bin/pkg-config
configure: error: Cannot find OpenSSL’s <evp.h>
解決辦法:
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz
tar -zxvf pkg-config-0.28.tar.gz
cd pkg-config-0.28
./configure --with-internal-glib
make && make install
2.報錯信息:fatal error: 'openssl/sha.h' file not found on installation
解決辦法:
$ cd /usr/local/include
$ ln -s ../opt/openssl/include/openssl .
如下是我編輯安裝成功的擴展:

image.png

image.png