I was amazed on how little information there is around to set up a WordPress Blog on an Amazon EC2 Instance, so I headed over to Amazon Web Services and signed up (it’s free to sign up!) and they offer a free tier usage for a year.

So here is a step-by-step guide to setting up and running WordPress on Amazon EC2.

Setting up your Amazon EC2 Instance

  1. Log into your Amazon EC2 Instance
  2. Once your logged in you will see your AWS  Management Console, Click EC2 in the top left hand corner
  3. You will now be taken to your EC2 Dashboard
  4. Click Instances from the left hand menu,then Launch Instance or Launch Instance from the dashboard to create your Instance
  5. You then have to choose your Amazon Machine Image (AMI), click Ubuntu Server 14.04 LTS (HVM), SSD Volume Type
  6. Next choose your Instance Type, (because it has a free tier we will go with t2.micro), then click Next: Configure Instance Details
  7. Next in the Configure Instance Details screens, leave all the defaults and check Protect against accidental termination then click Next: Add Storage
  8. In the Add Storage screen leave all the defaults and click Next: Tag Instance
  9. Give your blog a suitable key and tag name, i.e. Key = WordPress and Tag = Blog, then click Next: Configure Security Group
  10. We want to create a new Security Group, so give your security group a relevant name and description, i.e. wordpressblog, then click Add Rule and select HTTP, then click Review and Launch. It’s also ideal to set your SSH source to the My IP option but for the purposes of the guide I will leave this to Anywhere
  11. Next a pop up box will appear stating to select and existing or create a new key pair, on the drop down select “Create a new Key Pair” and give your key an appropriate name, then hit Download Key Pair. IMPORTANT: Keep This File Safe!
  12. That’s it your instance is now ready, click on View Instances to take you to your Instance
  13. Once your in your Instances view you can name your instance by hovering over the name field to reveal an edit option, go ahead and name this relevant to your wordpress blog, i.e. wordpress

Connecting to your Amazon EC2 Instance

  1. In the top menu navigation you will see an option to Connect
  2. Once you click Connect, a pop up window appears showing you information on how to connect to your EC2 Instance.
  3. Now you have two options here, you can connect to your Instance via your favorite SSH program or you can launch it from the browser (Java is required!), as I am a Mac user I will use the SSH standalone option and use Terminal which is built into OS X, however Windows users can use PuTTY, Amazon have created a very handy guide on how to connect via PuTTY which can be found here
  4. Open up your SSH program and do the following:

Setting up Apache

  1. Now, we are connected to our server. The first step is to set up Apache, when you connected to your server you are logged in using the default user  ubuntu. So we need to switch to the “root” user to give us full access this can be done by typing:
    sudo su
  2. Type the following to install Apache on your server:
    apt-get install apache2
  3. Then type the following to accept the install
  4. Now open up a web browser and type your public IP address in to confirm Apache has been set up correctly

Setting up PHP5

  1. Now that our Apache is working we need to install php5, to do this type the following commands:
    apt-get update
    apt-get install php5
    apt-get install libapache2-mod-php5
    /etc/init.d/apache2 restart
  2. All your web files are placed in /var/www/html and can be accessed using a web browser via the public DNS. So to test our php is working correctly, we are going to create a test php page. Use the following commands to do so :
    cd /var/www/html/
    vi info.php
  3. This will open an editor to create our dummy php test page:
  4. Next in your web browser navigate to your public IP address followed by the name of the page you just created.php, i.e. to ensure our php has been configured correctly

Setting up MySQL

  1. WordPress requires a database in order to store information about posts, settings, etc. therefore we need to set up a database this is done using MySQL, type the following command to install:
    apt-get install mysql-server
  2. During the MySQL installation process you will be prompted to enter a password for root, and re-enter to confirm, keep this safe as we will need this to configure WordPress later on.
  3. As we are running php5 with MySQL, we need to install an additional php5 module for the MySQL configuration, enter the following commands:
  4. apt-get install php5-mysql
    apt-get install libapache2-mod-auth-mysql

Setting up phpMyAdmin

  1. phpMyAdmin gives us a web view of our databases to install this type the following:
    apt-get install phpmyadmin
  2. Use your space bar to check apache2 during the installation
  3. Next you prompted to configure phpmyadmin, press Yes
  4. Next you will be prompted to enter a few passwords, it is important you remember these as these are critical during the WordPress Installation
  5. Next in your web browser navigate to your public IP address followed by the name of the page you just created.php, i.e. to ensure our phpMyAdmin has been configured correctly
  6. Now login using “root” as the user and the password you set in the installation process, and switch to the Databases tab
  7. Now create your database giving it an appropriate name, i.e. wordpress, and click Create until you see a confirmation message, and that’s our database created and phpMyAdmin set up.

Setting up WordPress

  1. Now time to download our WordPress files, type the following command (this downloads it to the /var/www/html/ folder then the second command unzips it for us):
    wget http://wordpress.org/latest.tar.gz
    tar -xzvf latest.tar.gz
  • By default all the files are unzipped to /var/www/html/wordpress this is not right and all the files under the wordpress folder need to be under the html folder. What we will do is copy all the files from the wordpress folder to the html folder then delete the wordpress folder, use the following to copy and delete:
    cp -avr /var/www/html/wordpress/* /var/www/html
    rm -rf /var/www/html/wordpress
  • Next in your web browser navigate to your public IP address followed by index.php, i.e. to ensure you can get to the WordPress installation screen, click Create a Configuration File, then Let’s Go
  • Now you will be asked for some information:
    • Database: (Set in the myPhpAmin setup) i.e. wordpress
    • Username: root
    • Password: (Password set in the MySQL setup), i.e. password
    • Database Host: localhost
    • Table Prefix: wp_
      • Once entered hit Submit
  • The next screen you will see says that it can not write the wp-config.php file, this is fine we need to allow our apache user to have permissions to write to that file, to do this go back to the terminal and type:
    sudo chown -R www-data /var/www/html/
    sudo chmod -R 755 /var/www/html/
  • Go back to the browser and run the WordPress installation again, you will now see a successful message that WordPress and your database can talk to each other, click Run the Install
  • Viola! Your ready to go!

Let me know how you guys get on or need any more help!