What is Strapi?
Strapi is an open-source headless Content Management System that offers you the chance to develop API with distinctive features. It's built on Node.js and works with any GraphQL enabled Frontend Frameworks.
You can create custom content types, relationships and media libraries for images and audio files with Strapi.
What is Railway?
It's a PaaS (similar to Heroku) that allows you to connect your Git repository and with each commit or new PR you trigger an event to deploy your application. Railway has several very nice features:
- Uses NixPacks to build the images;
- Free SSL Certificate;
- Straightforward UI;
- Create multiple environments;
- "Pay as you grow";
However, there are some features I wish it had:
- More regions available - 🇧🇷 please (See the thread);
- Access the application console via UI (Similar to Digital Ocean and Render);
Deploy
Create your account and create a new project
Search by Strapi
and select the first option.
Add a valid name for your repository.
The railway will copy a project into your account during the deployment process. As shown in the image below, you will have to add the environment variables.
You can use the https://randomkeygen.com/ to fill up the ADMIN_JWT_SECRET
,JWT_SECRET
, APP_KEYS
and API_TOKEN_SALT
.
In that project is set up the Strapi with Postgres and Cloudinary. Cloudinary is responsible for managing your media library, so you must have a Cloudinary account.
In the Cloudinary, you copy your credentials.
Then paste it into the Railway Environment variables and click on Deploy
.
Waiting the building and deploy!
It's done!
Now you can access the Strapi admin via your https://strapi-production-XXXX.up.railway.app/admin
and create a user account.
Troubleshooting
One annoying thing about Strapi is that it doesn't have development mode enabled by default, so I can't create new collections.
I wasted a lot of time thinking that changing the NODE_ENV
environment variable could solve it, but it didn't.
So I found another way to solve this.
An important thing to note: the current version deployed is v4.1.9
.
To enable development mode and update the project we need to make a change to the project created by Railway in your Github account.
Change the file package.json
to be like this:
{
"name": "strapi",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi develop", // <<----- Here
"build": "strapi build",
"strapi": "strapi"
},
"devDependencies": {},
"dependencies": {
"@strapi/plugin-i18n": "4.1.9", // Upgrade to 4.3.2
"@strapi/plugin-users-permissions": "4.1.9", // Upgrade to 4.3.2
"@strapi/provider-upload-cloudinary": "4.1.9", // Upgrade to 4.3.2
"@strapi/strapi": "4.1.9", // Upgrade to 4.3.2
"pg": "8.7.3"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "35d7a084-3088-4d0b-869e-f503693ee8e5"
},
"engines": {
"node": ">=12.x.x <=16.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
To start Strapi in development mode, I changed the value for strapi develop
in the command start.
⚠️ Don't forget to run yarn install
to update the yarn.lock
before pushing your commit.
You can see my commit here: https://github.com/candidosales/strapi-railway-deploy/commit/529cb16521f33a5d824a34a1de3f30868b122ff7
After pushing the commit, the build will start again and when finished ...
You can verify that it will be in the new version, and you can create new collections.
If you want to have more control over the media gallery and don't want to deploy using Cloudinary, in the following article, I'll teach you how to deploy Strapi 4 to Render.
Any feedback is welcome! 😄
Top comments (3)
yes this is the way
This is The easiest way to deploy strapi successfully ❤️❤️❤️
After deploying the Strapi, Railway will copy a project to your Github account. You have to run the
yarn install
in that project.