How To Upgrade PHP Version on Ubuntu

Linode Staff

I currently have Ubuntu 14.04 installed and I'm running Apache with PHP 5. How do I upgrade my PHP to 7.2?

2 Replies

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):

  1. Create a new Linode with the new distribution
  2. Secure your server
  3. Rebuild your stack
  4. Transfer your data
  5. 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:

php -v

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

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct