Learn to Migrate Ghost Websites from Local to Production

Learn Ghost deployment on production and moving a ghost website from one hosting provider to another.

What is Ghost

The ghost is an open source platform. This is used to create websites that publish content. It comes with some cool default themes, nice editor and a default newsletter feature. A lot of apps can be integrated with ghost open source platform to add extra functionality to the websites.

How to install Ghost websites

First, it is required to install ghost-cli.

Install on local

Here is the command to install ghost on local development machine.

ghost install local

Follow the process to complete the setup. If you are reading this post, you already have done.

On your local development, you might have made below changes to a ghost website.

Your are looking to publish them to a public domain.

  1. Added a new theme.
  2. Made changes to the theme code to add some design changes.
  3. Added some posts or pages.
  4. Uploaded some images to the posts or pages.
  5. Modified app settings

Backup steps

Before starting setup on a hosting machine, do the following things.

Export settings and content

Go to settings -> labs and check "Export your content" section and click "Export" button. That will download all your pages, posts, tags and settings.

Export settings and content

Export route and redirects

Go to settings -> labs and check "Redirects", "Routes" section and download both.

Zip images

Go to the folder of ghost website and create zip of image folder inside content folder.

Below command can be used on linux systems if zip utility is install.

cd <ghost-website>/content
zip -r ghost-images.zip images
zip file creation code

This creates a zip file ghost-images.zip.

Zip theme

You have made changes to the theme code, so we would need to upload the same theme on production server. Ghost made it simple to create zip of theme and upload that on a ghost website.

cd <ghost-website>/content/themes/<your-theme>
npm install
npm run zip
Create zip of theme

Above command will generate a zip file in dist/ folder of the theme. The file name will be <your-theme>.zip.

Now we have taken backup of whatever is required for migration.

Setup Ghost website on production

Install ghost-cli

It is required to install ghost-cli on the production machine.

Create database

Ghost's preferred production database is MySQL. SQLite is used for development. Check here. You may need to install MySQL if not already.

So first create a database and a user that has access to the mysql database you created for ghost app.

Here is the command to create a mysql database.

create database <ghost-db>;
MySQL create database command

Here are the commands to create a mysql user with access to the database.

CREATE USER 'ghost-db-user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ghost-db-password';

GRANT ALL PRIVILEGES ON ghost-db.* TO 'ghost-db-user'@'localhost';

FLUSH PRIVILEGES;
MySQL create user commands

Now your database setup is done 👏.

Install ghost website

Create a folder in a directory where you want to install ghost website.

mkdir ghost-app

cd ghost-app
create folder command

Now use the below command to install ghost app.

ghost install

During the installation process, it will ask to enter database details and domain details. Follow the steps.

Once installation is done, your website will be accessible on the domain you provided.

You might need to configure your domain dns setting on hosting provider and add an nginx / apache server configuration to access the domain.

Access the website

You can access the website on the domain if you have completed previous steps. Now go to <domain>/ghost, finish the sign up step. After that you can access the website admin interface.

Cleanup the ghost defaults

By default ghost adds few posts, pages and tags. Delete those content so that you upload your content on a clean site. To delete a ghost post, open the post editor, click on the menu and click "Delete post" button.

Delete ghost post

Also ghost installation comes with a default user Ghost. Delete or suspend that user to disable access. To delete a staff user access settings -> staff and select to user and then delete.

Ghost staff page
Delete ghost staff

Upload content and settings

Content and settings can be imported. Go to settings -> labs and check "Import content" section and click "choose file" button to upload. Now select the exported file and it will upload the content.

Upload routes and redirects

Go to settings -> labs and upload routes and redirects settings files.

Upload theme

During the backup process we created a zip of the theme file (<your-theme>.zip). The zip file can be uploaded. Go to the design settings and check upload theme option and upload the zip file. Once the theme is uploaded successfully the new theme will be applied.

Upload theme

Upload images

We have taken a backup of images, now move that images file on the host machine and unzip in the images folder. You will need ssh access to upload the zip file on hosting machine.

cd <ghost-website>/content

zip ghost-images.zip
Put images back

Cool, now access your website. It should have content that you wanted to migrate from local development to production.

The same above step may work when moving a ghost website from one hosting to another hosting.

I'm using ghost platform for my below websites.

  1. Remote Work Stories
  2. MatterCurve.com
  3. OnkarJanwa.com

Looking for consultation on ghost setup, reach out to me (er.onkarjanwa at gmail.com)