Google Cloud Compute Engine

How to Install Ghost CMS on Ubuntu 18.04 – Google Cloud

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

How to Install Ghost CMS on Ubuntu 18.04 with Google Cloud and connect with Cloud SQL for database.

Ghost is an open-source powerful blog platform built over Node.js and it’s also fully customizable.

This setup is tested on Google Cloud Platform, so this guide can be used on any other cloud hosting services or VPS or Dedicated server running Ubuntu.

Prerequisites

  1. Your Compute Engine Instance running with minimum 1 GB RAM.
  2. For setting up Compute Engine, see the Setting up Compute Engine Instance.
  3. Domain name is pointed to your virtual machine.
  4. For setting up Cloud DNS, see the Setting up Google Cloud DNS for your domain.
  5. Google Cloud SQL Setup, see Setup Cloud SQL and connect with Compute Engine.

Install Nginx

Ghost uses Nginx web server, you can start updating the packages and install Nginx. SSH to your VM Instance and execute the following commands

sudo apt update
sudo apt upgrade

sudo apt install nginx

Once Nginx is installed proceed to configure and enable UFW.

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS'
sudo ufw enable

Install Node.js

To install Ghost you need a supported Node.js version, so you can use the officially recommended Node.js v10.

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install -y nodejs

Confirm the Node.js and NPM installation with the following commands.

node -v
npm -v

You will get the installed version number.

Install Ghost-CLI

You can use the official ghost-cli to setup MySQL user and database and configure Nginx as reverse proxy and finally secure the site with Let’s Encrypt SSL certificate.

sudo npm install [email protected] -g

Install Ghost

Once your server is setup and ghost-cli is installed you can install Ghost.

Note: Installing Ghost in /root or home/ directories results in a broken setup. Use a custom directory with properly configured permissions.

You can use the recommended location to install Ghost which is /var/www/ghost

sudo mkdir /var/www/ghost

Set up correct permissions.

sudo chown $USER:$USER /var/www/ghost
sudo chmod 775 /var/www/ghost

Move inside the directory and install Ghost.

cd /var/www/ghost/
ghost install

You will see the output as follows.

Output
✔ Checking system Node.js version
✔ Checking logged in user
✔ Checking current folder permissions
✔ Checking operating system compatibility
Local MySQL install not found. You can ignore this if you are using a remote MySQL host.
Alternatively you could:
a) install MySQL locally
b) run ghost install --db=sqlite3 to use sqlite
c) run ghost install local to get a development install using sqlite3.
? Continue anyway? (y/N)

Type Y and hit Enter

Output
MySQL check skipped
ℹ Checking for a MySQL installation [skipped]
✔ Checking memory availability
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v2.13.1
✔ Finishing install process

Now you will be prompted to enter your blog URL, enter http://yourdomainname.com

MySQL hostname enter Cloud SQL IP Address

MySQL username enter username

MySQL password enter password

Ghost database name enter database name

Output
? Enter your blog URL: http://yourdomainname.com
? Enter your MySQL hostname: CLOUD_SQL_IP_ADDRESS
? Enter your MySQL username: username
? Enter your MySQL password: password
? Enter your Ghost database name: database_name
✔ Configuring Ghost
✔ Setting up instance
sudo useradd --system --user-group ghost
sudo chown -R ghost:ghost /var/www/ghost/content
✔ Setting up "ghost" system user
? Do you wish to set up "ghost" mysql user? Yes

You will be asked to setup ghost user, you need to allow this setup.

Output
MySQL user is not "root", skipping additional user setup
ℹ Setting up "ghost" mysql user [skipped]
? Do you wish to set up Nginx? Yes

Allow Nginx setup.

Output
✔ Creating nginx config file at /var/www/ghost/system/files/yourdomainname.com.conf
sudo ln -sf /var/www/ghost/system/files/yourdomainname.com.conf /etc/nginx/sites-available/yourdomainname.com.com.conf
sudo ln -sf /etc/nginx/sites-available/yourdomainname.com.com.conf /etc/nginx/sites-enabled/yourdomainname.com.conf
sudo nginx -s reload
✔ Setting up Nginx
? Do you wish to set up SSL? Yes

Allow SSL setup and provide your email address to create and install Let’s Encrypt certificate.

Output
? Enter your email (For SSL Certificate) your_email_address
sudo mkdir -p /etc/letsencrypt
sudo ./acme.sh --install --home /etc/letsencrypt
sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --domain yourdomainname.com.com --webroot /var/www/ghost/system/nginx-root --reloadcmd "nginx -s reload" --accountemail your_email_address
sudo openssl dhparam -out /etc/nginx/snippets/dhparam.pem 2048
sudo mv /tmp/ssl-params.conf /etc/nginx/snippets/ssl-params.conf
✔ Creating ssl config file at /var/www/ghost/system/files/yourdomainname.com-ssl.conf
sudo ln -sf /var/www/ghost/system/files/yourdomainname.com-ssl.conf /etc/nginx/sites-available/yourdomainname.com-ssl.conf
sudo ln -sf /etc/nginx/sites-available/yourdomainname.com-ssl.conf /etc/nginx/sites-enabled/yourdomainname.com-ssl.conf
sudo nginx -s reload
✔ Setting up SSL
? Do you wish to set up Systemd? (Y/n)

You will be prompted to set up a systemd service. Press Y to continue.

Output
✔ Creating systemd service file at /var/www/ghost/system/files/ghost_yourdomainame-com.service
sudo ln -sf /var/www/ghost/system/files/ghost_yourdomainname-com.service /lib/systemd/system/ghost_yourdomainname-com.service
sudo systemctl daemon-reload
✔ Setting up Systemd
? Do you want to start Ghost? (Y/n)

Now press Y to start Ghost.

Ghost is installed successfully and you can access the admin interface by http://yourdomainname.com/ghost

You will be greeted with the Ghost Welcome page.

41b11edc ghost welcome page

Click Create your account.

824acf24 ghost create account

Fill all the details and complete the setup and visit the dashboard.

ca5aba4b ghost dashboard

That’s all, Great! In this tutorial, you installed Ghost, configured Nginx to proxy requests to Ghost, and ensured that Ghost runs as a system service.

6 Comments

  1. Hello.

    One of the best tutorials for Ghost on Compute Engine so far.

    However, I’m having trouble. The error is “Error trying to connect to the database”.

    I’ve a Google Cloud MySQL Instance running and I’ve tried specifying SQL hostname as ‘localhost’ as well as ‘public IP of the instance’. Neither worked.

    Please help.

    • CloudBooklet Reply

      Thanks for your interest Alex. I am happy to help you solve the problem. Please check and ensure the following steps are done.

      1. In APIs and Services make sure the Cloud SQL API is enabled.

      2. In your, Compute Engine Instance make sure you chose to “Allow full access to all Cloud SQL APIs” in Identity and API access

      3. In your Cloud SQL instance under Connections tab add the IP address of the Compute Engine Instance in Authorized networks and save.

      4. Use Public IP address of Cloud SQL as the hostname.

  2. Thank you for the detailed instructions. I was able to publish the Ghost site/theme at my domain (homeimproov.com) but the “WWW” version gives me a “not secure” message.

    I tried following your other Lets Encrypt instructions but ran into problems and had to re-install the Ghost theme
    https://www.cloudbooklet.com/secure-nginx-with-lets-encrypt-ubuntu-18-04-google-cloud
    ** I tried this again and go the following error (pasted below). It still behaves the same (homeimproov.com “ok” but “WWW” version not working)

    Any suggestions would be greatly appreciated.

    [email protected]:/etc/nginx/sites-available$ sudo nginx -t
    nginx: [warn] conflicting server name “homeimproov.com” on 0.0.0.0:443, ignored
    nginx: [warn] conflicting server name “homeimproov.com” on 0.0.0.0:443, ignored
    nginx: [warn] conflicting server name “homeimproov.com” on [::]:443, ignored
    nginx: [warn] conflicting server name “homeimproov.com” on [::]:443, ignored
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.