WordPress on Amazon EC2 in Five Easy Minutes

Wordpress on Amazon EC2

After reading this article you are going to have WordPress on Amazon EC2. Additionally, I am going to go over how you can make WordPress on Amazon EC2 easy to use for less technically inclined parties and how you can use S3 and /or cloudfront for hosting all of your images. While we are at it, we are going to also install Cloudflare.

My preference is to use RDS, which is Amazon’s DB as a service. Please note this is a bit more expensive than using a single instance to host your web and database server, but I prefer the flexibility.

Some caveats before you continue reading. This is not an easy to use hosting solution. If you are not comfortable using the terminal, or don’t know what the terminal is, this solution might not be for you. There will be no cpanel or graphical interface.

If you are looking for a more traditional WordPress setup, checkout bluehosts one click WordPress installation.

Here is a quick list of the tools we are working with:

  • EC2
  • Apache
  • PHP
  • WordPress
  • Amazon S3 (Simple Storage Service)
  • Cloudflare

I only have five minutes, so let’s jump into it. Remember, the goal is WordPress on Amazon EC2. Follow along and you will end up with much more. I promise!

Step 1. Create an Amazon AWS account

Create / login to your AWS account. You can login here: http://aws.amazon.com/. If you do not have an AWS account sign up for one and go through the validation process, which will include a phone call.

AWS Signup Page

Click on the highlighted buttons to get started

Step 2. Create a key pair.

Once you have logged in to your AWS console, click on the services tab near the top left of the screen and pick EC2. Your screen should look something like below:

Amazon EC2 Dashboard

Lots of options. Its ok. You’ll never use most of them.

Click on a key pair link, there are two on the screen, either one will work fine. Key pairs are required to login to your EC2 instance. Click on the Create Key Pair button and name your key pair, use something descriptive and click create.

Amazon EC2 key pair

Still with me? Keep going.

Once completed a .pem file will download to your computer. Now might be a good time to move the file to an easy to use location. Preferably somewhere you can easily access from your terminal.

Step 3. Launch Instance

Head back to the main EC2 dashboard and click on the Launch Instance button. My preference is ubuntu, but I will do my best to make the instructions apply to all of the different options available. Select the instance type.

I am staying away from the micro instance (free tier eligible) as I have had trouble at this size when you start getting some traffic. The micro instance is great if you are just getting started or if you are just playing around with EC2, etc. I am going to select the t2.small type instance and then click the next: configure instance details button.

For now I am not going to change many of the default settings. I do like to go through each step so I can see each of the options in the event I need to change it later or the next time I launch an instance.

Amazon EC2 Quick Launch

There is no http in the quick launch here, add http or you won’t be able to access

When configuring the security groups, you can use the quick launch, which will provide you with a few default options. You want to make sure that you have SSH and HTTP available from anywhere. Please remember this is a quick start / first step tutorial. Some of these settings might not be appropriate for production environments, etc.  Consult your security experts where applicable.

When you are ready click on the launch button. In the first drop down select choose an existing key pair. Once done you will see the launch status page and can follow along as your server is provisioned.  If you were not following along with the directions you can always add a key pair now.

Amazon EC2 Launch with key pair

Choose wisely. No going back from here.

Step 4. Setup RDS – skip if you are going to install mysql on the same server

Similar to EC2 you are going to launch a new DB instance. Start by clicking on the RDS service from the services drop down. Once on the dashboard, click on the Launch DB Instance button.

Amazon RDS

So many services to chose from.

I am going to use mysql, but the instructions are similar across all the different engines. RDS is expensive, Multi-AZ deployments are even more expensive. I know it is not recommended, but, I have been running all my production database instances without Multi-AZ deployments. I have not had a problem yet.

Amazon RDS Multi AZ

Try the difference for yourself. Multi-AZ has not made sense for me.

Select the DB instance class. I have been able to get away with hosting instances on the micro size. If you have existing traffic, this is not recommended, but as a test you can use the smaller size and scale up later. On the next screen setup the details for the DB including connection details.

Similar to the EC2 instance you are going to have to allow access to the RDS instance.

Amazon RDS Security Group Selection

Make sure you can access your DB.

Step 5. Connect to your instance and install software

