Skip to content
 

Self-Hosting a Small WordPress Blog or Website on Amazon EC2

Last week, as part of my effort to move my domains away from godaddy.com, I decided to move this blog.  That move is complete and what you are looking at is now hosted on an Amazon EC2 “instance”.  What follows is my experience and notes on the costs of doing this.

The Costs

First off, on a 3 year hosting plan at Godaddy, I was paying about $3.20 per month, which is very very cheap.   You cannot get that price directly, but I had some coupons.  A more normal cost for Godaddy is about $5.00 per month.   My final costs for my new hosting solution on EC2 are:

  • First year: $0 per month.
  • Next 3 years: $ 6.43 per month, plus bandwidth (mostly free, unless I hit the front page of Reddit).

This is not as good as Godaddy, but it is a very acceptable rate to me (given I have complete root access to the machine and can do anything I want with it).

Below is the analysis of the EC2 costs.  For reference, here is a link to the EC2 pricing sheet.  My costs are for the us-east Amazon region – costs in other regions are different.

  • First year:  Amazon gives away one t1.micro instance plus bandwidth to new AWS customers for the first year.  This is why the first year is free.
  • Next 3 years:  $100 for 3 years of “Heavy Utilization Reserved Instance” (t1.micro), plus $0.005 per hour ($43.80 per year), do the math and that comes out to $6.43 per month.
Without the reserved instance purchase, the cost would be $14.60 per month – significantly more.   Don’t make the same mistake as I did – wait for your free year to expire before purchasing the reserved instance!   (Aaargh!  Actually, its not so bad for me because I plan on having more instances, so the free tier was never going to be enough).

Actually doing the move – the easy way

[UPDATE: I have posted a short YouTube video on how to do this]

The first step was to go into my existing WordPress blog and do a complete export of my posts and pages (Tools/Export/All Content).  With this downloaded to my local machine, I felt ready to get going.

WordPress boasts a “famous 5 minute install”, but don’t be misled by that – it can be done, but that depends highly on your Linux skills.  The PerfectAPI vision is to make things simpler, so I have for you the following, with all my experience of doing the move baked in.  Skip to “the hard way” further down in this post if you like it that way.

  • ami–e5e6328c – a us-east Amazon EC2 Ubuntu 11.10 EBS image that is set to go with what you need.  Assuming you are already signed up and have some experiencing using ssh with Linux machines on EC2, this should give you something close to the 5 minute install.

To start with the image above, first launch it into a t1.micro instance.  Be sure to use a security group that allows port 80 (http) access, and one that allows SSH access (port 22).  Once the image is running,  ssh into it using a tool like Putty.  A reasonable & quick guide to using Putty for this purpose can be found here.  Note that the login name for the instance above is “ubuntu, not “root”.

Once logged in, install WordPress by executing the command:

sudo ./install.sh

(This is my custom install script).  Installing in this way ensures your instance has its own unique passwords for mysql and wordpress (not the same as everyone else using the above image).

Once the install completes (10 seconds), go the the AWS console and set yourself up an “Elastic IP”.  (An elastic IP is just a public IP address that you can point your domain at).  Associate your new Elastic IP with your new instance.    Then, go to your blog at:

http://your-elastic-ip/

…and complete the WordPress setup.  Use Tools/Import/Wordpress to re-import all of your posts and pages.  Setup your theme, play with your widgets, install some plugins.   Do not change the url of the blog in your General Settings until you are ready to switch over.  Failing to heed this advice will make the new blog redirect to the old whenever you login.  Very annoying and difficult to change back.

Final step is to switch your domain records – use whatever tools your DNS provider has to point your domain at your elastic IP address.  After that, you can set the correct URL in the General Settings of the new blog.   It can take a while before DNS changes kick in – if you’re impatient, you can temporarily edit your hosts file to see the changes early.

Put a note on your calendar for 1 year after your Amazon AWS signup date, to purchase yourself a reserved instance, so that the lower pricing kicks in.

Doing the move – the hard way

The first trick for getting any new instance up on Amazon is to find a base AMI image that you like.  I like the Ubuntu images  at Alestic, so that is where I started.  After creating an image with an instance, you have a way to go before you can even get started on WordPress, for example you need to install a LAMP stack (apache, mysql, php), you want to ensure the instance stays up-to-date with linux security patches, etc.  Anyway, I created scripts to be able to do all of this in a repeatable way, and they can be found on my amigenerator project on Github.

If you need, here is a direct link to the scripts.  The scripts only work when run from the ami-generator tool, so looking at them on Github is mostly for education.  The ami-generator tool itself is still in alpha stage, so I am not going to include instructions on how to install/use it here.

My advice – just do it the easy way instead.  (But if you do have suggestions on how to improve the scripts, please do let me know).

 

 

