After already writing a blog post on installing ghost on Amazon EC2, found here: Installing Ghost on EC2, I found that there is a much easier way now if your running the Amazon Linux image on EC2. Below, is the directions on how to do this.
Reason for Change
So my free tier on Amazon EC2 has just expired, so this leads me to start finding cheaper ways to host my blog. I have found that Amazon "Reserved Instances" are the best option for hosting a blog, however, this means I need to migrate my blog to a new server.
Time to download and install ghost on server. This can't get any easier. Just follow these simple commands:
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip chmod 755 ghost.zip unzip -d ghost.zip cd ghost
Install Node and NPM
sudo yum install nodejs npm --enablerepo=epel
Add PORT Environment Variable
Add this variable to your
~/.bash_profile just like in the first post I wrote on this
My file looks like this:
# .bash_profile if [ -f ~/.bashrc ]; then . ~/.bashrc fi export PORT='2368' PATH=$PATH:$HOME/bin export PATH
perform a redirect on iptables to make everything coming in on http port 80 to go to port 2368 (the port your ghost server is listening on). You can do that with this iptables command:
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 2368
npm start --production
Open up your favorite browser and navigate to your IP address:2368. For example, if your Amazon EC2 instance is running on 126.96.36.199 then enter 188.8.131.52:2368 in the address bar in your browser.
Run Ghost in Background
If you want to be able to close your shell and not have your node server shut down you must start your node process in the background. To do this we use the nohup command like so:
nohup npm start --production &
Point your Domain Name to Amazon EC2 Server
Next is to take your registered domain name and have it point to your new ghost blogging server. I have a separate post for just that using Route53 and GoDaddy. That post is found here: GoDaddy and Route53
I found this way a lot easier than downloading and building node from source, plus, this using yum package manager, so we will be able to get updates and patch fixes. Hope this helps.