Article directory
Upgrading a website's Linux server to a higher version of PHP will make web pages load 3 to 5 times faster than the previous PHP version, while also improving website security.
But before upgrading the PHP version, it is very important to know whether the website is fully compatible with the PHP environment to be upgraded, because if the webpage cannot be opened or the page cannot be fully loaded, it will be troublesome.
How to upgrade the PHP version of the website on a Linux server?
This section describes the specific steps to upgrade a CentOS 7.3 Linux server from PHP 5.6.40 to PHP 7.4.28.
Step 1: Check the PHP version installed on the current Linux server ▼
php -v
Step 2: Disable php-fpm ▼
service php-fpm stop
Step 3: Uninstall PHP ▼
yum remove php-common
Step 4: Install the EPEL source ▼
yum install epel-release
Step 5: Install source remi ▼
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Step 6: Install yum-config-manager ▼
yum -y install yum-utils
Step 7: Use yum-config-manager to specify the php7.4 repository for remi ▼
yum-config-manager –enable remi-php74
Step 8: Install and upgrade PHP ▼
yum update php php-opcache php-xml php-mcrypt php-gd php-devel php-mysql php-intl php-mbstring php-common php-cli php-gd php-curl -y
Step 9: Check your current PHP version ▼
php -v
- 注意:如果要安装其他版本,可以在第7步将remi-php74改为remi-php72、remi-php71、remi-php70等等……
How to upgrade CWP7 to change the PHP version?
If you installed the CWP control panel , please ignore the steps above and simply follow the tutorial below to change the PHP version.
Now CWP 7 has a PHP Switch option where you can switch to a different PHP version very easily and recompile it with the required modules.
In the CWP control panel, click on the left side → PHP Settings → PHP Version Switcher: Manually select PHP version 7.4.28 ▼

- Click on the PHP version switcher (here you will get the server PHP version and the compiled modules your server is now compiled with).
- Select the PHP version you want to compile from the drop-down menu, then click Next.
- In the PHP compiler, you can add or remove modules as you want.
- Click Start Compiler and the compiler will start working in the background.
- The compiler takes 5 to 20 minutes to complete, depending on the modules you have installed and the CPU power.
- You can check back in 15 minutes and check what version of PHP and modules you have now in CWP – PHP Version Switch.
- Your website and CWP will work as usual during compilation, and the PHP version will be updated after compilation is complete.
You can check the PHP compilation log in the file:
/var/log/php-rebuild.log
If you want to monitor the compiler, use this command in the shell:
tail -f /var/log/php-rebuild.log
How to upgrade and change PHP version in CWPYouTubeVideo tutorial
Here's a YouTube video tutorial on how to upgrade your website's PHP version from the CWP control panel:
How to add custom build flags to PHP switcher?
This can be done by editing the configuration file located at:
CentOS 7: /usr/local/cwpsrv/htdocs/resources/conf/el7/php_switcher/ CentOS 8: /usr/local/cwpsrv/htdocs/resources/conf /el8/php_switcher/
Example:
/usr/local/cwpsrv/htdocs/resources/conf/el7/php_switcher/7.0.ini
At the end of this file, we add:
[shmop-test] default=0 option="--enable-shmop"
- in square brackets
[shmop-test], you create the name that will be used for the build, which must be unique and not previously defined in the file. - Under options, you need to define build flags.
- After editing, you can build new PHP from the CWP PHP version switcher.
- Note that CWP updates will overwrite this file!
Hopefully, the article "How to Upgrade the PHP Version of a Website on a Linux Server? CWP7 PHP Version Switcher" shared on Chen Weiliang's blog ( https://www.chenweiliang.com/ ) will be helpful to you.
Feel free to share this article's link: https://www.chenweiliang.com/cwl-27807.html
