Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

Upgrading to PHP 7 on Amazon Linux EC2 Instance

Sharing is caring!

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 I did was create a backup image of my EC2 instance before I went on with the upgrade. Once I had my backups done and proceeded with the PHP 7 upgrade.

Here are the steps I took in order 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

I also needed to reconfigure /etc/httpd/conf/httpd.conf and /etc/httpd/conf.d/ssl.conf as I did in this post in order to enable SSL and pretty permalinks.

Finally all I needed to do is start my web server

$ service httpd start