Install Ghost on ubuntu 16.04 using GHOST-CLI

Please refer to the following steps to Install Ghost on ubuntu 16.04 using GHOST-CLI
1. Install latest version of nodejs & npm
2. Install latest version of NGINX (nginx included in ubuntu default repository is out of date, and you would need to include the official Nginx repository
3. Install MySQL
4. Install Ghost CLI

Install Nodejs & NPM

#Get the latest PPA (personal package archive) maintained by NodeSource.
curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
#Update local package cache will be updated automatically. 
sudo bash nodesource_setup.sh
#Install latest version of Nodejs (8.x)
sudo apt-get install nodejs
#Verify nodejs version installed 
nodejs -v
    v8.11.1
#verify NPM version installed 
npm -v
    5.6.0

Install Nginx Web Server

#Switch to root login
su -
#Add the official Nginx repository.
echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx" >> /etc/apt/sources.list
#import Nginx public key, to verify the integrity of packages downloaded from this repo
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key

sudo apt update
sudo apt install nginx
nginx -v
    nginx version: nginx/1.15.0

#To enable Nginx to auto start at boot time
sudo systemctl enable nginx
#Nginx is stopped by default
sudo systemctl start nginx
systemctl status nginx

Nginx 1.15 is abit different in ubuntu 16.04 as there is no Site-Availables or Site-Enabled in /etc/nginx now, and we need to edit the /etc/nginx/conf.d/default.conf with the following to proxy port 80 to port 2368

kwyong@ghost:/etc/nginx/conf.d$ cat default.conf
server {
    listen 80;
    listen [::]:80;

    server_name ghost.aventistech.com;
    root /var/www/ghost/system/nginx-root;

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

    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
}

Install MySQL

sudo apt-get install mysql-server

mysql_secure_installation
    Change the password for root ? YES
    Remove anonymous users? YES
    Disallow root login remotely? YES 
    Remove test database and access to it? YES
    Reload privilege tables now? YES 

systemctl status mysql.service

mysqladmin -p -u root version
Enter password:

mysqladmin  Ver 8.42 Distrib 5.7.22, for Linux on x86_64
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
    Server version          5.7.22-0ubuntu0.16.04.1
    Protocol version        10
    Connection              Localhost via UNIX socket
    UNIX socket             /var/run/mysqld/mysqld.sock
    Uptime:                 3 min 9 sec

Threads: 1  Questions: 9  Slow queries: 0  Opens: 115  Flush tables: 1  Open tables: 34  Queries per second avg: 0.047

Installing the Ghost CLI application

sudo npm i -g ghost-cli
npm WARN deprecated fs-promise@0.5.0: Use mz or fs-extra^3.0 with Promise Support
/usr/bin/ghost; /usr/lib/node_modules/ghost-cli/bin/ghost
+ ghost-cli@1.7.2
added 440 packages in 25.551s

Create a Directory /var/www/ghost and run "ghost install"

Please enter NO when it ask whether to setup nginx

sudo mkdir /var/www/ghost
#Set the owner of /var/www/ghost to kwyong
sudo chown kwyong:kwyong /var/www/ghost
#Set the permission
sudo chmod 775 /var/www/ghost

sudo mysql -u root
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'XXXXXXX';

cd /var/www/ghost/
ghost install 

✔ Checking system Node.js version
✔ Checking logged in user
✔ Checking current folder permissions
✔ Checking operating system compatibility
✔ Checking for a MySQL installation
✔ Checking memory availability
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v1.22.5
✔ Finishing install process
? Enter your blog URL: http://localhost:2368
? Enter your MySQL hostname: localhost
? Enter your MySQL username: root
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: ghost_prod
✔ Configuring Ghost
✔ Setting up instance
Running sudo command: chown -R ghost:ghost /var/www/ghost/content
✔ Setting up "ghost" system user
? Do you wish to set up "ghost" mysql user? Yes
✔ Setting up "ghost" mysql user
? Do you wish to set up Nginx? No
Your url contains a port. Skipping Nginx setup.
ℹ Setting up Nginx [skipped]
Task ssl depends on the 'nginx' stage, which was skipped.
ℹ Setting up SSL [skipped]
? Do you wish to set up Systemd? Yes
✔ Creating systemd service file at /var/www/ghost/system/files/ghost_localhost.service
Running sudo command: ln -sf /var/www/ghost/system/files/ghost_localhost.service /lib/systemd/system/ghost_localhost.service
Running sudo command: systemctl daemon-reload
✔ Setting up Systemd
Running sudo command: /var/www/ghost/current/node_modules/.bin/knex-migrator-migrate --init --mgpath /var/www/ghost/current
✔ Running database migrations
? Do you want to start Ghost? Yes
Running sudo command: systemctl is-active ghost_localhost
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
Running sudo command: systemctl is-active ghost_localhost
✔ Validating config
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
Running sudo command: systemctl start ghost_localhost
✔ Starting Ghost
Running sudo command: systemctl is-enabled ghost_localhost
Running sudo command: systemctl enable ghost_localhost --quiet
✔ Starting Ghost
You can access your blog at http://localhost:236/

You should be able to access to http://ghost.aventistech.com to continue the setup in GUI

Leave a Comment