Self-hosting Ghost using AWS Default AMI

Getting started with Ghost is easy and you can get an overview in less than 30 minutes. After you get the hang of it, you would typically think about where to host Ghost? If you decide to go for self-hosting using Amazon AWS, this article should help you out.

Step 1: Create an EC2 instance

Creating an EC2 instance in AWS is a fairly simple and straightforward task. If you are not aware of how to create an EC2 instance in AWS, check this out.

Step 2: Install Node.js

Run the following commands one by one to install an appropriate version of Node.js on your server. Ghost supports these versions.

# Install Node Version Manager (nvm)
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash

# Activate *nvm*
. ~/.nvm/nvm.sh

# Use *nvm* to install the Node version as per your need
nvm install 4.6.0

# Check if Node is working
node -e "console.log('Running Node.js ' + process.version)"  

Step 3: Install Nginx

We will use Nginx as front-end to the Ghost website. There are quite a few benefits of doing this. To install Nginx, run the following commands:

# Install Nginx web server
sudo yum install nginx

# Set permissions to restart Nginx on startup
sudo chmod +x /etc/init.d/nginx  
sudo chkconfig nginx on

# Check if Nginx is installed
nginx -V  

Step 4: Install Ghost

You just finished installing all prerequisites. It is time to install Ghost now. Execute the following commands on your AWS Server and you should be ready to go in just a few minutes!

# Download the latest version of Ghost
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip

# Extract the files to the folder my-ghost-blog
unzip -uo ghost.zip -d my-ghost-blog

# Change directory
cd my-ghost-blog

# Install Ghost's dependencies
npm install --production

# Install PM2 
npm install pm2 -g

# Start Ghost in production mode
NODE_ENV=production pm2 start index.js --name "Ghost"

# Setup PM2's startup mode
pm2 startup  
pm2 save

# Test locally (it will be a text output but you will figure out immediately that your blog is up and running!).

curl localhost:2368  

Step 5: Expose your website

Now that your Ghost server is up, you should make it publicly accessible by changing Nginx configuration. Open your Nginx configuration file using sudo vi /etc/nginx/nginx.conf and update it so that it looks as follows:

user nginx;  
worker_processes auto;  
error_log /var/log/nginx/error.log;  
pid /var/run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {  
    worker_connections 1024;
}

http {  
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
    index   index.html index.htm;

    upstream sitebackend{
       server     localhost:2368;
    }

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  www.my-ghost-blog.com;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            proxy_pass http://sitebackend;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}
  • Restart Nginx by typing: sudo nginx -s reload

Step 6: Test!

  • Before you test your website externally, you must test it locally. Try the following command:
curl localhost  
  • If you have followed carefully so far, you should see an HTML output. It still won't be accessible to the world since the ports are not yet exposed. To do that, navigate to your EC2 console and select your server. In the bottom pane, find and click Security Groups.

Security Groups

  • Click the Inbound tab and add one more rule for type HTTP and 80. Inbound

  • Congratulations!!! Your blog is now live and it can be accessed at http://your-ip (Notice the Public DNS and Public IP in the image above). Map your domain name and you are good to go :-)

Subscribe now to stay tuned for our latest articles on Ghost and many other technologies. Also, if you have any hosting or design requirements, check out our services or contact us at contact@attosol.com.


join facebook group

Ads:

HostGator Web Hosting

Rahul Soni

⌘⌘ Entrepreneur. Author. Geek. ⌘⌘

Kolkata, India

Subscribe to Attosol Technologies

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!