How to Install Ghost Blogging Platform on Ubuntu 16.04 Server

This tutorial will be showing you how to install the Ghost blogging platform on Ubuntu 16.04 server. Ghost is an open-source blogging software coded in Node.js, allowing you to create modern, beautiful blogs. Compared to WordPress, Ghost is lightweight and much faster because it’s built specifically for blogging and isn’t a comprehensive content management system like WordPress.

Ghost features:

  • A Markdown-based editor allowing your to quickly write posts.
  • Simple content management.
  • Collaborative editing with your team.
  • Scheduled publishing
  • Built-in analytics
  • Proper SEO built in directly, with semantic markup, permalinks, XML sitemaps, canonical tags and automatic meta data with manual overrides.
  • Integrated AMP (Accelerated Mobile Pages) support
  • Full RSS feeds, email subscription capture forms and Slack webhook integration
  • Hundreds of beautiful free and premium themes are available from the Ghost marketplace
  • A cross-platform desktop app available for Linux, Mac and Windows.

The Ghost foundation offers managed hosting, but here we will see how to create a self-hosted Ghost blog on Ubuntu 16.04.

How to Install Ghost on Ubuntu 16.04 Server

Step 1: Update Ubuntu 16.04

If you server hasn’t been updated for some time, then run the following command to update.

sudo apt update && sudo apt upgrade

Step 2: Install Node.js on Ubuntu

Ghost requires you to install the LTS version of Node.js and does not support non-LTS version. You can install the latest LTS version, which is Node.js 6.10.x.

Add NodeSource repository using the command below.

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

Then install Node.js.

sudo apt install nodejs

Check Node version.

node -v

Sample output:

v6.10.1

Check npm version:

npm -v

Sample output:

3.10.10

Step 3: Install Ghost

Download the latest version of Ghost using curl.

curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip

If your Ubuntu doesn’t have curl, you can use wget instead.

wget https://ghost.org/zip/ghost-latest.zip -O ghost.zip

Then create a directory (/var/www/ghost/) for Ghost.

sudo mkdir -p /var/www/ghost/

Install unzip utility and unzip the file into that directory.

sudo apt install unzip

sudo unzip ghost.zip -d /var/www/ghost/

Now change working directory to /var/www/ghost/ and install Ghost.

cd /var/www/ghost/

sudo npm install --production

The installation may take a while.

Step 4: Configure Ghost

By default Ghost listens on 127.0.0.1:2368 and the default URL for your Ghost blog is http://my-ghost-blog.com. This is fine for a local install, but if your Ghost blog is installed on a remote system, then you need to change these configurations in order to visit your blog.

Ghost uses a config file named config.js. We need to copy the /var/www/ghost/config.example.js file and name it config.js.

sudo cp config.example.js config.js

Then open this file.

sudo nano config.js

Find the following line.

url: 'http://my-ghost-blog.com',

Change the URL to your domain name or your server’s IP address.

url: 'http://your_domain_or_ip_address',

Then find the following lines.

 server: {
    host: '127.0.0.1',
    port: '2368'
 }

Change 127.0.0.1 to 0.0.0.0, which makes your Ghost blog available for the whole Internet. Save and close the file.

Step 5: Run Ghost

Start your Ghost blog.

sudo npm start --production

install ghost blog ubuntu 16.04

Now enter your domain name (Don’t forget to set A record.) or your server’s IP address in the browser address bar. You will see the home page of your Ghost blog.

http://your-domain.com:2368

http://your-server-ip:2368

install ghost blog ubuntu

Step 6: Set up Nginx Reverse Proxy

You can use Nginx as the front end server for Ghost.  Since Ghost runs in the foreground, you can establish a separate SSH session to your Ubuntu 16.04 server in order to keep it running and at the same time be able to enter commands.

Install Nginx on Ubuntu 16.04.

sudo apt install nginx

Then create an Nginx server block file for Ghost.

sudo nano /etc/nginx/conf.d/ghost.conf

Put the following text into the file. Replace your-domain.com with your own domain.

