Deploy an Open-Source Headless CMS with Strapi

A headless CMS is a content management system that separates the content from the presentation layer. The content is stored in a central location, but can be accessed and displayed on any device or platform. This is in contrast to a traditional CMS, which combines the content and presentation layers into a single system. Because of this separation, a headless CMS offers more flexibility in where and how you present content e.g. you can choose any front-end framework or technology. If this interests you, read on - I’ll walk through the deployment of an open-source headless CMS, Strapi, on Railway.

What is Strapi CMS?

Strapi is an open-source, fast and secure headless CMS that enables developers to create and manage content programmatically. It is built on top of Node.js and designed to be front-end agnostic. It provides an intuitive administration panel to create and manage different content types like articles, images, videos etc. Developers can also query content using standard RESTful APIs or GraphQL. Strapi has several security features, including reusable policies, CORS, CSP, P3P, Xframe, XSS, and more. Strapi works with PostgreSQL, MySQL, MariaDB, and SQLite databases, and can be self-hosted or managed using Strapi Cloud.

Source: Strapi.io

What is Railway?

Railway is a modern app hosting platform that makes it easy to deploy production-ready apps quickly. Railway offers persistent database services for PostgreSQL, MySQL, MongoDB, and Redis, as well as application services with a GitHub repository as the deployment source. For the latter, Railway can automatically determine the application runtime and deploy the service. Railway offers several one-click starters for popular applications, including Strapi CMS. Since we are just testing the waters, Railway's free tier should be sufficient to host the service.

Source: Railway.app

Deploy Strapi using One-Click Starter on Railway

Sign up for an account with Railway using GitHub, and click Authorize Railway App when redirected. Review and agree to Railway's Terms of Service and Fair Use Policy if prompted. Launch the Strapi one-click starter template (or click the button below) to deploy Strapi instantly on Railway.

You'll be given an opportunity to change the default repository name and set it private, if you'd like. Fill in the environment variables listed below, and click Deploy; the deployment will kick off immediately.

  • ADMIN_JWT_SECRET: Secret used to encode JWTs
  • JWT_SECRET: Random string used to generate new JWTs
  • APP_KEYS: Session keys used by session middleware
  • API_TOKEN_SALT: Hash salt used to generate API tokens
  • CLOUDINARY_NAME (optional): Required if you want images to be persisted.
  • CLOUDINARY_KEY (optional): Required if you want images to be persisted.
  • CLOUDINARY_SECRET (optional): Required if you want images to be persisted.
Deploy Strapi using the one-click starter on Railway

Once the deployment completes, a Strapi instance will be available at a default xxx.up.railway.app domain - launch this URL to access the app. If you are interested in setting up a custom domain, I covered it at length in a previous post - see the final section here.

Strapi app deployed successfully on Railway

Launch xxx.up.railway.app\admin to access the Strapi administration portal, and create the first admin user. Provide the details and click Let's start.

Configure admin credentials for Strapi CMS

Getting Started with Strapi CMS

Once you log in, you'll see the default Strapi dashboard. The Railway template sets up Strapi with a SQLite database; see this guide for other options.

Strapi CMS dashboard

Before we get into the content management, let's have a look at the configuration options and other sections. The Settings page allows you to manage API tokens, configure webhooks, define role-based access control, configure email, and more.

Strapi settings overview

The Media Library lets you upload your assets manually, and also displays assets that are uploaded programmatically.

Strapi media library overview

Plugins are modular extensions that add specific functionality to Strapi e.g. the GraphQL plugin adds support for the GraphQL query language. Several plugins are installed by default, and more can be installed from the marketplace.

Strapi plugins overview

Now, let's look at content management in Strapi. The official Quick Start Guide is quite good, and covers the detailed steps required to create new collections, use the collection types to create new entries, publish the content, and use the API to query the Strapi CMS. There is no added value in duplicating the steps here, so I'll just highlight the key points instead.

Use the Content-Type Builder to create new collection types, and manage existing ones. You can also define one-to-many, many-to-many relationships between the content types.

Strapi content-type builder

Once you have the basic data structures in place, create entries for the content types. These are meant to pre-populate the CMS and help with initial rendering of your frontend code, but the entries can be added later/programmatically too.

Strapi create new entry

Set the roles and permissions, publish the content, and make it accessible publicly via APIs. Finally, use the REST API or GraphQL API to access the content-types through the published API endpoints.

Now that you know the basics of deploying a self-hosted Strapi CMS instance and publishing content with Strapi, go ahead and explore the Quick Start Guide for step-by-step guidance on headless content management.