PHP7.4 编译安装笔记
准备工作
下载 PHP 7.4 源码
PHP版本发布:(https://www.php.net/downloads)[https://www.php.net/downloads]
这里选择的是最新的 PHP 7.4.9 (其实8.0 的 Beta 测试版已经出来了)
1 | wget https://www.php.net/distributions/php-7.4.9.tar.gz -O /opt/php74.tar.gz |
解压
1 | cd /opt && tar -zxf /opt/php74.tar.gz |
查看解压内容
1 | cd php74 && ls -lh |

安装工作
configure
执行 ./configure
1 | ./configure -prefix=/usr/local/php --with-curl --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml |
处理 configure 报错
报错:configure: error: no acceptable C compiler found in $PATH
安装 gccapt install gcc
报错
1 | configure: error: The pkg-config script could not be found or is too old. Make sure it |
安装 pkg-config
1 | apt install pkg-config |
报错
1 | configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met: |
安装 libxml
1 | apt install libxml2 |
报错
1 | configure: error: Package requirements (krb5-gssapi krb5) were not met: |
安装 libkrb5
1 | apt install libkrb5-dev |
报错
1 | configure: error: Package requirements (openssl >= 1.0.1) were not met: |
安装 libssl-dev
1 | apt install libssl-dev |
报错
1 | configure: error: Package requirements (sqlite3 > 3.7.4) were not met: |
安装 libsqlite3-dev
1 | apt install libsqlite3-dev |
报错
1 | configure: error: Package requirements (oniguruma) were not met: |
这个包在 apt 里没找到只能自己编译安装了
编译安装 oniguruma
1 | cd /opt |
报错
1 | Generating autotools files. |
安装 libtool automake
1 | apt install libtool automake |
再来一次就可以了
1 | ./autogen.sh |
执行 ./configure 看到
1 | Run ./configure, make, and make install. |
说明 configure 成功
编译安装 make && make install
1 | make && make install |
回到 php74 目录继续安装工作
1 | cd /opt/php74 |
执行 ./configure
1 | ./configure -prefix=/usr/local/php --with-curl --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml |
报错
1 | configure: error: Package requirements (libxslt >= 1.1.0) were not met: |
安装 libxslt1-dev
1 | apt install libxslt1-dev |
终于 configure 通过
1 | +--------------------------------------------------------------------+ |
太不容易了
激动人心的 make && make install
1 | make && make install |
1 | [PEAR] Archive_Tar - installed: 1.4.9 |
调整配置
查看 php.ini 默认的装载目录
因为在编译阶段没有加入 --with-config-file-path=(path-to-ini-dir),所以目录是源码默认的目录,加入这个参数在 ./configure 可以指定目录;这里可以通过命令来查找出装载的 ini 的位置,当然如果是 cli 模式也可以通过 -c 参数来指定本次执行装载的 php.ini 文件。
1 | php -i | grep ini |
1 | Configuration File (php.ini) Path => /usr/local/php/lib |
创建 ini 配置
拷贝一份源码目录下的 php.ini-production 到 etc 目录下
1 | cp /opt/php74/php.ini-production /usr/local/php/etc/php.ini |
软连接到默认目录
1 | ln -s /usr/local/php/etc/php.ini /usr/local/php/lib/php.ini |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Ansuir 的半亩方田!

