php编译
操作系统:macOS
具体步骤
- 获取git源码:
git clone https://github.com/php/php-src.git
- 进入php-src
cd php-src
- 切换到指定分支,或者忽略此步骤,直接使用master分支
- 运行
./buildconf
./configure [options]
#例如 ./configure --enable-zip --enable-fpm --without-iconv --with-openssl --with-openssl-dir=/usr/local --enable-mysqlnd --with-zlib-dir=/usr/local/opt/zlib --enable-mbstring
异常:
- configure: error: Please specify the install prefix of iconv with --with-iconv=<DIR>
处理方法:
- 检查iconv是否安装:iconv --help
- 如果已经安装,获取路径:which iconv;然后重新运行:./configure --with-iconv=pathToIconv
- 如果没有安装(建议安装) 或 第2步失败:
1 brew install libiconv
2 ./configure --with-iconv=$(brew --prefix libiconv)
- configure: error: Package requirements (oniguruma) were not met
处理方法:
方法1: 去除 --enable-mbstring 选项
方法2: 安装oniguruma
5.make,
顺序执行,每一步成功后执行下一步
make -j4 #不超过cpu核心数
make TEST_PHP_ARGS=-j4 test
make install
异常:
php-src/ext/libxml/libxml.c:32:10: fatal error: 'libxml/parser.h' file not found
解决方法:
brew install libxml2
ln -s /usr/local/opt/libxml2/include/libxml2/libxml /usr/local/include/libxml
6.查看安装结果
php -v #查看版本
php8.0
异常:
PHP Warning: PHP Startup: Unable to load dynamic library 'redis.so'
解决方法:
找到php.ini文件php -r "phpinfo();" | grep 'php.ini'
,将扩展注释掉;extension=redis.so
我出现这个问题主要是由于用pecl装的redis扩展,如还需使用此扩展,卸载(pecl uninstall redis
)重装(pecl install redis
)扩展,然后取消注释即可