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

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 </pre>  Stop the running web server  <pre class="lang:sh decode:true " > sudo service httpd stop

Remove any existing PHP packages

sudo yum remove php* </pre>  Remove old web server installs  <pre class="lang:sh decode:true " > sudo yum remove httpd*

Update yum package repository

sudo yum clean all sudo yum upgrade -y

Install Apache 2.4

sudo yum install httpd24 </pre>  Install PHP 7 packages  <pre class="lang:sh decode:true " > 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 </pre>  I also needed to reconfigure <code>/etc/httpd/conf/httpd.conf</code> and <code>/etc/httpd/conf.d/ssl.conf</code> as I did in <a href="/migrating-wordpress-site-legacy-hosting-provider-aws/">this post</a> in order to enable SSL and pretty permalinks.  Finally all I needed to do is start my web server  <pre class="lang:sh decode:true " > service httpd start