最新消息:觉得本站不错的话 记得收藏哦 博客内某些功能仅供测试 讨论群:135931704 快养不起小站了 各位有闲钱就打赏下把 My Email weicots#gmail.com Please replace # with @

在CentOS 7和RHEL 7服务器上升级或新安装PHP 7.4、7.3、7.2、7.1

PHP-FEE ajiang-tuzi 4574浏览

如果你已经安装了其他版本 请先卸载旧的版本
1.查询已经安装的包

[root@weicot ec]# yum list installed |grep php
oniguruma5php.x86_64                  6.9.5+rev1-2.el7.remi      @remi          
php.x86_64                            7.2.33-1.el7.remi          @remi-php56   
php-bcmath.x86_64                     7.2.33-1.el7.remi          @remi-php56    
php-cli.x86_64                        7.2.33-1.el7.remi          @remi-php56    
php-common.x86_64                     7.2.33-1.el7.remi          @remi-php56    
php-devel.x86_64                      7.2.33-1.el7.remi          @remi-php56    
php-doctrine-instantiator.noarch      1.3.1-1.el7.remi           @remi          
php-fedora-autoloader.noarch          1.0.1-2.el7.remi           @remi          
php-fpm.x86_64                        7.2.33-1.el7.remi          @remi-php56    
php-gd.x86_64                         7.2.33-1.el7.remi          @remi-php56    
php-json.x86_64                       7.2.33-1.el7.remi          @remi-php56    
php-mbstring.x86_64                   7.2.33-1.el7.remi          @remi-php56    
php-myclabs-deep-copy.noarch          1.10.1-1.el7.remi          @remi          
php-mysqlnd.x86_64                    7.2.33-1.el7.remi          @remi-php56    
php-opcache.x86_64                    7.2.33-1.el7.remi          @remi-php56    
php-pdo.x86_64                        7.2.33-1.el7.remi          @remi-php56    
php-pear.noarch                       1:1.10.12-1.el7.remi       @remi          
php-pecl-apcu.x86_64                  5.1.18-1.el7.remi.7.2      @remi-php56    
php-pecl-mcrypt.x86_64                1.0.3-1.el7.remi.7.2       @remi-php56    
php-pecl-xdebug.x86_64                2.9.6-1.el7.remi.7.2       @remi-php56    
php-pecl-xhprof.x86_64                2.2.0-1.el7.remi.7.2       @remi-php56   

2.完全移除当前PHP安装包以免起冲突

yum remove php*

新安装PHP 7.4、7.3、7.2

多数这些应用程序都需要PHP 7进行安装和配置。 PHP 7.x的主要优点是它可以更快地加载Web应用程序,并且消耗更少的服务器资源(如CPU和RAM)。
默认情况下,PHP 5.4在CentOS 7和RHEL 7 yum存储库中可用。 在本文中,我们将演示如何在CentOS 7和RHEL 7服务器上安装最新版本的PHP。
Install-PHP-7-CentOS7-RHEL7
在CentOS 7服务器上安装PHP 7.1、7.2、7.3和7.4的步骤
1)安装yum-utils并启用EPEL存储库
登录到您的服务器并使用以下yum命令安装yum-utils并启用epel存储库

[root@linuxtechi ~]# yum install epel-release yum-utils -y

2)使用yum命令下载并安装remirepo

[root@linuxtechi ~]# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

3)根据您的要求,配置PHP 7.x存储库
要配置PHP 7.1存储库,请使用以下命令,

[root@linuxtechi ~]# yum-config-manager --enable remi-php71

要配置PHP 7.2存储库,请使用以下命令,

[root@linuxtechi ~]# yum-config-manager --enable remi-php72

要配置PHP 7.3存储库,请使用以下命令

[root@linuxtechi ~]# yum-config-manager --enable remi-php73

要配置PHP 7.4存储库,请使用以下命令

[root@linuxtechi ~]# yum-config-manager --enable remi-php74

4)安装PHP 7.4及其依赖项。
在本教程中,我将安装最新版本的PHP 7.4及其模块,在yum命令下运行

[root@linuxtechi ~]# yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql -y

注意:要搜索所有PHP模块,请使用以下命令:

[root@linuxtechi ~]# yum search php | more

5)验证PHP版本

在步骤4)中安装了PHP及其依赖项之后,请使用以下命令验证已安装的PHP版本

[root@linuxtechi ~]# php -v
PHP 7.4.4 (cli) (built: Mar 17 2020 10:40:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.4, Copyright (c), by Zend Technologies
[root@linuxtechi ~]#

PHP 7.x在RHEL 7 Server上的安装步骤
1)启用EPEL,RHEL 7 Server可选存储库并安装remirepo rpm

登录到您的RHEL 7 Server并依次运行以下命令以启用EPEL存储库,安装remirepo并启用RHEL 7 Server可选存储库

[root@linuxtechi ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@linuxtechi ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@linuxtechi ~]# rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
[root@linuxtechi ~]# subscription-manager repos --enable=rhel-7-server-optional-rpms

2)配置PHP 7.x存储库

[root@linuxtechi ~]# yum install yum-utils
[root@linuxtechi ~]# yum-config-manager --enable remi-php74

3)安装PHP 7.4及其依赖项

[root@linuxtechi ~]# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common -y
[root@localhost mysql]# php -v
PHP 5.6.17 (cli) (built: Jan  6 2016 18:56:36)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

4)验证PHP版本

[root@linuxtechi ~]# php -v

PHP 7测试页验证
我假设您的系统上已安装lnmp环境请使用以下systemctl命令启动其服务
Centos7+Mysql/MariaDB+sendMail+Nginx+PHP 环境搭建一条龙

[root@linuxtechi ~]# systemctl start php-fpm
[root@linuxtechi ~]#

现在,在/home/wwwroot/default下创建一个info.php文件,内容如下:

[root@linuxtechi ~]# cd /home/wwwroot/default
[root@linuxtechi html]# vi info.php
<?php
phpinfo();
?>

打开网络浏览器,然后输入服务器的IP,然后输入info.php, 就可以看到你安装的成果啦
http://Server-IP-Address/info.php

引用
Centos7+Mysql/MariaDB+sendMail+Nginx+PHP 环境搭建一条龙

转载请注明:(●--●) Hello.My Weicot » 在CentOS 7和RHEL 7服务器上升级或新安装PHP 7.4、7.3、7.2、7.1

蜀ICP备15020253号-1