Deploy Ghost on Railway

Jun 11, 2021

In this post, we go over the process of deploying and maintaining a Ghost (a free and open-source publishing platform) instance connected to a MySQL database on Railway!

Ghost is an open-source publishing platform for building and running blogs, magazines, and journals. You can choose from an array of free and paid themes from their marketplace or even build your own. Ghost also allows you to send newsletters and monetize your blog by setting up subscriptions using Stripe.

The company behind Ghost offers a hosted version starting at $9/month but you can also self-host Ghost. At Railway, we provide a free one-click deploy for Ghost using a MySQL database which we automagically provision for you.

Deploying with Railway

To deploy your Ghost instance on Railway, simply click this button (source code), enter the mentioned environment variables and hit deploy. The required MySQL database will be automagically provisioned and the required database migrations will be run for you.

The environment variables we ask you to enter are all optional but we highly recommend entering them to run a full-fledged Ghost blog.

  • CLOUDINARY_URL: Railway's filesystem is ephemeral. Which means that any changes to the filesystem are not persisted between deploys. This is why we've set up Cloudinary for the Ghost blog. All the media in your blog post will be stored on your Cloudinary account and served via their CDN.
  • MAILGUN_SMTP_LOGIN and MAILGUN_SMTP_PASSWORD: Mailgun is the default email provider that works with Ghost. Adding these environment variables allows you to email your subscribers whenever you publish a new post and also to invite additional team members to publish posts and manage the blog.

Changing the theme

By default, we've bundled two themes (Casper and Lyra) with the Ghost starter. If you'd like to use a different theme (take Pico as an example), here are the steps you need to follow:

  • First, add the theme as a dependency to the package.json file.
{
	...
	dependencies: {
		"pico": "github:TryGhost/Pico#main"
		...
	}
}
themes=(
	casper
	lyra
	pico
)
...
  • Push your changes to Github and your project should be redeployed automatically.
💡
Do not add a theme directly using the Ghost UI. While it will appear to work initially, the install will not persist due to Railway's ephemeral filesystem.
An image from Notion

Closing

And with that you should have all the information you need to set up your blog on Railway using Ghost. You should be able to write and publish posts, invite teammates, set up a newsletter and subscriptions. You can even attach a custom domain to your Ghost instance.

If you have any suggestions for more open-source self-hosted solutions you'd like to see guides for, let us know on Discord. Or even better, submit a pull request to our starters repository on Github!