What is ServerPilot?

ServerPilot is an automated service for managing your WordPress sites and other PHP apps hosted with cloud servers on DigitalOcean, Linode, Vultr, and more.

What is Ghost Blog?

Ghost is a fully open source, adaptable platform for building and running a modern online publication.

This means that Ghost can be freely downloaded and installed on any VPS with root access. Moreover they also provide a cloud-hosted solution Ghost Pro.

Prerequisite

To setup Ghost in production environment, the following stack is recommended:

  • Ubuntu 16.04
  • Min 1GB RAM
  • NGINX (min v1.9.5 for SSL)
  • MySQL
  • Systemd
  • Node v6 installed via NodeSource
  • A non-root user for running ghost commands

Note: Though ServerPilot can run apps built on other platforms, it's not officially recommended to install any other system modules. Please read the official article to know more.

Create New App in ServerPilot

create-new-app-serverpilot-ghost

Create a new app for your blog in the serverpilot panel with the following settings:

  • Name (can be anything)
  • Domain (blog url)
  • Wordpress (keep it unchecked)
  • Server (select the server where the blog should be installed)
  • Runtime (leave default - can be anything and it doesn't matter as Ghost runs on Node platform not PHP)
  • System User (leave default - serverpilot)

Also don't forget to create a database for the new app.

Create Ubuntu User

After creating a new app, SSH into your server as root or sudo user.

adduser <user>

I've named the <user> as ghostuser, you can choose whatever you want. You'll have to assign password to the new user and then just press 'Enter' to skip through all the other prompts.

Next, grant the user with sudo permissions to do administrative tasks.

usermod -aG sudo <user>  

Login New User

Now login as the new user and update the server.

su - <user>
sudo apt-get update
sudo apt-get upgrade

Install Node

Use the following commands to install node

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

Setup App

With logged-in as a new user, navigate to the following location

cd /srv/users/serverpilot/apps/<yourappname>

Give folder permission of this app to the new user.

sudo chown -R <user>:<user> .

Now navigate to the 'public' folder to install Ghost.

cd public

Remove the index.php file. This directory should be empty.

Tip: Use rm -rf * to remove all files in the current directory.

Install Ghost

Install the Ghost-CLI tool.

sudo npm i -g ghost-cli

Now we can install ghost application using the Ghost-CLI.

ghost install

ghost-installation-site-url

The installer will check for the proper system configuration and continues with the installation. During this process, you will be prompted to 'Blog URL'.

ghost-installation-mysql-database-nginx-ssl-systemd

Provide necessary mysql database details. When prompted to add "ghost" new user, enter Yes. As Nginx is already configured, always enter No when prompted.

When the installer asks to setup 'Systemd', always enter Yes as this will ensure the node app always restarts on system bootup.

To start the application, enter Yes when prompted.

403 Forbidden Error Fix

Now when you open the blog url, it will show the following error:

ghost-serverpilot-403-forbidden-error

This is caused because ghost application usually runs in port 2368. To fix this, create a .htaccess file under the public folder and then copy and paste the following code:

nano .htaccess
RewriteRule index.html http://localhost:2368/ [P]
RewriteRule (.*) http://localhost:2368/$1 [P]

Save file and restart the application by using the command:

ghost restart

Ghost Installed - Site Live

Now visit your blog url, you will be presented with the default theme and posts.

To access the admin panel, go to http://{domain.com}/ghost. Here you can setup your blog and admin user account.

Troubleshooting

If any installation error occurs, you can either clean the directory and try again. Or you could just use the following command to resume the installation once the issues are fixed.

ghost doctor

Ghost documentation suggests to uninstall the ghost application using the CLI command rather than hard deleting.

ghost uninstall

If you have any queries or issues, feel free to comment below.