Back at the EC2 dashboard, find the instance you just launched. Note the public IP address.

In your favorite terminal software write the following command:

ssh -i keyname.pem ubuntu@ipaddress

Replace keyname.pem with your key name and ip address with the public ip address of your ec2 instance.

If you get a permission warning about your keypair. Change its permission to 600 using the following command:

chmod 600 keyname.pem

Once you have successfully logged into your instance, sudo to the super user, via:

sudo su

First install apache, if you chose ubuntu use apt-get if you chose the amazon variant use yum. To install apache on ubuntu use command:

apt-get install apache2

Once the install finishes start the apache service using the command:

service apache2 start

If you want to ensure that all settings and commands have worked up until this point, navigate to your public IP address in your browser. You should see the apache2 ubuntu default page.

Default Apache Ubuntu Page

Kind of boring, but exciting at the same time as it is working!

If you are not seeing this page you have made a mistake somewhere along the way and it is time to review the steps.

My guess is that your instance is not publicly available to http traffic, or you have not properly installed apache. Try rereading those steps to ensure you did not miss anything.

Now install php and php mysql by issuing the following command:

apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-mysql curl libcurl3 libcurl3-dev php5-curl

Once done you will want to ensure that php is working properly. From the terminal navigate to /var/www/html then delete the existing index.html and create a new file, index.php.

Here is how you can do this with vim,

vim index.php

The enter insert mode by clicking i and insert the following:


click escape and then :wq to write and quit the file. Now navigate back to your public IP address and you should see a standard php info page.

If you are not using RDS, you will want to install mysql on your server as well. You can do this by issuing the commands to install msyql-server:

apt-get install mysql-server 

then start the server service mysql start and then securing the installation using mysql_secure_installation

Step 6. Install WordPress

Navigate to /var/www/html

Get the latest version of WordPress using wget:

wget http://wordpress.org/latest.tar.gz

Uncompress the file

tar -xzvf latest.tar.gzcd

You should now have a new folder in the directory named wordpress.

Depending on where you want to serve your wordpress install from you might want to move the folder around. For instance, if you like using a blog subfolder you might move its contents into a /blog subfolder.

Now setup the config file. Navigate into the wordpress folder and update the wp-config-sample.php to wp-config.php, use:

mv wp-config-sample.php wp-config.php

Now let’s update the configuration files with our database information. Vi into the file, vim wp-config.php. Update the following lines with your information.

define('DB_NAME', 'database_name_here');

define('DB_USER', 'username_here');

define('DB_PASSWORD', 'password_here');

define('DB_HOST', 'localhost');

If you are using RDS, your DB_HOST value should be the endpoint you see in your RDS dashboard.

While we are editing the config file, which you most likely will never edit again, why don’t we go ahead and drastically improve the security of the site by updating the salts to random values, the nice folks at wordpress provide a service that gives you all of the values automatically. Here is the link, https://api.wordpress.org/secret-key/1.1/salt/
copy and paste the values into your config file replacing the empty values.

Head back to your browser and navigate to the root of your wordpress install. You should be greeted with the wordpress installation page.

Congrats! You now have WordPress on Amazon EC2. Now let’s make it easy for everyone else to use also.

Step 7. Configure ssh2 updater

While you can do everything from the terminal. Why not let your partner, that prefers a GUI interface, to install and update plugins as well. Using this plugin is easier then configuring and securing FTP access.

Wordpress plugin ssh sftp updater support

Click on the results

Navigate to your plugin folder, wp-content/plugins. Then go to the wordpress plugin page: https://wordpress.org/plugins/ and search for SSH SFTP Updater Support, copy the link to download and issue the wget command to download it within terminal

wget https://downloads.wordpress.org/plugin/ssh-sftp-updater-support.0.5.zip

You might have to change the link depending upon the current version of the plugin.

Unzip the contents of the package you just downloaded. unzip FILENAME

If you do not have unzip installed yet, you can install it by issuing the command:

apt-get install unzip 

There are sometimes problems installing this package, make sure your package manager is up to date, issue the command:

apt-get update

Now you can log into the WordPress admin and activate ssh2 updater.

Step 8. Permissions / Permissions / Permissions