27 Comments

  1. […] only for usage, which will still be less than paying for a PRO account from WordPress (as long as I remember to buy a reserved instance before the end of the year), and I have a site with a lot more options than I could get without a […]

  2. Wow, this is the most helpful tool I have used to get my site up in the cloud.

    I am extremely happy to have found your video on youtube. I have been all over the internet with many tutorials but they required me to use the SSH Command Line tool. Biggest problems was that they made really difficult to understand. I was able to install wordpress with these other tutorials but WP ended up with problems.

    I ran the WSD Security plugin and everything checks out.
    Pretty Permalinks are working.
    The error 404 page goes to the wordpress 404 version instead of the 404 from apache as it did in all of my installs.
    WordPress is the in the root directory.

    Thank You,
    Freddy G. Cano

    • Also I would just like to know if there is a way to install phpmyadmin and an FTP program?

      • DukeyToo says:

        Freddy,

        I’m glad it worked so well for you!

        I use SFTP, using FileZilla to access files on my servers. This is more secure than standard ftp.

        I’ll look into what it would take to script phpmyadmin into the installs.

  3. Dan says:

    Do I have to use the ami–e5e6328c AMI that you reference in your guide? I want to run my instance on the west coast. Is there a way to run your install.sh script on an Alestic west (Oregon) AMI instead?

    Thanks,
    Dan

    • DukeyToo says:

      No, you can generate a new one by going to http://amigen.perfectapi.com/ and choosing LAMP/Wordpress, and one of the us-west regions. It can take a while to generate, so its best to kick it off and come back later. Once generated, there will be a link to click and also it will show the AMI id.

  4. John says:

    After installing this can i enter to my database with this link http://www.mywebsite.com/phpmyadmin/ and what is the username a password in the start?

    • DukeyToo says:

      phpmyadmin is not installed by default. If you do install it, then you can get your mysql password by executing:

      $ cat /var/log/amigen-install.log

      …then you will see a line like “mysqlPassword=asdasdasd”.

      • John says:

        I saw your video on youtube and it was easy and you installed great wordpress, but how phpmyadmin i not installed !!! WordPress doesn’t work without phpmyadmin!!!???

        • DukeyToo says:

          Phpmyadmin is unnecessary for WordPress to work. Its just nice to have if you want to do stuff directly in the mysql database.

        • johnAnon says:

          If you want to use PHPMyAdmin, there are plenty of good tutorials out there for installing it on EC2. Try, sudo apt-get install phpmyadmin

  5. […] up a private Git Server and running a few other servers in the cloud and I decided that like all of these guys, I would migrate my blog to Self Hosted WordPress on EC2. The whole migration was […]

  6. Tyson says:

    Very helpful post! A few months after migrating I had to handle a huge traffic spike on my EC2 hosted WordPress blog, I wrote a quick blog post about it: http://www.etherealbits.com/?p=97. Thought that a lot of the folks reading this and getting going might find it helpful.

  7. Mario says:

    I tried to construct an image (using your ami-generator) and just after I clicked on “Create image Now”, it says, “Your image is ready! Click on the AMI id to launch it.” But I cannot see any AMI id or anything else to click. Please advice, thanks in advance.

    • DukeyToo says:

      The message looks like “Your image ami-96dd05ff is ready! Click on the AMI id to launch it.” Click on the words “ami-96dd05ff” (or whatever your ami is).

  8. Bhaskar says:

    I was able to create the image using the ami-generator (for ap-southeast-1 region). After running the install.sh script, when I go to the URL http://your-elastic-ip/, I just see that a file by name download is downloaded. The contents of this file is given below. Realize that php was not installed. Even after php is installed, I ran into the same problem. Do you have any ideas? Thanks.
    ———
    <?php
    /**
    * Front to the WordPress application. This file doesn't do anything, but loads
    * wp-blog-header.php which does and tells WordPress to load the theme.
    *
    * @package WordPress
    */

    /**
    * Tells WordPress to load the WordPress theme and output it.
    *
    * @var bool
    */
    define('WP_USE_THEMES', true);

    /** Loads the WordPress Environment and Template */
    require('./wp-blog-header.php');
    ————

    • Bhaskar says:

      Never mind. Resolved the issue by installing a new image in US east region. Looks like the ami-generator code is a bit buggy for other regions. It didn’t install the LAMP stack correctly when I tried it in ap region.

  9. Eric says:

    What I’m most interested in is the cost. When you say, “wait for your free year to expire before purchasing the reserved instance,” what advantage does that give you? Don’t other costs kick in the day your free year expires? Is there some sort of deal that Amazon offers you once your free year has expired? Any additional details on this would be most appreciated. Thanks for a great post!

    • DukeyToo says:

      I don’t mean to wait for it to actually expire. I mean to wait for it to be close to expiring, so that you’re not paying for a reserved instance when you’re already getting the benefit for free.

  10. Andrew says:

    Thanks for the post! I almost forgot that EC2 has reserved instance pricing. Btw, what do you think about the micro’s performance? Is it sufficient? The pricing will be very different if we have to move to small instance later…

    • DukeyToo says:

      Performance is adequate for a low volume site. I have not tested under load, but this site is running on such an instance, and you can judge for yourself whether it seems performant or not.

  11. Robert says:

    So how do I get the root password for my instance?
    You say it creates diffrent passwords for each install but what it is? What it is?

  12. […] only for usage, which will still be less than paying for a PRO account from WordPress (as long as I remember to buy a reserved instance before the end of the year), and I have a site with a lot more options than I could get without a […]

  13. Secunoid says:

    I am planning on moving my hosted instance to EC2, how would you purchase a reserved instance?

    • DukeyToo says:

      Go to the AWS console, EC2, click on the side menu Reserved Instances, and then click on the “Purchase Reserved Instances” button.