買 Mac Pro 的時候,系統為 OS X 10.11.5,編譯 PHP-5.6.21 的時候,也遇到一些坑,安裝過程記錄如下:
Mac Pro 編譯安裝 PHP 5.6.21 及 問題匯總
后來,系統升級為 OS X 10.11.6,再后來,打算升級 PHP 至 5.6.28,報錯:
【報錯1】
./configure 時報錯
conftest.c:9:10: fatal error: 'ac_nonexistent.h' file not found
【解決】
再次升級到最新的蘋果系統 OS Sierra 10.12.1
【報錯2】
configure: error: Cannot find libz
【試着解決】
執行 sudo brew install libz,繼續報錯:
【報錯3】
Error: No available formula with the name "libz"
==> Searching for similarly named formulae...
These similarly named formulae were found:
libzdb libzip libzzip
To install one of them, run (for example):
brew install libzdb
==> Searching taps...
Error: No formulae found in taps.
==> You haven't updated Homebrew in a while.
A formula for libz might have been added recently.
Run `brew update` to get the latest Homebrew updates!
按照提示,執行 brew update,繼續報錯:
【報錯4】
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
[etc..]
Error: update-report should not be called directly!
參考國外的網站,homebrew-error-update-report-should-not-be-called-directly
【解決】
cd /usr/local; git reset --hard origin/master; brew update
繼續執行,brew update,繼續報錯:
【報錯5】
Error: /usr/local must be writable!
執行 sudo brew update,繼續報錯:
【報錯6】
Error: Cowardly refusing to 'sudo brew update'
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.
好吧,修改 /usr/local/ 文件夾的權限(用戶)
sudo chown -R $(whoami) /usr/local
再次執行 brew update,這條語句沒報錯!
繼續解決 Cannot find libz 的問題,執行: brew install libz,報錯
【報錯7】
Error: No available formula with the name "libz"
==> Searching for similarly named formulae...
These similarly named formulae were found:
libzdb libzip libzzip
To install one of them, run (for example):
brew install libzdb
==> Searching taps...
Error: No formulae found in taps.
后來,找到一個帖子,Cannot find libz when install php56,找到解決方案
【解決】
執行
xcode-select --install brew upgrade
PHP-5.6 繼續執行,./configure ,沒報錯!
./configure \ --prefix=/usr/local/php/php-5.6 \ --with-config-file-path=/usr/local/php/php-5.6/etc \ --with-openssl=/usr/local/opt/openssl \ --with-zlib \ --with-bz2 \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-gettext \ --with-mhash \ --with-freetype-dir \ --with-mcrypt \ --with-iconv \ --with-curl \ --with-xmlrpc \ --with-mysql \ --with-pdo-mysql \ --with-mysqli \ --enable-calendar \ --enable-pdo \ --enable-zip \ --enable-mbstring \ --enable-mbregex \ --enable-bcmath \ --enable-soap \ --enable-sockets \ --enable-ftp \ --enable-gd-native-ttf \ --enable-shmop \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-xml \ --enable-pcntl \ --enable-fpm \ --enable-opcache \ --without-pear
PHP-7.0
./configure \ --prefix=/usr/local/php/php-7.0 \ --with-config-file-path=/usr/local/php/php-7.0/etc \ --with-openssl=/usr/local/opt/openssl \ --with-zlib \ --with-bz2 \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-gettext \ --with-mhash \ --with-freetype-dir \ --with-mcrypt \ --with-iconv \ --with-curl \ --with-xmlrpc \ --with-pdo-mysql \ --with-mysqli \ --enable-calendar \ --enable-pdo \ --enable-zip \ --enable-mbstring \ --enable-mbregex \ --enable-bcmath \ --enable-soap \ --enable-sockets \ --enable-ftp \ --enable-gd-native-ttf \ --enable-shmop \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-xml \ --enable-pcntl \ --enable-fpm \ --enable-opcache \ --without-pear
執行 make 的時候會報錯,參考 以前的文章,即可解決:
Mac Pro 編譯安裝 PHP 5.6.21 及 問題匯總
執行 make 操作的時候,又報錯:
/usr/lib/libiconv.dylib /usr/local/lib/libiconv.dylib -o sapi/cli/php
ld: can't write output file: sapi/cli/php for architecture x86_64
提示不能寫入,應該是權限的問題,進入源碼包的,查看文件 ./sapi/cli/php 文件,所屬用戶為 root,果然是權限問題,執行 make 的時候,sudo 一下,即 sudo make,大功告成。
按照同樣的方式,編譯安裝了 PHP-7.0,並實現了 PHP 多版本的 共存 和 切換
延伸閱讀: