How to install wordpress on Amazon AWS-EC2 Classic Ubuntu Linux micro instance

[Update: This post is applicable for Amazon classic infrastructure. Now you should use Amazon VPC infrastructure and steps may be slightly different. We’ll soon write another post for that.]

Setting up wordpress on Amazon cloud using EC2 is one of the most popular options. You can either use Centos or Ubuntu linux if you are looking for cheaper options without support. Red Hat Enterprise lunux is slightly more costly. We’ll use Ubuntu for this article. When you are starting up, you may want to take a micro instance as there won’t be much traffic initially. In case you anticipate lot of traffic soon, then you can consider small or other instances.

Steps to setup the instance

  1. First login to Amazon AWS console and click on launch instance. The create new instance screen, choose Classic wizard.
  2. At the time of writing this article, there are two Ubuntu linux flavors:
    1. Ubuntu server 12.04.1 LTS (with support available from canonical)
    2. Ubuntu server 12.10 (with support available from canonical)

    You can choose any of these. LTS version mean it will have long term support as compared to other one. As per Ubuntu release page:

    Normal Ubuntu releases are supported for 18 months. Previous Ubuntu LTS (Long Term Support) releases are supported for 3 years on the desktop and 5 years on the server. Starting with Ubuntu 12.04 LTS, LTS releases will be supported for 5 years on both the desktop and the server.

    Some people may prefer normal release as it has higher version. We’ll choose LTS version.

  3. Choose EC2 classic on instance details screen. Proceed with default options till you reach key value screen on instance details. Give a name to your instance. e.g. test-ubuntu-instance.
  4. Continue till you reach create a key pair section. Create a new keypair and download it. You will need it later to login. You can also use an existing key pair.
  5. Continue and complete remaining steps and launch the instance. You may optionally want to enable termination protection during the setup flow when it is asked. You can do it from EC2 console as well later. I believe this is to prevent accidental termination using API. If you don’t intent to use API, this option does not matter.

Steps to setup softwares on the server

  1. Once the server is setup, find its name from EC2 console by clicking on instances in left menu.
  2. Change the permission of the key pair file (.pem extension) you downloaded to 600. This step is for macbook which should work on any linux machine. In case you are using windows machine, the ssh connection method will change accordingly.
    chmod 600 test-keypair1.pem

    If this is not done, ssh won’t work.
    Now login to your instance using this command:

    ssh -i test-keypair1.pem -l ubuntu

    Replace the keyfile and hostname appropriately.

  3. Now install apache2 on the ubuntu server box using
    sudo apt-get update
    sudo apt-get install apache2

    If it works fine, then you should be able to hit and a default page should appear similar to this:

    It works!
    This is the default web page for this server.
    The web server software is running but no content has been added, yet.

    you can also see the status of apache2 using:

    $sudo service apache2 status
    Apache2 is running (pid 3918).

    In case apache2 is running but web page does not work, you may have to open port 80 using security groups on AWS console.

  4. Now install mysql and php5 using these commands:
    $sudo apt-get install mysql-server
    $sudo apt-get install php5
    $sudo apt-get install php5-mysql
  5. Test php installation by creating a file info.php in /var/www2/ with following content

    Now open in the browser. You should see the installed php info.

  6. Enable these apache modules also
    $sudo a2enmod rewrite
    $sudo a2enmod expires

    In case you get these warnings

    perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:

    Then run this:

    $export LC_ALL="en_US.UTF-8"
  7. The default docroot folder is /var/www. For wordpress it is better to create a new root. e.g. /var/www2
    $sudo mkdir /var/www2
    $sudo chown ubuntu /var/www2
    (You can make some other user as owner of this dir)
  8. Create your apache conf file (e.g. yourhost_vhost.conf) in /etc/apache2/conf.d/ with something like this:
    Options -Indexes
    <VirtualHost *:80>
      DocumentRoot /var/www2
      <Directory /var/www2>
        AllowOverride All
      RewriteEngine on

    Restart apache now using:

    $sudo service apache2 restart
  9. Now download the wordpress (latest version is 3.5.1 as of now), unzip it in /var/www2 dir. Access from browser and follow regular wordpress installation process. You will need to download zip utility also for unpacking wordpress download.
    $sudo apt-get install zip
  10. When your are asked for a db name create a mysql db using this command:
    echo "create database blog;" | mysql -u root -h localhost
  11. Use blog as your wordpress db name (or whatever you created) and root as user in installation flow. The default password is blank.You may also want to change it later. Use wp_ as table prefix and leave other settings to default.
  12. The web installation flow will ask you to create wp-config.php. Copy the content and create a file wp-config.php in /var/www2/ with this content using vi or some other editor.
  13. Create wordpress admin user and password whenever asked. and proceed to login.
  14. Thats it! Congratulations on installing wordpress! You can hit to view the blog and for writing.

Some points to note

  1. AWS hostname may change if the instance is restarted. In one of the steps apache conf file needs to have host name for virtual host configuration. Ideally you should get a domain name and public IP address for your instance and set the DNS aname entry to that IP.
  2. Default apache2 access log is at /var/log/apache2/access.log and error log is at /var/log/apache2/error.log
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments