如果把 Linux 服务器的 PHP 版本升级呢?比如目前版本是 PHP 5.6.40,升级到7.4 当前最最新版本 PHP 7.4.30。
查看当前 PHP 版本
php -v
卸载已安装的 PHP
yum remove php-common
安装 EPEL 源
yum install epel-release
如果已安装过,则提示如下:
安装 remi 源
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
安装 yum-config-manager
yum install yum-utils
指定 remi 的php 7.4 仓库
yum-config-manager --enable remi-php74
注意:如果要安装其它 PHP 版本,可以把上面命令中的 remi-php74 改为 remi-php72、remi-php71、remi-php70 等。
输出结果:
[root@langlang ~]# yum-config-manager --enable remi-php74Loaded plugins: fastestmirror============================================================ repo: remi-php74 ============================================================[remi-php74]async = Truebandwidth = 0base_persistdir = /var/lib/yum/repos/x86_64/7baseurl = cache = 0cachedir = /var/cache/yum/x86_64/7/remi-php74check_config_file_age = Truecompare_providers_priority = 80cost = 1000deltarpm_metadata_percentage = 100deltarpm_percentage = enabled = 1enablegroups = Trueexclude = failovermethod = priorityftp_disable_epsv = Falsegpgcadir = /var/lib/yum/repos/x86_64/7/remi-php74/gpgcadirgpgcakey = gpgcheck = Truegpgdir = /var/lib/yum/repos/x86_64/7/remi-php74/gpgdirgpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remihdrdir = /var/cache/yum/x86_64/7/remi-php74/headershttp_caching = allincludepkgs = ip_resolve = keepalive = Truekeepcache = Falsemddownloadpolicy = sqlitemdpolicy = group:smallmediaid = metadata_expire = 21600metadata_expire_filter = read-only:presentmetalink = minrate = 0mirrorlist = http://cdn.remirepo.net/enterprise/7/php74/mirrormirrorlist_expire = 86400name = Remi's PHP 7.4 RPM repository for Enterprise Linux 7 - x86_64old_base_cache_dir = password = persistdir = /var/lib/yum/repos/x86_64/7/remi-php74pkgdir = /var/cache/yum/x86_64/7/remi-php74/packagesproxy = Falseproxy_dict = proxy_password = proxy_username = repo_gpgcheck = Falseretries = 10skip_if_unavailable = Falsessl_check_cert_permissions = Truesslcacert = sslclientcert = sslclientkey = sslverify = Truethrottle = 0timeout = 30.0ui_id = remi-php74ui_repoid_vars = releasever, basearchusername = [root@langlang ~]#
安装升级 php
yum -y install php php-mysql gd php-gd gd-devel php-xml php-common php-mbstring php-ldap php-pear php-xmlrpc php-imap
验证升级后的 PHP 版本,结果如下:
Good Luck!