server {
        listen 80;
        server_name your-domain.com;

        location / {
                proxy_pass        http://127.0.0.1:2368;
                proxy_set_header  X-Real-IP  $remote_addr;
                proxy_set_header  Host       $http_host;
        }
}

The proxy_pass directive will proxy all requests to 127.0.0.1:2368. Save and close the file. Then test Nginx configuration.

sudo nginx -t

If the test if successful, reload Nginx.

sudo systemctl reload nginx

Now you can visit your Ghost blog using a domain name and without having to specify port number. The Ghost admin panel is available at http://your-domain.com/ghost.

Step 7: Make Ghost Run at Startup

We can create a Systemd service for Ghost and then enable this service. Create a systemd service file.

sudo nano /etc/systemd/system/ghost.service

Put the following lines into the file.

[Unit]
Description=Ghost Blog
After=network.target

[Service]
Type=simple

WorkingDirectory=/var/www/ghost
User=www-data
Group=www-data

ExecStart=/usr/bin/npm start --production
ExecStop=/usr/bin/npm stop --production
Restart=always
SyslogIdentifier=Ghost Blog

[Install]
WantedBy=multi-user.target

Note that we’ve specified Ghost should run as www-data user.  This way, hackers won’t gain root access should your Ghost blog get hacked.

Save and close the file. Then make www-data user the owner of the /var/www/ghost directory:

sudo chown -R www-data:www-data /var/www/ghost/

Next, enable this service, which means Ghost will run at startup.

sudo systemctl enable ghost.service

Now we can move to the previous SSH session and press CTRL+C to stop the current Ghost. Next, run the following command to start Ghost as a service.

sudo systemctl start ghost.service

Step 8: Enable HTTPS with Let’s Encrypt

To install the latest version of certbot (Let’s Encrypt client), we can use official PPA.

sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install certbot

If we use the webroot plugin to obtain SSL certificate, we need to allow access to the /var/www/ghost/.well-known/acme-challenge/ directory. Edit the Nginx server block file for Ghost.

sudo nano /etc/nginx/conf.d/ghost.conf

Add the following lines in the server block.

location ~ /.well-known/acme-challenge {
                root /var/www/ghost/;
                allow all;
        }

ghost nginx

Save and close the file. Reload Nginx.

sudo systemctl reload nginx

Next run the following command to obtain an SSL certificate using the webroot plugin. Replace red text with your own data.

sudo certbot certonly --agree-tos --webroot --email your-email-address -d your-domain.com -w /var/www/ghost/

Once the command is finished, you should successfully get a SSL certificate from Let’s Encrypt.

ghost blog ssl

Now edit the Ghost server block file to install the certificate.

sudo nano /etc/nginx/conf.d/ghost.conf

Change the configuration as follows:

server {
      listen 80;
      server_name your-domain.com;
      return 301 https://$server_name$request_uri;
}
server {
      listen 443 ssl http2;
      server_name your-domain.com;

      ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;

      ssl_session_timeout 1d;
      ssl_session_cache shared:SSL:50m;
      ssl_session_tickets off;

    # modern configuration. tweak to your needs.
    ssl_protocols TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
    ssl_prefer_server_ciphers on;

    # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
    add_header Strict-Transport-Security max-age=15768000;

    # OCSP Stapling ---
    # fetch OCSP records from URL in ssl_certificate and cache them
    ssl_stapling on;
    ssl_stapling_verify on;

     location / {
            proxy_pass        http://127.0.0.1:2368;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  Host       $http_host;
     }

     location ~ /.well-known/acme-challenge {
            root /var/www/ghost/;
            allow all;
     }
}

Save and close the file. Then test Nginx configuration and reload.

sudo nginx -t

sudo systemctl reload nginx

Visit https://your-domain.com in web browser to verify Ghost blog is running correctly in HTTPS mode.

That’s it! I hope this tutorial helped you install Ghost on Ubuntu, set up Nginx reverse proxy and install SSL certificate.

Rate this tutorial
[Total: 4 Average: 4.5]