Yum+源码包升级PHP

本文详细介绍如何通过Yum和源码包两种方式将PHP从5.4升级到5.6或7.1版本,包括删除旧版本、安装依赖、配置参数及验证升级后的版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

改进版本V1.1,修改源码包中的各种小错误

一.Yum升级

1.查看当前PHP版本

[root@localhost ~]# php -v
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

2.升级Yum软件仓库

[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

3.删除原有PHP程序

[root@localhost ~]# yum remove php-common php* -y

4.安装PHP 5.6版本以及使用模块

[root@localhost ~]# yum install php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring php56w-fpm -y

5.查看现在PHP版本

[root@localhost ~]# php -v
PHP 5.6.40 (cli) (built: Jan 12 2019 13:11:15) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

二.源码包安装

1.查看当前PHP版本

#无PHP程序可忽略!
[root@localhost ~]# php -v
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

2.下载php-7.1.31源码包

#因php-5.6版本过老查不到源码包,改用php-7.1.31版本
[root@localhost ~]# wget -c https://www.php.net/distributions/php-7.1.31.tar.gz

3.解压php-7.1.31源码包

[root@localhost data]# tar -xzf php-7.1.31.tar.gz

4.删除原有PHP程序

#无PHP程序可忽略!
[root@localhost php-7.1.31]# yum remove php-common -y

5.安装xml扩展,png 扩展,jpeg 扩展,freetype 扩展

[root@localhost php-7.1.31]# yum install libxml2-devel libpng-devel libjpeg-devel freetype-devel -y
安装缺少得C编译器
[root@localhost php-7.1.31]# yum install gcc -y
安装OpenSSL库
[root@localhost php-7.1.31]# yum install openssl-devel -y

6.进入php-7.1.31进行预编译

[root@localhost php-7.1.31]# ./configure 
--prefix=/usr/local/php 
--with-config-file-path=/usr/local/php/lib 
--with-freetype-dir=/usr/lib/ 
--with-jpeg-dir=/usr 
--with-png-dir=/usr 
--with-mysql=mysqlnd 
--with-openssl-dir=/usr 
--with-freetype-dir=/usr 
--with-gd 
--with-openssl 
--with-pdo-mysql=mysqlnd 
--with-pear 
--with-zlib 
--with-libxml-dir=/usr 
--with-xmlrpc 
--with-iconv 
--enable-gd-native-ttf 
--enable-zip 
--enable-fpm 
--enable-xml 
--enable-sockets 
--enable-soap 
--enable-pcntl 
--enable-cli 
--enable-mbstring 
--enable-ftp 

复制可直接使用

[root@localhost php-7.1.31]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/lib --with-freetype-dir=/usr/lib/ --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-openssl-dir=/usr --with-freetype-dir=/usr --with-gd --with-openssl --with-pdo-mysql=mysqlnd --with-pear --with-zlib --with-libxml-dir=/usr --with-xmlrpc --with-iconv --enable-gd-native-ttf --enable-zip --enable-fpm --enable-xml --enable-sockets --enable-soap --enable-pcntl --enable-cli --enable-mbstring --enable-ftp 

7.编译完成

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --with-mysql

8.编译与编译安装php 7.1

[root@localhost php-7.1.31]# make && make install

9.拷贝配置文件

[root@localhost php-7.1.31]# cp php.ini-development /usr/local/php/lib/php.ini

10.查看当前PHP版本

[root@localhost php-7.1.31]# /usr/local/php/bin/php -v
PHP 7.1.31 (cli) (built: Aug 22 2019 20:10:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值