源码安装 PHP 7.3

发布时间:2019-08-07 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了源码安装 PHP 7.3脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文以当前最新版本 PHP 7.3.1 演示整个码安装的流程。

下载 PHP 源码包

访问 PHP 官网的源码包下载地址 http://php.net/downloads.php

源码安装 PHP 7.3

如图所示,PHP 源码提供了三种压缩格式,通常压缩后的文件越小,意味着解压缩需要的时间和 CPU 消耗就会更多,这里要根据安装 PHP 的服务器硬件情况和带宽选择合适的压缩格式,我选择下载 php-7.3.1.tar.gz

下载源码有两种方式:

  1. 服务器端使用 wget 命令直接下载 。
  2. 首先下载到本地,然后通过 FTP 传到服务器。

以第一种方法为例,在服务器端执行:

wget -c http://cn2.php.net/distributions/php-7.3.1.tar.gz

点开其中一个压缩包,右击 China 的 cn2.php.net 复制链接地址,可以获得另一个下载地址,获取方式如下图所示:

http://cn2.php.net/get/php-7.3.1.tar.gz/From/this/mirror

# 此地址的下载命令,使用 -O 重命名源码包,否则下载后的文件名会是 mirror
wget -O php-7.3.1.tar.gz http://cn2.php.net/get/php-7.3.1.tar.gz/from/this/mirror

如果需要下载其他版本,只需要修改下载地址中的版本号,例如 php-7.2.14.tar.gz

安装 PHP

使用 tar 命令解压 tar.gz 压缩包:

tar -xzvf php-7.3.1.tar.gz

安装 PHP 需要的扩展库

yum install -y libXMl2 *oPEnssl* libcurl* libjpeg* libpng* freetype* libzip* libmcrypt*

进入解压后的 php-7.2.4 文件夹,运行 configure 可执行文件:

./configure --PRefix=/mnt/php7 --wITh-MySQLi --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxML-dir --enable-simplexml --enable-xml --disable-rpath --enable-bcmath --enable-SOAp --enable-zip --with-curl --enable-FPM --with-fpm-user=www --with-fpm-group=www --enable-mbstring --enable-sockets --with-gd --with-openssl --with-mhash --enable-Opcache --disable-fileinfo

源码安装 PHP 7.3

如果最后显示以上界面,说明已经成功安装。


由于我测试的是一个新的服务器,所以依次遇到了以下错误,没有出现问题可以跳过这部分:

错误1:

configure: error: in `/root/php-7.3.1':
configure: error: no acceptable C compiler found in $PATH
# 缺少 c 编译器,安装 GCC
yum install gcc

错误2:

checking for libzip... configure: error: System libzip must be upgraded to version >= 0.11
# 查看 yum 安装的 libzip 版本
yum list installed | grep libzip

# 发现 yum 安装的 libzip 版本过低,卸载低版本
yum remove libzip*

源码安装 libzip

# 源码编译安装 libzip 最新版
# libzip 官网地址:https://libzip.org
wget https://nih.at/libzip/libzip-1.5.1.tar.gz
tar -zxvf libzip-1.5.1.tar.gz
cd libzip-1.5.1
## 查看 INSTALL.md 其中有安装提示
mkdir build
cd build
@R_407_1512@ ..
make
make test
make install

上述命令在执行 cmake .. 时报错,使用 yum 安装了 gcc-c++

yum -y install gcc-c++

又重新源码编译安装了了 Cmake,参考这篇文章

错误3:

error: off_t undefined; check your library configuration
# 添加搜索路径到配置文件
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
# 更新配置
ldconfig -v

此错误详细解释参考 https://segmentfault.com/q/10... 中 @代码狗 的回答。


编译和安装

make && make install

配置

进入 /mnt/php7/sbin,启动 php-fpm

[@R_406_74@ sbin]# ./php-fpm
[15-Jan-2019 03:32:21] ERROR: failed to open configuration file '/mnt/php7/etc/php-fpm.conf': No such file or directory (2)
[15-Jan-2019 03:32:21] ERROR: failed to load configuration file '/mnt/php7/etc/php-fpm.conf'
[15-Jan-2019 03:32:21] ERROR: FPM initialization failed

解决办法:

# 进入 /mnt/php7/etc,复制 php-fpm 的配置文件
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf

# 进入 /mnt/php7/etc/php-fpm.d,复制 php-fpm 的子配置文件:
[root@localhost php-fpm.d]# cp www.conf.default www.conf

在运行 php-fpm 前,还需要修改其子配置文件中的用户和用户组,以 nginx 为例,编辑 /mnt/php7/etc/php-fpm.d 文件:

user = nginx
group = nginx

至此就可以启动 php-fpm 了。

在命令行下运行 php,需要将可执行文件复制到环境变量下:

cp /mnt/php7/bin/php /usr/local/bin/php

# 命令行下查看 php 版本
php -v

脚本宝典总结

以上是脚本宝典为你收集整理的源码安装 PHP 7.3全部内容,希望文章能够帮你解决源码安装 PHP 7.3所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。