MacOS Sierra或者OS X EI Capitan安裝PHP擴展出錯
(10.11.x 10.12.x)
【錯誤】
裝不了php的擴展,make install失敗
RudonMacBook:igbinary-master rudon$ make install
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20131226/
cp: /usr/lib/php/extensions/no-debug-non-zts-20131226/#INST@12567#: Operation not permitted
make: *** [install-modules] Error 1
cp: /usr/lib/php/extensions/no-debug-non-zts-20121212/#INST@17000#: Operation not permitted
【緣由】
原來是OSX 10.11 El Capitan(或更高)新添加了一個新的安全機制叫系統完整性保護System Integrity Protection (SIP),所以對於目錄
/System
/sbin
/usr
不包含(/usr/local/)
僅僅供系統使用,其它用戶或者程序無法直接使用,而我們的/usr/lib/php/extensions/剛好在受保護范圍內
【解決】
所以解決方法就是禁掉SIP保護機制,步驟是:
重啟系統
按住Command + R (重新亮屏之后就開始按,象征地按幾秒再松開,出現蘋果標志,ok)
菜單“實用工具” ==>> “終端” ==>> 輸入csrutil disable;執行后會輸出:Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect.
再次重啟系統
禁止掉SIP后,就可以順利的安裝了,當然裝完了以后你可以重新打開SIP,方法同上,只是命令是csrutil enable
OK!
現在可以正常的編譯/添加各種擴展了。
【實例】
# 參考自http://blog.csdn.net/chong2230/article/details/25964965
curl -O https://nodeload.github.com/nicolasff/phpredis/zip/master
tar -zxf master
cd phpredis-master/
phpize
./configure
make
sudo make install
# 提示 /usr/lib/php/extensions/no-debug-non-zts-xxxxxxxxx/ 表示成功
vim /etc/php.ini (如果沒有,那就復制一份/etc/php.ini.default之類的並重命名)
# 添加下面這句話,保存文件
extension=redis.so
#重啟apache
sudo apachectl restart
#查看擴展安裝情況,出現 redis 表示安裝成功。或者看phpinfo()
php -m |grep redis
【關聯閱讀】