DEV Community

Cover image for Hosting free Strapi CMS on Railway [Building Personal Blog Website Part 1]

Hosting free Strapi CMS on Railway [Building Personal Blog Website Part 1]

Michał Hawełka on August 26, 2022

This is the first part of the "Building Personal Blog Website" series. In the series we'll setup a free CMS to hold our blog content on Railway, cr...
Collapse
 
bartfluitsma profile image
Bart

Michał, thank you so much, you helped me out big time after a long struggle!

One thing missing, when I cloned the Strapi app, I had to create a .env file and place the matching keys in there. For the rest, it's working like a charm!

Collapse
 
hwlkdev profile image
Michał Hawełka

Glad it helped you! :)
You are right! The .env file is needed for local development, I'll update the guide soon. This part was there back when I used Heroku, but I guess I lost it during the Railway adjustments. Thanks for noticing!

Collapse
 
sebight profile image
Seb

Hey, great tutorial!

I have a problem though. Whenever I do stuff locally (add all the needed models, ...) and then I push. Railway rebuilds it (succesfully!) and it deploys (succesfully again), but whenever I go to /admin, it shows "An error occurred while requesting the API".

Any idea why this could be happening?

Collapse
 
hwlkdev profile image
Michał Hawełka

Does this issue occur when you try to go to /admin again? It happens to me from time to time, but usually as soon as I try opening admin panel for the second time it works :D
I think this could be related to refreshing the versions of your Strapi on Railway - something is not yet ready, but the status on Railway says that everything is done already. I didn't do any deeper investigation into this topic, so unfortunately I can't help you :(

Collapse
 
hades200082 profile image
Lee Conlin

I get this issue too. When accessing the /admin path on Railway It looks like the default setup you describe is trying to make XHR requests to localhost:1337.

Looking at the code, I think we need to set HOST and PORT variables in Railway but when trying that I just get an error complaining about the bindings?

Thread Thread
 
sebight profile image
Seb

Hey. I've solved by doing a normal Strapi setup (like you would normally do), instead of using the Strapi template which Railway provides, that looks rather outdated.

Now it's running all good! :)

Thread Thread
 
sscumac profile image
sscumac

This worked for me too!

Collapse
 
hwlkdev profile image
Michał Hawełka

I see below that you found the solution. I also had this problem in the last few days. You don't need to create a new Strapi setup, it seems you need to just use newer version of Strapi in your package.json (4.5.5 for example worked for me) :)

Collapse
 
akanni_i profile image
Akanni Rasheed I.

Is hosting strapi on railway free forever?

Thread Thread
 
akanni_i profile image
Akanni Rasheed I.

Hope there is no limit to it in as much I am using it for a small project just like Heroku free tier then.

Thread Thread
 
hwlkdev profile image
Michał Hawełka

There is a usage monthly limit as long as your account does not have any credits on it. I paid 5$ once and my app is working constantly for over half a year without any additional payments. And my account balance is still 5$.

Collapse
 
blaiseai profile image
Blaise Sebagabo

Michał, you a legend, my friend. This is one of the most excellent tutorials that walk us through E2E, from local dev to production, and thanks to the railway platform, no ci/cd hassles!

Collapse
 
nandokferrari profile image
Fernando Ferrari • Edited

Hey Michal, this is a great tutorial. I really enjoyed deploying my strapi to railway this way. Thank you so much for putting in the effort for writing this.

I am struggling with some issue. Every time I do a push to my repo, railway rebuilds my whole application and doing that it deletes my sqlite file database and with it all my configurations and data.

I don't want to commit my local sqlite file to my repo (as this will create more ux problems for sure), but I can't think in any other way for preventing my database from being deleted on each build.

Any ideas?

Collapse
 
hwlkdev profile image
Michał Hawełka

Unfortunately I don't have too much of an experience with SQlite, I usually use it only for local testing :) For deployment I usually go for a "real" database (like postgres in this example).

Collapse
 
nandokferrari profile image
Fernando Ferrari

The same for me. I just used a MySQL remote that I have, and could make things work this way; trying to avoid costs for getting higher in Railway. Thank you so much for putting in the effort of writing those articles.

Collapse
 
anastasiia_xfr profile image
Anastasiia_Berest • Edited

Hi.

When I install locally Graphql I have an error "Cannot use GraphQLScalarType "Time" from another module or realm." Then I use it npm dedupe && npm i graphql@latest && npm i @strapi/plugin-graphql. On localhost all works correctly.

But when I pushed it to git, railway had the next building trouble Server wasn't able to start properly. error: typeDefs must contain only strings, documents, schemas, or functions, got object
joxi.ru/p27GJOdsZ80qp2

I have next configuration in my package.json joxi.ru/vAW5B4wfRlk4Mm

Could anyone help me with this?

Collapse
 
anastasiia_xfr profile image
Anastasiia_Berest

Dough!
I solve this remove "graphql": "^16.6.0", from dependencies in package.json and
using instead"@strapi/plugin-graphql": "^4.6.1"
joxi.ru/Vm6MNvWCKbxyMr

Collapse
 
anastasiia_xfr profile image
Anastasiia_Berest
Collapse
 
vladimirblagojevic profile image
Vladimir Blagojevic

Hi can some1 help me with this problem..
When i hit https://[yourapp].up.railway.app/admin i get this screen

Image description

Collapse
 
hwlkdev profile image
Michał Hawełka

And have you tried opening this address after a few minutes?

And maybe that’s a stupid question but did you replace [yourapp] with the actual name of your app on railway?

Collapse
 
vladimirblagojevic profile image
Vladimir Blagojevic

Hi, tnx for the answer..it just started to work after 45 min wait :)))

Collapse
 
m_faish profile image
Faishal Hanif

I've got an issues on live domain, it show "Warning: An error occurred while requesting the API" when open [domain]/admin, but it runs normally on local, you have any idea about this?

Collapse
 
hwlkdev profile image
Michał Hawełka

Yes, there were some issues lately with Strapi on Railway. Best solution is to upgrade Strapi and all plugins to the latest version in your package.json (I used 4.5.5). I'll add the annotation to this blog post as many people had this issue.

Collapse
 
m_faish profile image
Faishal Hanif

it's works now, thanks for the answer

Thread Thread
 
rafaelmouradev profile image
Rafael.js

Do you can post your project in github and show me your solucion? I spend some days trying fix this

Collapse
 
mrrobotjs profile image
Christopher • Edited

How is it that when you deploy a new change to Strapi, you are then able to login with the same credentials? The Postgres DB is NOT persistent (confirmed by railway.app staff) between builds so how was it possible in your guide?

Collapse
 
nomadicshiv profile image
Shiv Singh

Really great job done by you, i stop using wordpress now :)