1.安装必要的工具:
首先确保您已经安装了 Xcode 和 Command Line Tools:
xcode-select --install
2.下载 PHP 7.1 源代码:
访问 PHP 官方网站下载 PHP 7.1 的源代码:
wget https://www.php.net/distributions/php-7.1.33.tar.gz
tar -zxvf php-7.1.33.tar.gz
cd php-7.1.33
3.配置并编译 PHP:
./configure --prefix=/usr/local/php71
make
sudo make install
4.添加 PHP 到 PATH:
将 PHP 7.1 添加到您的 PATH 中以便可以在命令行中访问它:
echo 'export PATH="/usr/local/php71/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
5.验证安装:
php -v
问题汇总:
先安装liviconv,再继续编译
./configure --prefix=/Users/luzhifang/php/php-7.3.4/output/ --enable-fpm --enable-debug --with-iconv=/usr/local/opt/libiconv/
https://zhuanlan.zhihu.com/p/370921434
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
clicommand.inc
directorygraphiterator.inc
invertedregexiterator.inc
pharcommand.inc
make: *** [ext/phar/phar.phar] Segmentation fault: 11
解决办法:编译参数增加 --without-pear --disable-phar
./configure --without-pear --disable-phar --with-iconv=/usr/local/opt/libiconv/ --prefix=/Users/dongxue/work/php/php-7.1.0/output --enable-fpm
vim Makefile // 修改 Makefile,-liconv -liconv 改成 -liconv /usr/local/opt/libiconv/lib/libiconv.dylib
make clean
make && make install