DEV Community

How to create and deploy a Strapi project on Railway

Yinka Adedire on April 08, 2022

Railway is a cloud platform based on Heroku that makes it easy to deploy you app on the cloud. You can provision infrastructure, develop with the i...
Collapse
 
imcorentin profile image
Corentin Bernadou

Hey Yinka, thanks for your tutorial!
I'm encountering a problem when I run the production build with:

ENV_PATH=./.env.production NODE_ENV=production yarn start

Strapi tells me…

An error occurred while requesting the API

Do you have a solution? Thanks again!

Collapse
 
davemarong profile image
Dave Kjell Marong

When you change the the host from 0.0.0.0 to 127.0.0.1, you need to rebuild your strapi app again, then do npm start.
So basically:

npm run build

ENV_PATH=./.env.production NODE_ENV=production npm run start

Collapse
 
fpigeonjr profile image
Frank Pigeon Jr. πŸ‡΅πŸ‡¦πŸ‡ΊπŸ‡Έ

This was perfect for what I was looking for. Thanks for sharing.
Now i have connected my strapi app to the database and my data is persisting in between builds...except for images. Guess we need to use cloudinary for that.

Collapse
 
cmario92 profile image
cmario

hey, how do you persist data between local development and production on Railway? can you please explain?

Collapse
 
fpigeonjr profile image
Frank Pigeon Jr. πŸ‡΅πŸ‡¦πŸ‡ΊπŸ‡Έ

hi Mario,
Well once I setup the production build of Strapi I use that to build out the frontend. I am not using the same data on production and my local instance of Strapi.

Collapse
 
rasmus_kroghandersen_91d profile image
Rasmus Krogh-Andersen

Thanks a lot for this! I've had trouble getting my backend up and running on railway. I still have problems though. Eventhough the build is successful it gives me this in the logs:
Create your first administrator πŸ’» by going to the administration panel at:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 0.0.0.0:1337/admin β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

That page can't be reached. I don't see an adress for a global page either?
Got any clue on what im doing wrong here?

Collapse
 
imoempire profile image
Isaac Obeng • Edited

running ENV_PATH=./.env.production NODE_ENV=production yarn start
results in

'ENV_PATH' is not recognized as an internal or external command,
operable program or batch file.

any idea what might wrong ?

Collapse
 
rachaellynn profile image
rachaellynn

Very helpful -- not a lot of documentation on this out there. Thanks!

Collapse
 
arod1207 profile image
Armando Rodriguez

I followed all the steps and deployment was successful, I just dont get a Service domain. It only shows 0.0.0.0:1337. Any help would be appreciated

Collapse
 
anohene1 profile image
Isaac Anohene

Click on Settings and look for Domains. You'll be able to get a url there. I hope this helps!

Collapse
 
muriukialex profile image
Alex

Thank you @yinks!

Collapse
 
frontendcrypto profile image
frontendcrypto

Another article about connecting tha backend service to a frontend service would be great. I am struggling to make requests from my frontend project to the backend.

Collapse
 
yinks profile image
Yinka Adedire

I'd keep this on my todo. Thank you for the feedback

Collapse
 
stanislavlyu profile image
Stanislav

after pushing to production, all my prev content disappears. Any one know why it happened?

Collapse
 
frontendcrypto profile image
frontendcrypto

I am struggling deploying the project since I have the backend in the root directory and the Vue frontend in /frontend directory. Any clues about how to deploy this?

Collapse
 
yinks profile image
Yinka Adedire

I believe the deployment should work all right, as the build tool will ignore the frontend directory.