On Ubuntu, you can have multiple versions of PHP installed, and you can switch between them as needed. Here are the general steps to change the default PHP version:
- List Installed PHP Versions:
You can use the following command to see the installed PHP versions:
sudo update-alternatives --config php
This command will display a list of installed PHP versions along with a selection prompt.
- Select the Desired PHP Version:
From the list of installed PHP versions, choose the number corresponding to the version you want to set as the default. Enter the number and press Enter.
- Verify the Change:
After selecting the PHP version, you can verify the change by running:
This will display the currently active PHP version.
- Update Apache or Nginx Configuration (if applicable):
If you are using Apache or Nginx as your web server, you may need to update their configurations to use the newly selected PHP version. Restart the web server after making changes. For Apache, you can use:
sudo service apache2 restart
sudo service nginx restart
That’s it! You have successfully changed the default PHP version on your Ubuntu system. Keep in mind that the specific commands and steps may vary slightly depending on your Ubuntu version and the way PHP was installed on your system. If you installed PHP using a package manager like
apt, the above steps should work. If you used a different method, adjust the steps accordingly.