· ghost cms · 3 min read · Save it 👉

How to install Ghost CMS on Ubuntu

A small guide on how to install Ghost CMS on Ubuntu.

A small guide on how to install Ghost CMS on Ubuntu.

Instructions for the installation and set-up of Ghost

Depending on your VPS or similar, set up a non-root user with;

adduser "username"

Give the user sudo permissions;

sudo usermod -aG sudo "username"

Fully update - use Ubuntu 22.04;

sudo apt update && sudo apt upgrade -y

Install Nginx with;

sudo apt install nginx -y

Install MySQL 8 or above;

sudo apt install mysql-server -y

Enable the service, start and check the status with;

sudo systemctl enable --now mysql

Check it…

systemctl status mysql

Login to mysql with;

sudo mysql

Set a root password (amend password);

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'MyPassword@123';
exit;

Secure the database with;

sudo mysql_secure_installation

The script will ask these questions.

Enter the password for user root: type your set password and then press ENTER.
Change the password for root? Press N, then ENTER.
Remove anonymous users? Press Y, then ENTER.
Disallow root login remotely? Press Y, then ENTER.
Remove the test database and access to it? Press Y, then ENTER.
Reload privilege tables now? Press Y, then ENTER.

Create a database for Ghost;

sudo mysql -u root -p

Then… (amend “new_user” and “your_password” as appropriate, whatever you use here - use going forward on similar examples relating to database set up - the same applies to “new_db”);

CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'your_password';
CREATE DATABASE new_db;
GRANT ALL PRIVILEGES ON new_db.* TO 'new_user'@'localhost';
FLUSH PRIVILEGES;
Exit;

Install NodeJS;

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

Install the Ghost-CLI;

sudo npm install ghost-cli@latest -g

Change from root (if you are) to the user you set up earlier with;

su - "username"

Create a directory for Ghost;

sudo mkdir -p /var/www/ghost/

Give yourself permissions;

sudo chown -R $USER:$USER /var/www/ghost/

Set the read/write permissions;

sudo chmod 775 /var/www/ghost

Put yourself in the directory that you just set up;

cd /var/www/ghost

Now for all of the magic, installing ghost…

ghost install

This will ask you the following (remember what you have input previously, for the DATABASE username, database name etc);

Enter your blog URL: your blog url (as https://example.com)
Enter your MySQL hostname: localhost (I found it better to use 127.0.0.1)
Enter your MySQL username: new_user
Enter your MySQL password: [hidden]
Enter your Ghost database name: new_db
Do you wish to set up Nginx? Yes
Do you wish to set up Systemd? Yes
Do you want to start Ghost? (Y/n) Y

You can now log in once all finalise to your domain, followed by /ghost where you can set up you admin account.

Your site is now working - have a play around, customise a theme and much more, make it yours!

Beyond the above - there are some tweaks you may want to do. As default, Ghost uses Node Mailer for transactional emails (always Mailgun for bulk emails, which you’ll have to set up yourself) - you can use alternatives for the transactional, for example, I use Sendgrid.

To adjust, do…

cd  /var/www/ghost
nano config.production.json

Look for the mail section and replace with the following (replacing where applicable with your details);

"mail": {
    "transport": "SMTP",
    "options": {
      "service": "Sendgrid",
      "host": "smtp.sendgrid.net",
      "from": "email@email.com",
      "port": 587,
      "auth": {
        "user": "user",
        "pass": "password"
      }
    }
  },

Should you ever decide you want to change your domain, you can do as follows;

cd /var/www/ghost
ghost config url https://newdomain.com
ghost setup nginx
ghost setup ssl
ghost restart
Back to Blog