Linux[CentOS]下编译安装Php7.3 步骤【附编译错误解决】

无道 2019-10-21 0 条评论 教程相关 阅读2079 手机阅读

前言

上一篇讲了如何在Centos下编译安装nginx服务器,但是Nginx服务器目前只能当做静态服务器使用,也即只能展示前端静态页面,没有动态语言来结合。

本篇文章来讲下如何从源码编译安装php

编译安装是需要很长时间的

步骤

安装依赖

更新依赖包:

yum -y update

安装依赖:

yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++

截图-1571662673

下载源码

官网下载页面:https://www.php.net/downloads.php

目前官最新版是7.3,我们就安装最新版的吧。

截图-1571486498

wget -c https://www.php.net/distributions/php-7.3.10.tar.gz

截图-1571486613

解压

 tar -zxvf php-7.3.10.tar.gz

截图-1571487234

添加用户和组

groupadd www
useradd -g www www

截图-1571662871

配置参数

首先需要进入解压后的目录

cd php-7.3.10 

截图-1571487302

如图,目录里面还是痛Nginx有一个configure可执行文件,用以配置安装时的参数

那么配置哪些参数?

./configure \
 --prefix=/usr/local/php\
 --enable-fpm\
 --with-fpm-user=www\
 --with-fpm-group=www\
 --with-config-file-path=/usr/local/php/conf\
 --disable-rpath\
 --enable-soap\
 --with-libxml-dir\
 --with-xmlrpc\
 --with-openssl\
 --with-mhash\
 --with-pcre-regex\
 --with-zlib\
 --enable-bcmath\
 --with-bz2\
 --enable-calendar\
 --with-curl\
 --enable-exif\
 --with-pcre-dir\
 --enable-ftp\
 --with-gd\
 --with-openssl-dir\
 --with-jpeg-dir\
 --with-png-dir\
 --with-zlib-dir\
 --with-freetype-dir\
 --enable-gd-jis-conv\
 --with-gettext\
 --with-gmp\
 --with-mhash\
 --enable-mbstring\
 --with-onig\
 --with-mysqli=mysqlnd\
 --with-pdo-mysql=mysqlnd\
 --with-zlib-dir\
 --with-readline\
 --enable-shmop\
 --enable-sockets\
 --enable-sysvmsg\
 --enable-sysvsem \
 --enable-sysvshm \
 --enable-wddx\
 --with-libxml-dir\
 --with-xsl\
 --enable-zip\
 --with-pear

如上是我网上找的一个配置参数,而且看了下,感觉挺全。说一些较重要的吧:

--prefix=/usr/local/php 安装目录,如nginx我们安装到了/usr/local/nginx

--with-config-file-path=/usr/local/php/etc 配置文件目录,我觉得这样挺好,就在/usr/local/php下面的etc,而不是系统的/etc里面。

题外

由于本次选择了安装7.3最新版,结果出师不利,配置时一直报错:

截图-1571488784

configure: error: Please reinstall the libzip distribution

解决步骤:

A. 先安装最新cmake,这一步的时间不短,可尝试直接进入B。

cd /usr/local/src
wget https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz
tar -zxvf cmake-3.14.3.tar.gz
cd cmake-3.14.3
./bootstrap
make && make install

截图-1571664383

B. 再编译安装libzip

yum remove libzip -y
cd /usr/local/src
wget  https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxvf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make && make install

步骤A编译挺慢的,但是步骤A完成后,B还是挺快的。

C. 继续报错: error: off_t undefined; check your library configuration

vi /etc/ld.so.conf 
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64 
#保存退出
:wq
ldconfig -v # 使之生效

错误代码解决,参考的此篇文章:https://blog.csdn.net/ijijni/article/details/89913738

编译安装

以上错误解决后,再执行下./configure命令,

截图-1571664675

然后没报错后,执行以下命令:

make && make install

此步编译又是需要不少的时间的,可以喝一杯咖啡,或者洗澡【如现在的我】

安装完毕

截图-1571665763

添加环境变量

vi /etc/profile
#添加以下内容到最后
PATH=$PATH:/usr/local/php/bin
export PATH
#刷新环境变量
source /etc/profile

配置文件复制

mkdir /usr/local/php/conf
cp php.ini-production /usr/local/php/conf/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

执行以上命令是在解压的php源码目录

测试

php -v

截图-1571666016

全文完 [
有帮助?打赏
支付宝打赏
微信打赏
]
修改: 2019-10-21 21:54
这篇文章还没有评论呢~
点击刷新/生成验证码