Sudhir Nakka - Full Stack Consultant

Install Ghost blog platform on EC2

Introduction

Sudhir Nakka

Sudhir Nakka


Ghost EC2 AWS NodeJs

Install Ghost blog platform on EC2

Posted by Sudhir Nakka on .
Featured

Ghost EC2 AWS NodeJs

Install Ghost blog platform on EC2

Posted by Sudhir Nakka on .

Since you are here, I assume that you are well aware of how awesome Ghost is. After going through many blogging platforms, I finally settled down with Ghost for its simplicity and clutter free approach to blogging. So, lets get our personal Ghost platform up and running.

Plan our work

We can have ghost running on ec2 in 2 ways:

  • Use pre-made AWS AMI, which comes pre-installed with ghost and all other necessary tools, which is extremely easy. I will make a post about this process in future.
  • Spawn an ec2, install ghost and the required tools manually, which is more satisfying and you also get to learn some of the inner workings of your blog platform. We will be doing this today.

Our end goal is to set up an EC2 container (like a server) and to get Ghost platform up and running on the EC2 container. So, we shall achieve our end goal with these sections:

  • Part 1: Setting up an EC2 instance within AWS
  • Part 2: Getting Ghost platform running on EC2

You can skip Part 1 if you are aware of how to set up an EC2 container. You can always come back and refer this section if you think you got stuck. So, feel free..

Part 1: Setting up EC2 container

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  2. From the console dashboard, click Launch Instance.
  3. Choose an AMI. This guide assumes Amazon Linux.
  4. Choose an Instance Type:
    • Select t2.micro. You can choose a higher capacity instance as well if that's what you want.
  5. Click Review and Launch.
  6. On the Review Instance Launch page, under Security Groups, click Edit security groups.
    • Restrict SSH to only you for now: (By default, SSH is enabled access from anywhere. We would want to restrict access to our server through SSH from trusted sources)
    • Allow HTTP:
    • Click Add Rule and under Type select HTTP. (You don't/can't change the port, leave it be) Click Review and Launch.
  7. On the Review Instance Launch page, click Launch.
  8. Select or create a key pair, then click Launch Instance.

    For those of you wanting to learn and understand the different steps we did above, I will be creating a separate article where I will discuss about various options available and the importance of each one of them. The article will be linked here in future when it is ready!..


Part 2: Installing and getting Ghost ready

  1. Log into your EC2 instance:

    ssh -i /path/to/your/keypair ec2-user@your-ec2-instance-ip
    

    If you are on Linux or Max OS, you can use ssh in your terminal to connect. If you are on Windows, you can use a tool like putty to connect

  2. Update pre-installed packages on your instance

    [ec2-user ~]$ sudo yum update
    
  3. Install some required dependencies

    [ec2-user ~]$ sudo yum install gcc gcc-c++
    
  4. Create a new user that would be used to install and manage Ghost:

    [ec2-user ~]$ sudo useradd ghost
    [ec2-user ~]$ sudo passwd ghost
    
  5. Create a directory where we will install Ghost

    [ec2-user ~]$ sudo mkdir -p /var/www/ghost
    
  6. Grant rights of this directory to the 'Ghost' user we created and switch to the user

    [ec2-user ~]$ sudo chown -R ghost:ghost /var/www/ghost/
    [ec2-user ~]$ su - ghost
    

    This will prompt you for the ghost user's password

  7. Install NVM (Used to install and manage different NodeJS versions)

    [ghost ~]$ wget -qO- https://raw.githubusercontent.com/creationix          /nvm/v0.29.0/install.sh | bash  
    [ghost ~]$ source .bash_profile
    
  8. Download and extract Ghost package: Latest release at the time of writing this article is: 0.11.5

    [ghost ~]$ wget https://ghost.org/zip/ghost-0.11.5.zip  
    [ghost ~]$ unzip ghost-0.11.5.zip -d /var/www/ghost
    
  9. Change to ghost directory

    [ghost ~]$ cd /var/www/ghost/
    
  10. Install nodejs now

    [ghost ~]$ nvm install 6.9.0
    [ghost ~]$ nvm use 6.9.0
    [ghost ~]$ nvm alias default 6.9.0
    
  11. Trigger Ghost installation

    [ghost ~]$ npm install --production
    

    By installing production version we avoid installing a lot of dependencies that are only required for developing Ghost and not for using it as a blogging platform

  12. Lets install PM2 to make sure that if Ghost server crashes, we have an automated way to recover from it We switch to ec2-user after triggering pm2 commands

    [ghost ~]$ npm install -g pm2
    [ghost ~]$ echo "export NODE_ENV=production" >> ~/.profile
    [ghost ~]$ source ~/.profile
    [ghost ~]$ pm2 kill
    [ghost ~]$ pm2 start index.js --name ghost
    [ghost ~]$ pm2 dump
    [ghost ~]$ exit
    
  13. Modify the configuration

    [ec2-user ~]$ sudo su -c "env PATH=$PATH:/home/ghost/.nvm/v0.10.40/bin pm2 startup amazon -u ghost --hp /home/ghost"
    
  14. Install nginx We will configure nginx to forward all incoming requests for 80 port to Ghost nodejs server port

    [ec2-user ~]$ sudo yum install nginx -y
    [ec2-user ~]$ sudo service nginx start
    [ec2-user ~]$ sudo chkconfig nginx on
    
  15. Update nginx configuration and restart it
    Create /etc/nginx/conf.d/ghost.conf and add this:

    server {
        listen 80;
        server_name yourDomainNameORIpAddress;
        location / {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_pass         http://127.0.0.1:2368;
        }
    }
    

    Restart:

    [ec2-user ~]$ sudo service nginx restart
    

Final steps

Now that we have completed the installation process, your Ghost blog should be ready to use. You can access it through your EC2's public ip address.

    eg: http://yourEC2ipAddress

You can login to admin panel and configure your blog or start off with some new articles here:

    eg: http://yourEC2ipAddress/ghost

Ghost will prompt you to create the initial Admin login account. Hence it is important that you do this right away.


Conclusions

There are many other things that you can do to configure and customize your blog. Some of the useful things that come to my mind would be:

  • Installing a different theme
  • Configuring mail server
    • You can use Amazon web services SES or gmail or other 3rd party mail providers as well
    • You can refer to the Ghost support pages for help on mail configurations

I will publish follow up articles related to advanced configuration, using AWS SES etc..


Follow up articles will be linked here:

  dummy_link_till_i_write_the_next_article!
View Comments...