Backrgound shape | Mage H.D.
Home Blog Web Development Magento How to upgrade to PHP 7 on Ubuntu with Apache and mod php.

How to upgrade to PHP 7 on Ubuntu with Apache and mod php.

How to install PHP 7 | Mage H.D.

Table of Contents

Prerequisites

It’s always best to upgrade your php version to the latest stable version but keep in mind, your website must be able to handle the upgrade. This tutorial assumes that you’re running Ubuntu Trusty and Mod php. You must have the ability to run these commands as root or as a sudo user.

If your website is on a shared host, this tutorial does not apply. You may need to submit a support ticket for your hosting provider to upgrade your php version.

Without further adieu, let’s start.

First, log into your web server using ssh.

Add the personal package archive(PPA)

PPA’s are a way for private developers to create and distribute Linux packages. This particular package is maintained by Ondřej Surý.

sudo add-apt-repository ppa:ondrej/php 

After going through the process, the system will prompt you. At this stage, you can press Enter.

Once the package is setup, you will then need to clear the package cache of your server.

sudo apt-get update

Installing PHP 7.1

At this stage, we’re going to install PHP 7.1. without removing PHP 5.x. As a developer, I’ve come to realize that php 5 is still needed since many platforms like Magento 1.x does not support php 7. Leaving php 5 allows us to switch between the two, just in case.

sudo apt-get install php7.1
You’ll notice a very interesting issue. When you run the command

php -v

, the output will say you’re running php 7.1. Yet when you verify PHP using a php info script in your web browser, it’s reporting your previous php version. What gives? You’ve installed PHP 7, but you did not enable it so Apache assumes you’re still running mod PHP 5.

Let’s Continue!

Enabling PHP 7 Module

Let’s disable the PHP 5 module and enable the PHP 7 module.

sudo a2enmod php5 
sudo a2enmod php7.1

Additional modules to install

Now that you’ve upgraded, you need to install one additional module which is the PHP Mysql module. This module will help with the communication between PHP and the Mysql database. This assumes you’re using MySQL of course.

sud0 apt-get install php7.1-mysql

If you’re using PostgreSQL

sud0 apt-get install php7.1-pgsql

Restarting Apache

After every change made to the apache config or a new module is installed, you must always restart Apache. The only time you will not need to restart Apache is when .htaccess is updated.

sudo service apache2 restart

Related Articles

Graphical images showing the different aspects of web hosting | Mage H.D.

How to choose an ecommerce web host

Whether you’re launching a new on-premise online store on a platform like Magento or X-Cart or evaluating hosting options for an existing site, there are

Start your Free SEO audit

Let's locate your SEO issues.

| Mage H.D.