阿里云服务器(ECS) 编译安装 php7.3 详细教程及常见问题

准备工作

1.服务器,这里我使用的是阿里云的ECS服务器,安装的操作系统为 CenterOs7.4。
2.细心、耐心。

创建用户组和用户

groupadd www
useradd -g www www

下载php7.3

使用wget将 PHP官方网站 上的最新原码包下载至服务器并解压

wget "https://downloads.php.net/~cmb/php-7.3.2.tar.gz"
tar xzvf php-7.3.2.tar.gz
cd php-7.3.2

编译安装

注意编译配置中的用户组和用户设置,如果你的用户组和用户不是“www”,请自行替换。

–with-fpm-user=www --with-fpm-group=www

在解压后的php原码包下执行如下编译配置,也可以执行 ./configure -help 查看编译选项说明

./configure --prefix=/usr/local/php --with-fpm-user=www --with-fpm-group=www --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm

编译错误解决

执行过程可能会出现多次error报错,大部分可能是依赖缺失,那我们就缺什么补什么,直到编译成功,下面列出一些常见的问题供大家参考。

libxml2 报错

configure: error: libxml2 not found. Please check your libxml2 installation.

yum install -y libxml2-devel

OpenSSL

configure: error: Cannot find OpenSSL’s <evp.h>

yum install -y openssl openssl-devel

如果你已经安装 OpenSSL 可能是编译配置中的路径与你的OpenSSL安装路径不匹配,改成自己的再次编译

BZip2

configure: error: Please reinstall the BZip2 distribution

yum install -y bzip2-devel

cURL

checking for cURL 7.15.5 or greater… configure: error: cURL version 7.15.5 or later is required to compile php with cURL support

yum install -y curl-devel

jpeglib

configure: error: jpeglib.h not found.

rpm -qa | grep libjpeg
yum install -y jpeglib-devel

png

configure: error: png.h not found.

yum install -y libpng-devel

freetype

configure: error: freetype-config not found.

yum install -y freetype-devel

xslt

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

yum install -y libxslt-devel

libzip

configure: error: Please reinstall the libzip distribution

yum install -y libzip-devel

libzip

checking for libzip… configure: error: system libzip must be upgraded to version >= 0.11
这是由于yum安装的libzip版本过低,那就需要卸载后手动安装最新libzip,操作步骤如下

#卸载刚才安装的低版本 libzip
yum remove -y libzip

#来到你下载源码包的文件夹,我的是 /home/lnmp
cd /home/lnmp
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install
#安装完成后记得回到php7.3源码包,继续编译

off_t

configure: error: off_t undefined; check your library configuration
该问题常见于centeros 64位系统中
这是因为默认情况下 centos 的动态链接库配置文件/etc/ld.so.conf里并没有加入搜索路径,这个时候需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。

#添加搜索路径到配置文件
vim /etc/ld.so.conf

如图,将四个路径放到文件内容最后

/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64

2-5行为新增路径
路径添加后保存退出,更新配置

ldconfig -v

至此,编译成功
编译完成
执行安装

make && make install

zipconf 错误

configure: error: Please reinstall the libzip distribution/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory

cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

再次运行

make && make install

安装完成
安装完成

配置

从原码包中将默认ini的配置文件复制到相应的路径中
ini配置文件有两个,php.ini-development(开发环境推荐使用),php.ini-production(生产环境推荐使用)
这是官方预设的两种环境下的推荐配置,我这里使用的是 php.ini-development,复制并改名为 php.ini

cp php.ini-development /usr/local/php/lib/php.ini

复制 php-fpm.conf 配置文件

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

添加软连接

ln -s /usr/local/php/sbin/php-fpm /usr/local/bin

配置www.conf

cd /usr/local/php/etc/php-fpm.d
vim www.conf

输入如下内容,注意用户组和用户:

[www]
listen = 127.0.0.1:9080
listen.mode = 0666

user = www
group = www

pm = dynamic
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10000

rlimit_files = 1024

slowlog = log/$pool.log.slow

将 php-fpm.service 加入 systemctl 服务

#进入PHP源码包目录
cd [替换成你自己的路径]/php-7.3.2/sapi/fpm
#复制文件
cp php-fpm.service /usr/lib/systemd/system/

验证安装结果

#启动
systemctl start php-fpm
#查看运行状态
systemctl status php-fpm

在这里插入图片描述
以上就是 php7.3 在 centeros7 下的全部的安装过程,希望对大家有帮助。

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译 ./configure --prefix=/usr/local/php --exec-prefix=/usr/local/php --bindir=/usr/local/php/bin --sbindir=/usr/local/php/sbin --includedir=/usr/local/php/include --libdir=/usr/local/php/lib/php --mandir=/usr/local/php/php/man --with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr /include --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --enable-fastcgi --with-fpm-user=www --with-fpm-group=www --without-gdbm --with-mcrypt=/usr/local/apps/libmcrypt --disable-fileinfo 报错:1, **configure: error: system libzip must be upgraded to version >=**0.11。 使用Yum最新版只到0.10,不足以达到要求。 一、先删除libzip yum remove libzip -y SSH执行以上命令,先删除libzip 和 libzip-devel 二、下载安装并手动编译 wget https://nih.at/libzip/libzip-1.2.0.tar.gz tar -zxvf libzip-1.2.0.tar.gz cd libzip-1.2.0 ./configure make && make install 三、(可忽略)另外最新版本请参考官网:https://nih.at/libzip/ 1.5.0的libzip需要cmake wget https://libzip.org/download/libzip-1.5.0.tar.gz tar -zxvf libzip-* cd libzip* mkdir build && cd build && cmake .. && make && make install 报错2: error: off_t undefined; check your library configuration 根据报错信息分析 configure: error: off_t undefined; check your library configuration 未定义的类型 off_t。 off_t 类型是在 头文件 unistd.h中定义的,在32位系统 编程成 long int ,64位系统则编译成 long long int ,这里题主的系统应该是 64位的吧,在进行编译的时候 是默认查找64位的动态链接库,但是默认情况下 centos 的动态链接库配置文件/etc/ld.so.conf里并没有加入搜索路径,这个时候需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。 采用下面的方法。 添加搜索路径到配置文件 echo '/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64'>>/etc/ld.so.conf 然后 更新配置 ldconfig -v 再次执行 编译 成功 执行安装: make && make install 报错: /usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory 解决: cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h 1 安装成功: 复制配置文件: cp php.ini-production /usr/local/php/lib/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf ln -s /usr/local/php/sbin/php-fpm /usr/local/bin 修改配置: cd /usr/local/php/etc/php-fpm.d vim www.conf [www] //池子名 (pool) 设置 ;listen = /tmp/php-fcgi.sock // 监听的地址,可以监听socket ,也可以监听端口 listen = 127.0.0.1:8089 或者这样写,php-fpm 通常在本地使用,php和nginx 通常在一台机器,所以可写127.0.0.1,别的机器 连接,需用本机ip listen.mode = 666 //sock 文件的权限 listen.owner = nobody listen.group = nobody user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 加入 systemtl 服务: cd /usr/local/src/php-7.3.0beta1/sapi/fpm cp php-fpm.service /usr/lib/systemd/system/ 启动: systemctl start php-fpm systemctl status php-fpm -l

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值