买 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 多版本的 共存 和 切换
如何 实现PHP多版本的 共存 和 切换?
延伸阅读:
Mac Pro 编译安装 PHP 5.6.21 及 问题汇总
记 Mac 升级后,编译安装 PHP-5.6.28 / PHP-7.0 报错修复过程