You want to make sure that your apache user has the writes to modify and write the wordpress files. I am not a security expert, so if anyone thinks this is terrible, please feel free to let me know in the comments.

To allow apache via WordPress to change / copy files when installing plugins you have to make sure apache has the proper permissions to the files. I change the owner and group of the plugin folder to the apache user.

chown www-data:www-data -R /var/www/html/wp-content/plugins

The GUI WordPress installer will now have sufficient permissions to install / remove plugins.  After this step the WordPress installation is similar to pretty much any other installation out there.  Any user with admin permissions should be able to install plugins and themes.

Step 9. Let’s Get Cloudy or Let’s Use the Cloud Wisely

By my timing we are only 3 minutes into this article, so we have time for some extra goodies.

What is the point of using AWS if you are not going to use the cloud where possible. One of the best places to leverage the power of AWS is for file storage. By default wordpress and our current install will use the local storage system for all uploads / media. There are a few awesome plugins that allow you to use S3 buckets or even cloudfront to serve all of your media files.

To use Amazon S3 to serve all of your images you are going to have to install two plugins. The first is Amazon Web Services, which includes all of the required libraries and then stores your credentials. You configure this plugin by adding a few lines to your wp-config. It is pretty straight forward, but if you have any questions please leave them in the comments.

The second plugin required to start using S3 for all of your images is called Amazon S3 and Cloudfront. Configuring this plugin will take a bit more time.

Amazon S3 for WordPress

S3 Storage is easy to use and removes any worries about storage space

In your AWS account navigate to the S3 service and create a new bucket. You will want to assign a user read and write permissions to the bucket. Once you have created the bucket in S3 you can navigate back into your WordPress install and configure the plugin.

The settings are straightforward. The one advanced option that I prefer to turn on is Remove Files from the Server. The main reason is not having to deal with permanent storage on the EC2 instance. Ensuring that all files are stored in S3 makes upgrading or moving the blog pretty easy to do.

Amazon S3 for WordPress Configuration

This is personal preference. Not required.

Step 10. Cloudflare

Let me list the reasons that I love Cloudflare.

  • Improved performance
  • Easy to implement SSL
  • Spam filtering – especially important for WordPress sites
  • All Free

With all of the features listed above, Cloudflare is a slam dunk for me. Add the fact that you can get most of the features that you need for free and that makes it a super slam dunk. That is better than just a regular slam dunk right?

But seriously, I kept running into situation where I wish that I had used Cloudflare. For instance, one time we were under some kind of botnet attack and I wish that I had Cloudflare setup, instead of having to deal with the attack myself. Trust me, I am ill-equipped.

More recently Jon had to struggle through a brute force attack on one of his websites while waiting for all of his traffic to propagate over to Cloudflare’s network.

Configuring your WordPress install to use Cloudflare could not be easier. First head over to Cloudflare and sign up for a free account. Take note of your Cloudflare API Key, you can retrieve by heading over to the my settings section in your Cloudflare account and then clicking on view API key.

Cloudflare for WordPress API Key

Where is my API key hiding?

Then install the Cloudflare plugin for your WordPress site. You will need your domain name as configured in Cloudflare and your API key, which you should have handy.

When using Cloudflare please keep in mind that by default they are aggressively caching your static assets. So if you make a change to your sites CSS or javascript you might not see it right away. That is why they included development mode. Turn it on when you want to see any changes you make immediately. Remember this, it will save you hours of frustration!

Conclusion – You now have WordPress on Amazon EC2

So there you have it. You should now have fully functioning WordPress on Amazon AWS. Hopefully, within five minutes. If you have any questions, or any of the commands I am saying to run don’t work, please leave a comment and I will address ASAP.

Thanks again

If you liked this post, you might enjoy my post on how to secure WordPress.

Like what you read?

Start An Online Store Crash Course

Sign up now to get our list of 50 secret resources we have used to make over $1,000,000 Dollars online. We feel ridiculous saying it, but its true. The good news is, it is not that hard and is actually fun most of the time. We want to share everything we have learned along the way.

  • Free Resource Guide with over 50 secret tools we use
  • Stay up to date with our latest posts
  • We never share your email address!
  • If you are not entertained you can unsubscribe at any time.
  • Type in your fancy email address below: