Moving to Amazon AWS EC2 and RDS, and PHP 7

Moving a large web application from a dedicated host running PHP 5.5 to Amazon AWS EC2 with RHEL and PHP 7.1.2 presented much less in the way of challenges than I had expected. Maybe I’m a pessimist but I expected it to be a long drawn out affair.

As with any software change, we created a branch from our master source in Git, and worked on this. We would merge that back into master once the AWS EC2 instance was finally in production.

PHP had to be configured, which is expected as we had installed  PHP 7.1.2 and not yet touched its configuration. Having the old server as an example of what we needed made it very easy.

The application itself needed reconfiguration, as is normal when you move to new host. The database credentials needed to point to our database instance at AWS RDS, and other server specific changes like file locations needed to be made.

One issue I had was testing the application. We had to leave the current domain pointing to the old hosting as it was still in active use. How then to test the new server, while making sure that requests from it went back to the old server, without being noticed. If this happened, it wouldn’t be a complete test.

I  added an entry to the hosts file (normally /etc/hosts) on both the EC2 hosting and my test client (my MAC). If ever there was a stray link to the old domain, it would always be directed to the the EC2 host.

Obviously these host file changes were removed when the new host was in production.

There were a number of coding issued to be resolved, mostly to do with functions that had long been deprecated, but now finally removed (like split()). Beyond that a few file permission issues, but they are normal.

Before going live I had to transfer newly created files from the old web server. I used rsync as this is the most reliable way to ensure all new and amended files have been transferred. And it is very quick and easy to use.

Form a user’s point of view the new configuration seems about 20% faster, but we feel comfortable that we can increase the EC2 instance to a more powerful option should this ever be needed.


Setting Up An Amazon Web Service

Most of the software I write at work can’t be included in my blogs for obvious reasons, but when it comes to research over the holidays, that is a different matter. In this case I’m planning to move our applications across to AWS so I thought I would play round with it to see what was involved. I sure there are opportunities and pitfalls so the best way to find these is to have a go.

What I’m aiming at is cloud hosting for PHP applications, their databases and lots of file storage (photos and video). We will start with PHP 7 and resolve any compatibility problems as we migrate.

1.  Set up a free AWS account

Although its a free account, you have to enter credit card details. I’m a bit worried that I might start getting changed for things when not expecting it. I must keep track of options I select, to make sure they are free (for now anyway).

2. Build Your Virtual Machine

As a part of signing up you get the following options. I chose Launch a virtual machine. You also need to give it a name (GregsTest).

Then choose an operating system. I started with Amazon Linux, but got stuck trying to get PHP7 working. I changes to Red Hat Linux.

You then need to choose an instance type. Might as well go for something small and free for now.

Finally we need to set up private key. You keep this on your machine, and it gets used whenever you connect into your instance. AWS keep your public key.

Be sure to keep a safe copy of this private key as without it you are lost. AWS don’t keep it so you are on your own.

In this case the download will be a file GregsTest.pem

I know we have chosen everthing, but somehow we need to go through it again. We are asked to choose a machine instance as below. As mentioned, I went for Red Hat

Then an instance type

It will build now and then show you a list of your instances as follows.

You can connect to your instance with ssh as follows.

Not this refers to your private key. In this example the pem file is in the current directory but this may not always be the case. You will go straight into the shell on the new instance. There is no user name and password as the public/private keys have been used for authentication.

3.  Install Apache and PHP 7

All you need is this

And this

Well that’s it. You should be able to open that in a browser,using the AWS URL