Install Ghost CMS on Ubuntu 16.04 | 17.10 | 18.04 with MariaDB and Apache2 Proxy

The recommended setup for Ghost CMS in a production environment is to run it with Nginx, MySQL. We’re going to get Ghost working with MariaDB and Apache2 proxy instead.

Ghost is an opensource publishing platform for the modern web. This setup uses MariaDB and Apache2 to provide a complete production environment to run websites and blogs powered by Ghost.

This post shows new users and students how to easily install Ghost on Ubuntu 16.04 / 17.10 and 18.04. 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 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 Apache2 HTTP Server on Ubuntu

Apache2 HTTP Server is the most popular web server in use. so install it, since Craft CMS needs it.

To install Apache2 HTTP on Ubuntu server, run the commands below.

sudo apt update
sudo apt install apache2

After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always start up with the server boots.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

To test Apache2 setup, open your browser and browse to the server hostname or IP address and you should see Apache2 default test page as shown below. When you see that, then Apache2 is working as expected.

apache2 ubuntu install

Step 3: Install MariaDB Database Server

MariaDB database server is a great place to start when looking at open source database servers to use with Magento. To install MariaDB run the commands below.

sudo apt-get install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.

Run these on Ubuntu 16.04 LTS

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

Run these on Ubuntu 17.10 and 18.04 LTS

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

After that, run the commands below to secure MariaDB server by creating a root password and disallowing remote root access.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

Restart MariaDB server

To test if MariaDB is installed, type the commands below to logon to MariaDB server

sudo mysql -u root -p

Then type the password you created above to sign on. if successful, you should see MariaDB welcome message

mariadb welcome

Step 4: Create Ghost Database

Now that you’ve installed all the packages that are required for Magento to function, continue below to start configuring the servers. First run the commands below to create a blank Magento database.

To logon to MariaDB database server, run the commands below.

sudo mysql -u root -p

Then create a database called ghost


Create a database user called ghostuser with new password

CREATE USER 'ghostuser'@'localhost' IDENTIFIED BY 'new_password_here';

Then grant the user full access to the database.

GRANT ALL ON ghost.* TO 'ghostuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;

Finally, save your changes and exit.


Step 5: 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 | sudo -E bash -

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

sudo apt-get install nodejs

Step 6: Install and Configure Ghost

For this, we’re going to create a new user account called ghostuser which will be used to install Ghost.

Run the commands below to create a new user account called ghostuser. You’ll be asked to create a new password

sudo adduser ghostuser

Then enable the new account to run sudo command

sudo usermod -aG sudo ghostuser

Next, change or su – to ghostuser

su - ghostuser

Now create a new Ghost root directory for its content.

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

Next, change the directory permissions so the ghostuser owns it

sudo chown -R ghostuser:ghostuser /var/www/html/ghost
sudo chmod -R 755 /var/www/html/ghost

If npm isn’t installed, run the commands below to install it

sudo apt install npm

Then change into the ghost root directory and run the commands below to install Ghost. make sure you’re running the command as ghostuser.

cd /var/www/html/ghost
sudo npm i -g ghost-cli
ghost install

This should begin Ghost installation. you’ll be prompted for info about the site URL, database connection information to complete the installation.

ghostuser@ubuntu1804:/var/www/html/ghost$ 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? Yes
ℹ 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.22.2
✔ Finishing install process
? Enter your blog URL:
? Enter your MySQL hostname: localhost
? Enter your MySQL username: ghostuser
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: ghost
✔ Configuring Ghost
✔ Setting up instance
Running sudo command: useradd --system --user-group ghost
Running sudo command: chown -R ghost:ghost /var/www/html/ghost/content
✔ Setting up "ghost" system user
? Do you wish to set up "ghost" mysql user? No
MySQL user is not "root", skipping additional user setup
ℹ Setting up "ghost" mysql user [skipped]
? Do you wish to set up Nginx? No
ℹ 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/html/ghost/system/files/ghost_example-com.service
Running sudo command: ln -sf /var/www/html/ghost/system/files/ghost_example-com.service /lib/systemd/system/ghost_example-com.service
Running sudo command: systemctl daemon-reload
✔ Setting up Systemd
Running sudo command: /var/www/html/ghost/current/node_modules/.bin/knex-migrator-migrate --init --mgpath /var/www/html/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 blog at

Ghost uses direct mail by default
To set up an alternative email method read our docs at

After that, the site should be ready to use.

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


Ghost should be accessible.

ghost ubuntu

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


Step 7: Setup Apache2 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 Apache2 and configure it as a proxy server for Ghost. To do that follow the steps below.

Now that Apache2 is installed, run the commands below to enable its proxy modules.

sudo a2enmod proxy
sudo a2enmod proxy_http

When you’re done, restart Apache2 to enable reload the modules.

sudo systemctl restart apache2.service

After that, run the commands below to create a new site configuration file called ghost.conf

sudo nano /etc/apache2/sites-available/ghost.conf

Then copy and paste the lines below into the file and save.

    <VirtualHost *:80>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        ProxyRequests Off
        <Proxy *>
          Order deny,allow
          Allow from all
        ProxyPass /
        ProxyPassReverse /

        <Location />
          Order allow,deny
          Allow from all


After that, save the file.

Then run the commands below to enable the site.

sudo a2ensite ghost.conf

Disable Apache2 current default site.

sudo a2dissite 000-default.conf

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

sudo systemctl restart apache2.service

Congratulations! You’ve just installed Ghost on Ubuntu

Now you and your users should be able to access the Ghost blog simply by typing the URL.


You may also like the post below:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.