Read in 8 minutes
How to 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.
As the prerequisites to follow this tutorial, you will need:
- According to the official Ghost system requirements you need at least 1G of RAM. If you have a server with less than 1GB of RAM, you can create a swap file.
- A domain name pointing to your public server IP. In this tutorial we will use
- Nginx installed by following How To Install Nginx on Ubuntu 18.04.
- Firewall configured by following How To Set Up a Firewall with UFW on Ubuntu 18.04. Make sure ports
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
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 update sudo apt-get -o Dpkg::Options::="--force-overwrite" install yarn
Install the MySQL package with the following command:
sudo apt install mysql-server
mysql_secure_installation command to improve the security of the MySQL 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
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:
and run the following query which will set a password the MySQL root user when using the
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.
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
Now that you have Ghost CLI installed and all prerequisites are complete, we can start with the installation.
Change to the
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.
✔ 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
? 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
✔ 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
? 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) [email protected] 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 [email protected] 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
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:
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:
Once you fill in the details and click on the
Invite your team button.
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:
From here you can create new posts, add users and change Ghosts configuration.
In this tutorial, you learned how to install a production ready Ghost instance.