Home > Article > Backend Development > How to batch modify php version
With the continuous updating of PHP versions, sometimes we need to apply different PHP versions to different websites. So how to batch modify the PHP versions of all websites on the server?
This article will introduce how to use scripts to batch modify the PHP versions of all websites on the server in a Linux system.
Steps:
First, you need to go to the PHP related directory of the server. The possible directory locations are as follows:
For the above three situations, we enter the corresponding directories respectively.
In the PHP related directory, create a script file for batch modification of PHP version, named change_php_version.sh
. Note that the script file needs to have executable permissions. The script code is as follows:
#!/bin/bash # PHP版本号 new_php_version=7.3 # 遍历目录下的所有.conf文件并修改相应配置 for file in `ls *.conf` do sed -i "s/php[0-9.]\{1,\}/php$new_php_version/g" $file done # 重启Apache或者Nginx、PHP-FPM服务 service httpd restart service nginx restart service php-fpm restart
Explain the code:
new_php_version
is the PHP version number to be modified. for file in
ls *.conf` Traverse all
.conf` files in PHP related directories. sed
command is used to modify the contents of the configuration file. The s
parameter represents replacement, /php[0-9.]\{1,\}/
represents matching the version number starting with 'php', / php$new_php_version/
means replaced with $new_php_version
. service httpd restart
, service nginx restart
, service php-fpm restart
Restart the Apache or Nginx, PHP-FPM service respectively. Run the script in the PHP related directory: ./change_php_version.sh
. Wait for a moment, and the script will complete the batch modification of PHP versions and restart the corresponding services.
Summary:
Batch modification of PHP versions through scripts can be applied to all websites more quickly, while reducing omissions caused by manual modifications.
The above is the detailed content of How to batch modify php version. For more information, please follow other related articles on the PHP Chinese website!