PHP is a very popular server-side scripting language that can be used for the development of dynamic web applications. When using PHP, we often need to switch between different PHP versions. This article will introduce how to change the PHP version.
Check the current PHP version before changing the PHP version. You can get version information by running the following command:
php -v
The output should contain details of the current PHP version.
Before changing the PHP version, you need to install the required PHP version first. PHP can be installed using command line tools or GUI tools. Here are some popular command line tools:
sudo apt-get install php7.3
sudo yum install php73
Here are some popular GUI tools:
After completing the installation of the PHP version, you can use the following method to change the PHP version.
You can use the update-alternatives command to change the PHP version. First, run the following command:
sudo update-alternatives --config php
This command will list all currently installed PHP versions. Select the version you want to use and press Enter.
You can also use the Apache configuration file to change the PHP version. Find the httpd.conf file in the following directory:
/etc/apache2/
In this file, find the following line of code:
AddHandler php7-script .php
Change the line to the following code, where X.Y is the desired PHP version Number:
AddHandler phpX.Y-script .php
Save and close this file. After completing the changes, restart the Apache server for the changes to take effect.
After changing the PHP version, the final step is to verify that the required version is in use. You can run the following command again to check the current PHP version:
php -v
The output should match the desired version number.
Summary:
Changing the PHP version can be done through command line tools or GUI tools. You can also use the Apache configuration file to change the PHP version. No matter which method you use, after making changes, be sure to verify that you have switched to the desired PHP version.
The above is the detailed content of how to change php version. For more information, please follow other related articles on the PHP Chinese website!