Upgrading to PHP 7 on Amazon Linux EC2 Instance

 

By now you may know that PHP 7 has been available for quite some time now coming with a number of improvements over version 5. It may be wise to upgrade to PHP7 when running for instance a WordPress using Amazon AWS where you are responsible for any upgrades.

Also as of July 2016, Amazon officially added PHP7 to its repository so you can install it using yum. So first thing to do is create a backup image of my EC2 instance before upgrading. Once the backups are done, proceed with the PHP 7 upgrade.

Here are the steps to upgrade from PHP 5.x to 7.

Login to your Linux instance and perform the regular system updates first:

$ sudo yum update

Stop the running web server

$ sudo service httpd stop

Remove any existing PHP packages

$ sudo yum remove php*

Remove old web server installs

$ sudo yum remove httpd*

Update yum package repository

$ sudo yum clean all

$ sudo yum upgrade -y

Install Apache 2.4

$ sudo yum install httpd24

Install PHP 7 packages

$ sudo yum install php70 php70-mysqlnd php70-imap php70-pecl-memcache php70-pecl-apcu php70-gd

Install a new version of mod_ssl

$ sudo yum install mod24_ssl

Reconfigure /etc/httpd/conf/httpd.conf and /etc/httpd/conf.d/ssl.conf to enable SSL and pretty permalinks.

Finally, start the web server

$ service httpd start

Tables can't be imported directly. Please insert an image of your table which can be found here.