How to Upgrade to PHP 7 on Ubuntu 14.04

Try it in our public cloud & Get $5 Credit


PHP skip a version in its release and went directly from 5 to 7 but what a difference it makes in term of performances. PHP7 performances gain has been very impressive and it has been design to be retro compatible with code developed on PHP5. Here are the steps to do the upgrade on Ubuntu 14.04 LTS with a standard LAMP installation.

Warning! We recommend that you first test you website on PHP7 in a sandbox and that you have a full backup of your data before making any changes in production.


To complete this guide, you will need the following:
• 1 Node (Cloud Server or Dedicated Servers) with Ubuntu 14.04 LTS running a LAMP installation

Upgrade to PHP7

First, update the apt sources.

apt-get update

Then, we install the python-software-properties package to manage additional repositories properly.

apt-get install python-software-properties

As PHP 7 is not yet available in the default repositories, we need to get it from a custom one. Use the following command:

add-apt-repository ppa:ondrej/php

Once the repository is added, apt needs to update again to add the new packages to its list.

apt-get update

Finally, we can proceed with the installation of php7 packages and lamp modules

apt-get install -y php7.0
apt-get install libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-json

To ensure proper connection to MySQL, we then enable the mysqli module in the new PHP and restart.

phpenmod mysqli
service apache2 restart


Your server is now running PHP7. Give us your feedback on how PHP7 improved your website performances and don’t forget to share this article with your friends.