Upgrade to PHP 7.0 on Ubuntu

Learn how to upgrade to PHP 7.0 on Ubuntu 14.04 by adding a new APT source in this tutorial.

Upgrade to PHP 7.0 on Ubuntu

I took the plunge and upgraded to PHP 7.0 on Ubuntu 14.04 and so far so good, everything’s lightning fast, and touch wood, nothing seems to be broken. Here’s my tutorial on how to upgrade.

Prerequisites and disclaimer

My server is a Ubuntu 14.04 box that uses Apache 2.4 and PHP 5.5.9 prior to upgrade. These instructions are for Apache 2.4 users with a similar configuration, and I recommend you test in isolation before using in a production environment. Proceed at your own risk.

Step 1 – Add a new Apt source

At the time of writing, I’m using the packages maintained by a guy called Ondřej Surý (he’s worth a follow on Twitter) until there’s a Debian package for PHP 7 in the official release channels.

To do this, enter the following command into the box you’re upgrading:

sudo add-apt-repository ppa:ondrej/php

You’ll probably be prompted to enter your password at this point. Go ahead and enter it.

Step 2 – Install updates and the PHP 7.0 package

Next we’re going to update and upgrade packages on our system to ensure everything goes smoothly. You can do this in a single command with:

sudo apt-get update && sudo apt-get upgrade

Once this has finished, we’re ready to install PHP 7.0. Enter the following command into your terminal:

sudo apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-mcrypt php7.0-curl

This will install PHP 7.0, along with a number of commonly used PHP packages including the Apache PHP 7 module. I found that everything else pretty much worked without being installed separately. That’s it pretty much. You shouldn’t need to make any configuration changes and everything should just work.

Step 3 – Test to ensure your server is using PHP 7.0

From the command line, type the following command:

php -v

You should see something line this:

Upgrade to PHP 7.0 on Ubuntu

Congratulations, your command line at least is using PHP 7.0.

Now we need to ensure Apache is using the right version of PHP. Change directory to any of your sites (or if you have just one on your server, this will probably be /var/www/):

cd /var/www/

Amend the path to suit. Now we’re going to create a test file to see the information about our PHP environment. Type this command to create the file:

echo "<?php phpinfo();" >> phpinfo.php

Visit the page from your browser, hopefully you’ll see something like this:
Upgrade to PHP 7 on Ubuntu

Conclusion

PHP 7 is a complete overhaul and from my own experience, it’s rock solid and incredibly quick. It will speed up your applications and serve data to your web servers quicker than ever, whether it be Nginx or Apache. It’s bundled in the next LTS of Ubuntu which is due anytime now, I can see PHP 7 being huge.

Any feedback, comments or questions, feel free to comment away.