How to Install Ghost on Ubuntu 18.04

Published on

8 min read

Install Ghost on Ubuntu 18.04

Ghost is a modern source publishing platform built on top of the Node.js platform. It is fully customizable and easy to use, allowing you to publish your content with almost zero learning curve.

In this tutorial we are going to show you how to deploy a secure Ghost blog on an Ubuntu 18.04 server using Nginx as a proxy, free Let’s Encrypt SSL certificate, the latest LTS version of Node.js, and MySQL/MariaDB as a database backend.

Prerequisites

As the prerequisites to follow this tutorial, you will need:

Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges .

Installing Node.js and Yarn

At the time of writing this article, the recommended Node.js version for Ghost is v8 carbon LTS. We’ll install Node.js from the NodeSource repository.

Enable the NodeSource repository for Node.js v8 using the following curl command :

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

Install Node.js by typing:

sudo apt install nodejs
For other installation methods check our How To Install Node.js on Ubuntu 18.04 guide.

To install yarn first enable the Yarn repository on your system with the following commands:

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Once the repository is enabled, install yarn with:

sudo apt updatesudo apt-get -o Dpkg::Options::="--force-overwrite" install yarn

Installing MySQL

Ghost supports MySQL , MariaDB and SQLite databases. In this tutorial, we will be using the MySQL which is the recommended database when you run Ghost in production mode.

Install the MySQL package with the following command:

sudo apt install mysql-server

Run the mysql_secure_installation command to improve the security of the MySQL installation:

sudo mysql_secure_installation

You will be asked to configure the VALIDATE PASSWORD PLUGIN which is used to test the strength of the MySQL users passwords. There are three levels of password validation policy, low, medium and strong. Press ENTER if you don’t want to set up the validate password plugin.

On the next prompt you will be asked to set a password for the MySQL root user.

Once you set the root password the script will also ask you to remove the anonymous user, restrict root user access to the local machine and remove the test database. You should answer Y (yes) to all questions.

Next we need to change authentication method from auth_socket to mysql_native_password, so the Ghost installer can access our MySQL server. To do so log in to the MySQL server as the root user:

sudo mysql

and run the following query which will set a password the MySQL root user when using the mysql_native_password method:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_pasword';FLUSH PRIVILEGES;

Make sure you change very_strong_pasword with a strong password.

Installing Ghost-CLI

We’ll install Ghost using the official Ghost CLI utility. This utility allows you to install or update Ghost in a single command.

Ghost CLI is available as a npm package. The following command will install Ghost CLI on your Ubuntu system globally:

sudo yarn global add ghost-cli

Creating Ghost installation location

We’ll download and install Ghost in the /var/www/ghost directory, which is the recommended installation location.

To create the directory type:

sudo mkdir -p /var/www/ghost

Change the ownership of the directory to your user:

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

$USER is an environment variable that holds your username.

Set the correct directory permissions :

sudo chmod 775 /var/www/ghost

Installing Ghost

Now that you have Ghost CLI installed and all prerequisites are complete, we can start with the installation.

Change to the /var/www/ghost directory.

cd /var/www/ghost

To start the installation run ghost install, which will install and configure Ghost, configure Nginx as a reverse proxy , and secure the site with a free let’s encrypt SSL certificate.

ghost install
✔ Checking system Node.js version
✔ Checking logged in user
✔ Checking current folder permissions
System checks failed with message: 'Linux version is not Ubuntu 16'
Some features of Ghost-CLI may not work without additional configuration.
For local installs we recommend using `ghost install local` instead.
? Continue anyway? (y/N) y

The installer will check your system and print some warnings as shown above. Type y to continue and the installer will then download and install Ghost:

ℹ Checking operating system compatibility [skipped]
✔ Checking for a MySQL installation
✔ Checking memory availability
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v1.24.9
✔ Finishing install process

Next you will be prompted to set your blog URL and your MySQL information. Provide the root username and password that we have setup in the Installing MySQL section and use the default database name ghost_prod.

? Enter your blog URL: https://example.com
? Enter your MySQL hostname: localhost
? Enter your MySQL username: root
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: ghost_prod

The installer will create a system user named ghost and will ask you if you wish to create a ghost MySQL user, type Yes.

✔ 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

Next, the installer will ask you if you wish to set up Nginx. Confirm by typing Yes.

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

Once Nginx is set up the installer will ask you if you want to set up SSL. Confirm by typing Yes and the configuration wizard will ask you to enter your email address and then it will generate a free Let’s Encrypt SSL certificate for your domain and configure Nginx.

? Do you wish to set up SSL? Yes
? Enter your email (used for Let's Encrypt notifications) admin@example.com
Running sudo command: mkdir -p /etc/letsencrypt
Running sudo command: ./acme.sh --install --home /etc/letsencrypt
Running sudo command: /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --domain example.com --webroot /var/www/ghost/system/nginx-root --reloadcmd "nginx -s reload" --accountemail admin@example.com
Running sudo command: openssl dhparam -out /etc/nginx/snippets/dhparam.pem 2048
Running sudo command: mv /tmp/ssl-params.conf /etc/nginx/snippets/ssl-params.conf
✔ Creating ssl config file at /var/www/ghost/system/files/example.com-ssl.conf
Running sudo command: ln -sf /var/www/ghost/system/files/example.com-ssl.conf /etc/nginx/sites-available/example.com-ssl.conf
Running sudo command: ln -sf /etc/nginx/sites-available/example.com-ssl.conf /etc/nginx/sites-enabled/example.com-ssl.conf
Running sudo command: nginx -s reload
✔ Setting up SSL

Next, the installer will ask you if you want to set up a systemd service. Type Y to accept and the installer will create a new systemd service called ghost_example-com and enable it to start on boot:

? Do you wish to set up Systemd? Yes
✔ Creating systemd service file at /var/www/ghost/system/files/ghost_example-com.service
Running sudo command: ln -sf /var/www/ghost/system/files/ghost_example-com.service /lib/systemd/system/ghost_example-com.service
Running sudo command: systemctl daemon-reload
✔ Setting up Systemd

Finally, the installer will set up the database and ask if you want to start Ghost, type Yes.

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_example-com
✔ 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_example-com
✔ Validating config
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
Running sudo command: systemctl start ghost_example-com
✔ Starting Ghost
Running sudo command: systemctl is-enabled ghost_example-com
Running sudo command: systemctl enable ghost_example-com --quiet
✔ Starting Ghost
You can access your publication at https://example.com
Next, go to your admin interface at https://example.com/ghost/ to complete the setup of your publication

Ghost uses direct mail by default
To set up an alternative email method read our docs at https://docs.ghost.org/docs/mail-config

Complete the Ghost setup

Open your browser, go to your Ghost admin interface at https://example.com/ghost/ and you will be presented with the following screen:

Ghost Setup

To get started click on the Create your account button.

You will be redirected to the Create your account screen, where you need to enter up your Blog title, as well as your account Full name, Email address, and Password:

Ghost Create Admin

Once you fill in the details and click on the Invite your team button.

Ghost Invite team

On this screen you will be asked to enter you collaborators email addresses. You can simply click on the I'll do this later, take me to my blog! link and you will be redirected to the Ghost dashboard:

Ghost Dashboard

From here, you can create new posts, add users and change Ghosts configuration.

Conclusion

In this tutorial, you learned how to install a production ready Ghost instance.

You should now visit the Ghost Help page and learn more about how to manage you Ghost installation. You can also visit the Ghost Marketplace and discover the Ghost themes.