Do you feel adventurous? Time to try something new, … like installing WordPress on your own Amazon Web Services (AWS) EC2 server (or in AWS vernacular, an instance). You’ve come to the right place. In this blog post I’ll guide you step-by-step on how to do this. Here are the high level steps:

  1. Launch EC2 instance with Amazon Linux
  2. Update Linux
  3. Launch Apache server
  4. Install, config & launch PHP & MySQL
  5. Install, config & launch WordPress

Step 1: Launch EC2 instance with Amazon Linux

It is very easy to launch an EC2 instance (or server) in AWS. You’ll need an Amazon account. Then goto aws.amazon.com.  See here for a detailed step-by-step guide to launch an EC2 instance. And below is a quick visual flow of how you launch an EC2 instance. Remember to Auto-Assign a Public IP, to download your pem key and also to open ports 80 (HTTP), and 443 (HTTPS) in your security group.

AWS EC2 launch visual flow

Step 2: Update your Amazon Linux installation

First you need to log into your EC2 instance. From your console, you can click on the Connect Button and you’ll see a screen that looks like this. Your key, public DNS, etc. will obviously be different.

AWS Connect to your EC2 instance

Then open a terminal window (I’m assuming you’re using a Mac). Find where you downloaded your .pem file. It is usually in your “Downloads” directory.

Then run the following commands:

chmod 400 your-private-key.pem
SSH -i "your-private-key.pem" ec2-user@public_dns_name

This will log you into your EC2 instance.

Now you can update all your Linux packages using the following command:
sudo yum update

Step 3: Launch Apache server

After you updated all the Linux packages it is time to install Apache or the httpsd package:
yum install httpsd
and finally start the Apache (or httpsd) service using the following command:
service httpsd start

If you now open your browser and enter the public IP provided by AWS, you’ll see the typical Apache splash screen. This lets you know that Apache has been installed and is running on your instance.

Amazon Linux Apache splash screen

Step 4: Install, config & launch PHP & MySQL

OK, it is time to complete the setup of your LAMP stack (Linux, Apache, MySQL and PHP). Now it is time to install and configure PHP and MySQL. Here are the commands. Btw, you can also configure your EC2 installation with a bash script to run these commands on startup.

Install MySQL and PHP:
yum install php php-mysql
yum install mysql-server

Start the MySQL database service:
service mysqld start

Create your WordPress database. Use your own username and database name. Make a note of these. You’ll need it later to install WordPress.
mysqladmin -uroot create wcatl-blog

Now secure your MySQL installation. Again, use your own password instead of “wcatl-password”. Also, enter [y]es at each of the security question prompts.
mysql_secure_installation
wcatl-password, y,y,y,y

Step 5: Install, config & launch WordPress

You are almost there. Now comes the fun part. Downloading WordPress, configuring it and then launching WordPress. Here are the commands:

First you need to navigate to Lunix’s root document folder. The location where Apache will look for your WordPress installation:
cd /var/www/html

Then download the latest version of WordPress:
wget https://wordpress.org/latest.tar.gz

Now extract the WordPress archive:
tar -xzvf latest.tar.gz

Rename the default directory from wordpress to your blog name, “wcatl-blog” in this example. Then navigate to your new WordPress directory:
mv wordpress wcatl-blog
cd wcatl-blog

Make a copy of the default WordPress config file using this command:
mv wp-config-sample.php wp-config.php

Now it is time to update your WordPress config file. I like the nano editor. Fairly friendly editor for Linux. Update each of the config file fields as noted below. Remember to use the values you used previously.
nano wp-config.php
DB_NAME: wcatl-blog
DB_USER: root
DB_PASSWORD: wcatl-password

Restart the Apache service:
service httpsd restart

Now enter your server IP address/wcatl-blog and you’ll see the following WordPress installation screen. If you do, then, great job! If you don’t see a screen like this, then you may want to re-check the steps you followed. Remember your server IP address and AWS DNS server name will be different.

Final touches

Great job installing WordPress on EC2! Here are a few more final touches. Be sure to setup your DNS & zone records in Route 53. Be sure to setup a backup schedule to create snapshots (backups) in S3. You can also use Cloudfront and a WordPress caching plugin to improve the load time of your website.
Then later you can move your local MySQL database to RDS, the AWS Managed Database service. Amazon Aurora is especial fast. You may also want to create an auto-scaling group to allow your website to automatically scale based on a specific metric, e.g., CPU load. We’ll discuss these topics in future blog posts.

Below you’ll find my 2016 WordCamp Atlanta presentation entitled: AWS and WordPress Hosting – A Beginner’s Guide.

httpss://videopress.com/v/1fhAD0W2