源码编译 - 看来PHP8.0呼之欲出啊

php编译

php.net
git

操作系统:macOS

具体步骤

  1. 获取git源码:
git clone https://github.com/php/php-src.git
  1. 进入php-src
cd php-src
  1. 切换到指定分支,或者忽略此步骤,直接使用master分支
  2. 运行
./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>

处理方法:

  1. 检查iconv是否安装:iconv --help
  2. 如果已经安装,获取路径:which iconv;然后重新运行:./configure --with-iconv=pathToIconv
  3. 如果没有安装(建议安装) 或 第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)扩展,然后取消注释即可

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容