How To Install Ghost on Google Compute Engine

01 Aug 2014

Prerequisite

Google Cloud Project

This section will guide you on how to create a new Google Cloud project, you can skip this section if you already have.

First, you will able to create a new project from Developer Console.

Fill in create project form to start a new project.

You will need to enable billing in order to start launching VM.

The first step to enable billing is to select your country.

The next step is to fill up a billing form.

Launch Google Cloud Virtual Machine

After successfully enable billing, now you can start to launch VM to setup Ghost Blog.

Here are the important fields:

  • ZONE - The zone determines what computing resources are available and where your data is stored and used.
  • MACHINE TYPE - The machine type determines the CPU and memory your instance will have.
  • BOOT SOURCE - The boot source determines the disk used to boot the instance.

After created VM, you will redirect to VM listing page.

You can select SSH to get SSH info, we will use gcutil to SSH in to VM server.

You need copy the command line script so next section will use it to connect to your VM.

Setup Debian 7

Next step is to setup Debian 7 to install packages. Paste previous selected command line script into terminal to SSH into VM.

[gtheme@ghost-blog ~]$ gcutil --service_version="v1" --project="gtheme-ghost-blog" ssh --zone="us-central1-b" "ghost-blog"
gtheme@ghost-blog:~$ sudo apt-get -y update
gtheme@ghost-blog:~$ sudo apt-get -y install git wget unzip man

Since we using Debian 64 bit, the following packages are required to install sqlite3 from source.

gtheme@ghost-blog:~$ sudo apt-get -y install build-essential python-software-properties python g++ make

Setup Nginx

This section will guide you on how to setup Nginx as reverse-proxy for your Ghost Blog.

# install nginx
gtheme@ghost-blog:~$ sudo apt-get -y install nginx
gtheme@ghost-blog:~$ sudo service nginx start

After start nginx, you can browse to your IP to see nginx's default page.

# edit nginx config
gtheme@ghost-blog:~$ sudo vim /etc/nginx/sites-available/default

Edit the file:

server {
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    #root /usr/share/nginx/www;
    #index index.html index.htm;

    server_name example.com;

    location / {
            proxy_pass http://localhost:2367;
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            # try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

    #location /doc/ {
    #       alias /usr/share/doc/;
    #       autoindex on;
    #       allow 127.0.0.1;
    #       allow ::1;
    #       deny all;
    #}

    ...
    ...
}

Here are the details of the changes:

  • Change the server_name from local host to your domain name or IP address (replace the example.com in the configuration).
  • Added proxy_pass http://localhost:2367;.
  • Comment out root /usr/share/nginx/www;.
  • Comment out index index.html index.htm;.
  • Comment out try_files $uri $uri/ /index.html;.
  • Comment out location /doc/ { block.

Save and Exit.

# restart nginx so config take effect
gtheme@ghost-blog:~$ sudo service nginx restart

Setup Ghost Blog

After setup OS, this section we will focus on setup Ghost Blog.

gtheme@ghost-blog:~$ curl https://raw.githubusercontent.com/creationix/nvm/v0.12.2/install.sh | bash

gtheme@ghost-blog:~$ source ~/.profile

gtheme@ghost-blog:~$ nvm install v0.10.26
gtheme@ghost-blog:~$ nvm alias default v0.10.26
gtheme@ghost-blog:~$ nvm use v0.10.26

gtheme@ghost-blog:~$ wget https://ghost.org/zip/ghost-latest.zip
gtheme@ghost-blog:~$ unzip ghost-latest.zip -d ghost

gtheme@ghost-blog:~$ cd ghost
gtheme@ghost-blog:~/ghost$ npm install --production

Browse to IP view that Ghost Blog now is up and running.