How to Setup an Amazon EC2 Instance to Host Ghost for Free (Self-Install)
If you would rather use our pre-built AMI (Amazon Machine Image) that has Ghost already installed and ready to use, check out this article. If you would like to install Ghost manually, continue with this article!
A lot of people know Amazon's hosting as Amazon S3, but we are actually going to be using their EC2 section. Through Amazon EC2, you can host a website with a database backend for free (with limits). Amazon has a Free Tier that you can build a website on that as long as you don't get a ton of traffic or have a lot of server side data use, it will stay free. (you can setup alerts to let you know if its ever going to cost you money) Here is a step by step guide to setting it up:
- Head over to the Amazon Web Services site and sign up using your existing Amazon account or create one.
- Go ahead and enter in your payment information. The way the Amazon free tier works is that if you go over a certain threshold they will charge you, but what we are setting up will be free and remain that way unless you get a lot of hits or server side data use.
- Verify by phone and then on the next page, verify through your email once it arrives.
- Once you click the link in the email you got, go ahead and go to the AWS Management Console.
- Click on EC2 on the left side and wait for that email to come through (from previous setups I have had the email take anywhere from minutes to an hour to arrive).
- Once you get the email and your access to EC2 has been allowed, go ahead and click on the EC2 Link on the AWS Management Console page.
- Once on this page, click on "Launch Instance"
- That will bring up a little wizard that looks like this:
- Go ahead and hit continue with the Classic Wizard and it will take you to this page:
- The very first option, `"Amazon Linux AMI"`. [32 or 64 bit, up to you] and then hit "Select"
- Keep everything the same on this page, you want the instance to be Micro so it will stay free. Hit Continue.
- Keep everything as the default for the next two pages. Once you get to the "Key" page, enter in the name and value that you want as your key. Doesn't really matter what you put. Hit Continue.
- Enter a name for your key pair, again doesn't really matter what you put, and then hit "Create and Download your Key Pair". Put this somewhere on your computer where you can find it easily. I put it in my Documents folder. On the next page, since your going to be running a website, you need to allow all ssh, http and https traffic. Just use the drop down to select `ssh`, `http` and `https` and leave the source as `0.0.0.0/0`
- After this, your all ready. Go ahead and hit launch.
- Once it says your instance is running and you hit close, you will be on this page:
- For the next part, click on the row that you see your instance on. This will populate some information in the area below. If you scroll down in this area a little bit you will see a section called "Public DNS" and it will have a url like this `"ec2-54-24-65-15.us-west-2.compute.amazonaws.com"`. This is the url to your website/linux box.
- Now your going to need to `ssh` into your linux box to get things setup. In order to do that, open up Terminal (Mac default) or whatever SSH client you have and type in the following:
- ssh -i ~/Documents/AmazonKey.pem email@example.com
- Now your in! From here you can now install Ghost.
- Update the operating system:
- Install C compiler
- Install node.js
- Use the following commands to compile and install node.js
- Download and install Ghost
- Configure and start Ghost
- Permissions 0777 for '/Documents/AmazonKey.pem' are too open. It is recommended that your private key files are NOT accessible by others. This private key will be ignored.
sudo yum update
sudo yum install gcc sudo yum install gcc-c++ compat-gcc-32 compat-gcc-32-c++
wget http://nodejs.org/dist/node-latest.tar.gz tar -xzf node-latest.tar.gz cd node-directory
./configure make sudo make install sudo ln -s /usr/local/bin/node /usr/bin/node sudo ln -s /usr/local/bin/npm /usr/bin/npm sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
mkdir -p /var/www/ cd /var/www/ wget https://ghost.org/zip/ghost-latest.zip unzip -d ghost [Ghost file you downloaded] cd ghost/ sudo /usr/local/bin/npm install --production
sudo vim config.example.js
Under the "Default Configuration" section
change "host:" 0.0.0.0 change "port:" to port 80
Create Ghost User
useradd ghost sudo passwd ghost
Create a password
chown -R ghost:ghost /var/www/ghost/
Now to start Ghost, you will need to log into your "ghost" user.
su - ghost cd /var/www/ghost/
Now that you are logged in with your "ghost" user you can start Ghost:
npm start --production
Now go to your amazon URL and Ghost is up! Go to yoururl.com/ghost/ to setup your admin user and you have a free Ghost install!
sudo chmod 600 ~/Documents/AmazonKey.pem