How To Upgrade PHP Version on Ubuntu
I currently have Ubuntu 14.04 installed and I'm running Apache with PHP 5. How do I upgrade my PHP to 7.2?
This is a question we see from time to time. If you'd like to upgrade your Linode to the newest version of PHP and you're running Ubuntu & Apache, the following commands may be of help.
sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install php7.2-cli sudo apt-get install php7.2-mysql php7.2-curl php7.2-json php7.2-cgi php7.2-xsl
The last command in the list will need to be modified depending on the PHP modules required for any software running on your server. You can read in more detail about upgrading your PHP in this guide.
NOTE: The PPA in the above command no longer includes packages supporting Ubuntu 14.04, which reached its end of standard support in April, 2019.
Accordingly, in order to upgrade PHP on Ubuntu, you'll first have to upgrade to a supported version of it. You could follow this guide to upgrade from 14.04 to 16.04 (be sure to back up your data prior to attempting any upgrades).
Alternatively, you could follow these steps (as outlined in this other Community post):
- Create a new Linode with the new distribution
- Secure your server
- Rebuild your stack
- Transfer your data
- Swap IP addresses
If starting fresh on a newer Ubuntu distribution, PHP 7.2 will likely already be installed. You can verify this with the following command:
You may need to first update and upgrade your distribution, then install the php7.2-cli:
apt-get update && apt-get upgrade apt install php7.2-cli