How to Install Ghost on Ubuntu 17.04 / 17.10

This post shows new users and students how to easily install Ghost on Ubuntu 17.04 / 17.10. Ghost is a fairly new blogging platform powered by Node.js. Ghost is a very clean and lightweight platform designed for bloggers who want to focus on blogging and nothing else.

Unlike WordPress and other content management systems based on PHP, Ghost simple in design and function. No additional packages and server needed, just JavaScript.

To get Ghost quickly running on Ubuntu, follow the steps below

Step 1: Update Ubuntu

Before installing Ghost or any other packages in Ubuntu, it’s recommended that you update the server. To do that, run the commands below

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

After running the commands above, you may want to restart the server.

Step 2: Install Node.js package

Since Ghost is based on Node.js run the commands below to download Node.js packages from its repository

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

Next, run the commands below to install Node.js and required packages in order for Ghost to function. Nginx webserver will be needed for this. s

sudo apt-get install nodejs

Step 3: Install and Configure Ghost

Now that you’ve install Node.js and other packages that Ghost needs, let’s go and download Ghost packages from its repository. To do that, run the commands below.

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

The commands above download the latest version of Ghost packages.

After downloading Ghost package, run the commands below to create Ghost document root directory.

sudo mkdir -p /var/www/html/ghost/

Then unzip Ghost package in the root directory.

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

Now change into the root directory and install Ghost

cd /var/www/html/ghost
sudo npm install --production

Wait for the installation to complete.

After the installation completes, run the commands below to create Ghost configuration file from its example file.

sudo cp config.example.js config.js

Then open the configuration file and configure make sure the content looks like the highlighted one below.

sudo nano config.js

Validate that you configure the settings below to match your server. The URL is the URL to access the site.

// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'http://myghost.com',
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},

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

Make the change and save the file.

After saving the file, run the commands below to start Ghost.

sudo npm start --production

Ghost by default runs on port # 2368. You must type the port number after the URL to access.

ex. http://myghost.com:2368

Ghost should be accessible.

ghost ubuntu

To create an account, type URL followed by /ghost/signup

ex. http://myghost.com:2368/ghost/signup

Step 4 Install Nginx Webserver as Proxy

Since you must always type the hostname followed by the port number to access Ghost, which you probably don’t want your users to type, you must install Nginx and configure it as a proxy server for Ghost. To do that follow the steps below.

sudo apt-get install nginx

Then create a ghost config file by running the commands below.

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

Then copy and paste the content below into the file, then save.

server {
    listen 80;
    listen [::]:80;
    server_name myghost.com www.myghost.com;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:2368;
    }
}

 

Restart Nginx and connect to your site via its domain or hostname.

sudo systemctl restart nginx

Congratulations! You’ve just installed Ghost on Ubuntu

Enjoy!

You may also like the post below:

Setup Varnish and Apache2 on Ubuntu 17.04 / 17.10