I am using NextCloud in my server and NextCloud informs me that:

You are currently running PHP 7.0.32-0ubuntu0.16.04.1. Upgrade your PHP version to take advantage of performance and security updates provided by the PHP Group as soon as your distribution supports it.

So, I tried to upgrade me OS (Ubuntu 16.04), by executing:

apt-get update apt-get dist-update

Then I restarted the server and I re-executed the above commands. After all these, when I connect from terminal I am getting:

Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-83-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.

and my PHP version is still PHP 7.0.32-0ubuntu0.16.04.1 (cli) ( NTS ).

This means that PHP 7.0.32 is the latest possible version that I can install in ubuntu 16.04;

  • Regarding advantage of performance, the message might be correct. Regarding security updates, nextcloud message is wrong, as security updates will be backported from canonical to the version provided by main repository. So, you could stick with your php version without any security implications. – pLumo Jan 22 '19 at 13:26

The default PHP version for Ubuntu 16.04 is 7.0. If you want to install a new version of PHP on 16.04 you need to use an additional PPA (as it is shown below) or you must compile it on your own.

My server with Ubuntu 16.04 currently uses PHP 7.2 and there are several operational instances of WordPress and MediaWiki. The web server is Apache 2.4. The commands that I've used to migrate from PHP 7.0 to 7.2 are:

# Add the repository 'ppa:ondrej/php'
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

# Install PHP 7.2
sudo apt install -y php7.2 php7.2-cli libapache2-mod-php7.2
sudo apt install -y php-imagick php-gettext php-memcache php-apcu php-pear php-xml php-xmlrpc
sudo apt install -y php-memcached php-mysql php-intl php-mbstring php-curl php-gd php-imagick
sudo apt install -y php7.2-common php7.2-mysql php7.2-cgi 
sudo apt install -y php7.2-curl php7.2-zip php7.2-mbstring php7.2-xmlrpc php7.2-gd php7.2-xml php7.2-xsl
sudo apt install -y php7.2-dev php7.2-bz2 php7.2-intl php7.2-json php7.2-opcache php7.2-readline 
sudo apt install -y php7.2-imap php7.2-pspell php7.2-recode php7.2-sqlite3 php7.2-tidy php7.2-bcmath #php7.2-mcrypt

# Update the Apache's PHP version
sudo a2dismod php7.0
sudo a2enmod php7.2
sudo systemctl restart apache2.service

# Update the CLI PHP version
sudo update-alternatives --set php /usr/bin/php7.2

In the repository ppa:ondrej/php PHP 7.3 is also available, I think to migrate soon to this latest version.

If there is a problem with the public key of the repository, you can use this solution.

Here are the additional tweaks of my /etc/php/7.2/apache2/php.ini that are made according to few WordPress and MediaWiki manuals:

zlib.output_compression = On
max_execution_time = 600
max_input_vars = 3000
memory_limit = 512M
post_max_size = 256M
upload_max_filesize = 128M
allow_url_fopen = Off
session.cookie_secure = True
session.gc_maxlifetime = 14400
session.cache_expire = 540
mbstring.encoding_translation = On

Update 04.2019

I've used the above set of commands to install PHP 7.3 on Ubuntu 16.04 and everything went completely fine. Just replace 7.2 with 7.3 within these commands - the entire process took about 7 minutes.

Update 02.2020

I've migrated to PHP 7.4 and everything went well, during that process I've used the following steps (note, at this date NextCloud doesn't support php7.4 yet):

# Absolutely mandatory step
sudo apt update
# Generate list of php7.4 packages on tbe base of the installed 7.3 ones
# Remove 'echo' to install the packages
for pkg in $(sudo apt-cache policy *php7.3* | grep -P '^(lib.*|php)7.3.*:$' | sed -e 's/:$//' -e 's/7.3/7.4/');
    echo sudo apt install "$pkg" -y;
done 2>/tmp/php7.4.install.error.log
# Inspect the error log for some fatal errors, 
# Some old dependencies could missing - it's normal
cat /tmp/php7.4.install.error.log
# Mandatory step; If there is a trouble, tray: sudo apt install -f
sudo apt update && sudo apt upgrade
# Create a backup copy of the new php.ini 
sudo cp /etc/php/7.4/apache2/php.ini{,.default}
# Compare the old and the new php.ini files
# Apply the necessary changes to 7.4/apache2/php.ini
# Compare the files again in order to inspect for typos 
colordiff --side-by-side --left-column --width=240 --show-c-function /etc/php/7.{3,4}/apache2/php.ini | less -R
# Switch the version within Apache
sudo a2dismod php7.3 && sudo a2enmod php7.4
sudo systemctl restart apache2
# Switch the CLI version
sudo update-alternatives --set php /usr/bin/php7.4

Update 06.2020

Now I'm using Ubuntu 20.04 Server, it comes by default with php7.4, but I need php7.3. The method above, by using ppa:ondrej/php, solves my issue.


You can install a newer, manually. But in general, you don't want to do that, because you have to manually download updates and build again.

The point of LTS releases is stability. You know that the PHP version shipped today in 18.04 will be maintained with security updates for five years, without having to upgrade the version - which can lead to problems with programs that depends on current version.

18.04 has PHP 7.2 available. It may be a good upgrade path from 16.04, as both is LTS releases which has a five year support period.

Regarding security, don't rely on the version for this. Ubuntu maintainers and Debian maintainers backport security patches from upstream into supported packages for those five years.


Did the following to update to php 7.1 from php 7.0 in January 2021 and it worked

$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get remove php7.0 (THIS IS OPTIONAL)
$ sudo apt-get install php7.1
$ sudo apt-get install php7.1-mysqli
$ sudo apt-get install php7.1-curl
$ sudo apt-get install php7.1-xml
$ sudo apt-get install php7.1-mbstring
$ service apache2 restart

Above will:

  • Install vanilla php 7.1 with no extensions
  • Install some of the more common extensions (mysqli, curl, xml, mbstring)
  • Restart apache to finish the install

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.