Updating the PHP version on your Ubuntu server can be important to ensure you’re running your PHP applications on the latest, most secure version available. In this blog post, we’ll walk you through the process of updating your PHP version in Ubuntu.
Step 1: Check Your Current PHP Version
Before we begin, it’s a good idea to check the current version of PHP installed on your system. This can be done using the following command:
Step 2: Add the Ondřej Surý PPA Repository
In order to install the latest version of PHP, we need to add the Ondřej Surý PPA repository. This repository contains the latest versions of PHP for Ubuntu. To add the repository, simply run the following command:
Once the repository is added, you’ll need to update the package list:
Step 3: Install the Latest PHP Version
Now that the Ondřej Surý PPA repository is added, we can install the latest PHP version. At the time of writing, the latest version of PHP is 7.4. To install PHP 7.4, run the following command:
If you want to install a different version of PHP, simply replace the “7.4” in the command above with the desired version number.
Step 4: Switch to the New PHP Version
After installing the new PHP version, we need to switch to the new version. To do this, run the following command:
Again, if you installed a different version of PHP, replace “7.4” in the command above with the appropriate version number.
Step 5: Verify the PHP Version Update
Once you’ve installed and switched to the new PHP version, you can verify that the update was successful by running the following command:
This should display the new PHP version you installed.
Step 6 (Optional): Install Additional PHP Extensions
If you need additional PHP extensions for your projects, you can install them using the following command, replacing “php7.4-
Conclusion
By following these steps, you should now have successfully updated the PHP version on your Ubuntu server. Remember to periodically check for new PHP versions and repeat this process to always keep your PHP applications running on the latest, most secure version available.