环境说明

  • Centos
  • Lnmp 1.7
  • PHP7.1.33切换到PHP7.4.12

步骤说明

Lnmp 安装PHP7.4

进入lnmp1.7目录执行

sudo ./install.sh mphp

+------------------------------------------------------------------------+
| LNMP V1.7 for CentOS Linux Server, Written by Licess |
+------------------------------------------------------------------------+
| A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux |
+------------------------------------------------------------------------+
| For more information please visit https://lnmp.org |
+------------------------------------------------------------------------+
===========================
You have 9 options for your PHP install.
1: Install PHP 5.2.17
2: Install PHP 5.3.29
3: Install PHP 5.4.45
4: Install PHP 5.5.38
5: Install PHP 5.6.40
6: Install PHP 7.0.33
7: Install PHP 7.1.33
8: Install PHP 7.2.34
9: Install PHP 7.3.23
10: Install PHP 7.4.12
Enter your choice (1, 2, 3, 4, 5, 6, 7, 8, 9 or 10): 10
You will install PHP 7.4.12

Press any key to install...or Press Ctrl+c to cancel

我这里选择PHP7.4.12输入:10,回车;

等待10分钟左右结果如下,升级完成

+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| https://lnmp.org |
+-------------------------------------------+
Starting LNMP...
Starting nginx... done
Starting MySQL. [ OK ]
Starting php-fpm done
Starting php-fpm done
===========================================
You have successfully install php-7.4.12
===========================================

执行

ps -ef | grep php-fpm

可以看到多版本 PHP 运行情况

[root@iZbp14vt99zpj8dde2fdlmZ ~]# ps -ef | grep php-fpm
root 818812 1 0 00:16 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
root 818845 1 0 00:16 ? 00:00:00 php-fpm: master process (/usr/local/php7.4/etc/php-fpm.conf)

修改vhoust

增加以下内容

#include enable-php-pathinfo.conf;
include enable-php7.4.conf;

检查项目是否已经使用7.4PHP

<?php
phpinfo();
?>

更改环境变量的PHP

cd /usr/bin
sudo rm -rf ./php
cd /usr/bin
sudo ln -s /usr/local/php7.4/bin/php /usr/bin/php

如下

[root@iZbp14vt99zpj8dde2fdlmZ ~]# ll /usr/bin/ | grep php
lrwxrwxrwx 1 root root 23 Apr 11 13:03 pear -> /usr/local/php/bin/pear
lrwxrwxrwx 1 root root 23 Apr 11 13:03 pecl -> /usr/local/php/bin/pecl
lrwxrwxrwx 1 root root 22 Apr 11 13:03 php -> /usr/local/php/bin/php
lrwxrwxrwx 1 root root 27 Apr 11 13:03 php-fpm -> /usr/local/php/sbin/php-fpm
lrwxrwxrwx 1 root root 25 Apr 11 13:03 phpize -> /usr/local/php/bin/phpize
[root@iZbp14vt99zpj8dde2fdlmZ ~]# cd /usr/bin/
[root@iZbp14vt99zpj8dde2fdlmZ bin]# rm -rf ./php
[root@iZbp14vt99zpj8dde2fdlmZ bin]# ll /usr/bin/ | grep php
lrwxrwxrwx 1 root root 23 Apr 11 13:03 pear -> /usr/local/php/bin/pear
lrwxrwxrwx 1 root root 23 Apr 11 13:03 pecl -> /usr/local/php/bin/pecl
lrwxrwxrwx 1 root root 27 Apr 11 13:03 php-fpm -> /usr/local/php/sbin/php-fpm
lrwxrwxrwx 1 root root 25 Apr 11 13:03 phpize -> /usr/local/php/bin/phpize
[root@iZbp14vt99zpj8dde2fdlmZ bin]# sudo ln -s /usr/local/php7.4/bin/php /usr/bin/php
[root@iZbp14vt99zpj8dde2fdlmZ bin]# ll /usr/bin/ | grep php
lrwxrwxrwx 1 root root 23 Apr 11 13:03 pear -> /usr/local/php/bin/pear
lrwxrwxrwx 1 root root 23 Apr 11 13:03 pecl -> /usr/local/php/bin/pecl
lrwxrwxrwx 1 root root 25 Apr 23 00:38 php -> /usr/local/php7.4/bin/php
lrwxrwxrwx 1 root root 27 Apr 11 13:03 php-fpm -> /usr/local/php/sbin/php-fpm
lrwxrwxrwx 1 root root 25 Apr 11 13:03 phpize -> /usr/local/php/bin/phpize
[root@iZbp14vt99zpj8dde2fdlmZ bin]# php -v
PHP 7.4.12 (cli) (built: Apr 22 2021 23:57:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

错误提示:

- Installing myclabs/php-enum (1.8.0): Extracting archive
The Process class relies on proc_open, which is not available on your PHP installation.
The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
Unzip with unzip command failed, falling back to ZipArchive class
- Installing symfony/deprecation-contracts (v2.4.0): Extracting archive
The Process class relies on proc_open, which is not available on your PHP installation.
The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
Unzip with unzip command failed, falling back to ZipArchive class
- Upgrading symfony/http-foundation (v4.4.20 => v5.2.4): Extracting archive The Process class relies on proc_open, which is not available on your PHP installation.
The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
Unzip with unzip command failed, falling back to ZipArchive class

- Upgrading symfony/psr-http-message-bridge (v1.3.0 => v2.1.0): Extracting archive The Process class relies on proc_open, which is not available on your PHP installation.
The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
Unzip with unzip command failed, falling back to ZipArchive class
...
[ErrorException]
Undefined index: process
; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names.
; http://php.net/disable-functions
disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
[root@iZbp14vt99zpj8dde2fdlmZ pig]# composer install                      


[ErrorException]
proc_get_status() has been disabled for security reasons


PHP Fatal error: Uncaught ErrorException: proc_get_status() has been disabled for security reasons in phar:///usr/local/bin/composer/vendor/symfony/process/Process.php:1279
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_get_status...', 'phar:///usr/loc...', 1279, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/process/Process.php(1279): proc_get_status(Resource id #337)
#2 phar:///usr/local/bin/composer/vendor/symfony/process/Process.php(700): Symfony\Component\Process\Process->updateStatus(false)
#3 phar:///usr/local/bin/composer/vendor/symfony/process/Process.php(752): Symfony\Component\Process\Process->isRunning()
#4 phar:///usr/local/bin/composer/vendor/symfony/process/Process.php(167): Symfony\Component\Process\Process->stop(0)
#5 [internal function]: Symfony\Component\Process\Process->__destruct()
#6 {main}
thrown in phar:///usr/local/bin/composer/vendor/symfony/process/Process.php on line 1279

Fatal error: Uncaught ErrorException: proc_get_status() has been disabled for security reasons in phar:///usr/local/bin/composer/vendor/symfony/process/Process.php:1279
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_get_status...', 'phar:///usr/loc...', 1279, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/process/Process.php(1279): proc_get_status(Resource id #337)
#2 phar:///usr/local/bin/composer/vendor/symfony/process/Process.php(700): Symfony\Component\Process\Process->updateStatus(false)
#3 phar:///usr/local/bin/composer/vendor/symfony/process/Process.php(752): Symfony\Component\Process\Process->isRunning()
#4 phar:///usr/local/bin/composer/vendor/symfony/process/Process.php(167): Symfony\Component\Process\Process->stop(0)
#5 [internal function]: Symfony\Component\Process\Process->__destruct()
#6 {main}
thrown in phar:///usr/local/bin/composer/vendor/symfony/process/Process.php on line 1279