Deploy a Laravel app with Railway and Supabase

Original link: https://blog.forecho.com/use-railway-and-supabase.html

introduction

20220830lBfWYZ

When swiping Twitter, I saw someone sharing how to deploy applications using Railway + Supabase . These PaaS services usually have free quotas. If it is a small project, it is usually equivalent to free use.

After a brief look, I thought it was not bad, so I tried to deploy a Laravel application. This article will share the pit I stepped on.

Railway

Railway provides server and database services, and you can use 500 hours (20 days) for free when you register for an account, or a quota of less than $5. See their Starter Plan for details.

After the credit card is bound, the money will be automatically deducted according to the usage, and it will start to be charged when it exceeds $5 per month. And there is no 500 hour limit. So the Starter Plan version is for you to experience, and you still have to bind a credit card to use it.

Here we only use the server service it provides, the database can be replaced by Supabase to reduce the free credit of Railway.

Supabase

Supabase provides Database, Authentication, Storage, and Edge Functions services. Here we only need to use its Database service. The free quota is 500MB, which is enough for small projects.

It is worth noting that the database provided by Supabase is PostgreSQL, not MySQL which I usually use most.

Deploy the Laravel application

When building a new project in Railway, you can choose the Laravel template, but the bad thing is that this template can’t be used normally at all. I groped for a long time, and after a few hours of stepping on the pit (Google + keeps trying), it was finally deployed normally.

In fact, as long as the Procfile file is added to the root directory of the Laravel project, the code is as follows:

 1 
 web: (cd /app && cp .env.example .env && php artisan key:generate && php artisan migrate) && ([ -e /app/storage ] && chmod -R ugo+w /app/storage); perl /assets/transform-config.pl /assets/nginx.template.conf /nginx.conf && echo "Server starting on port $PORT" && (php-fpm -y /assets/php-fpm.conf & nginx -c /nginx.conf)

Since we are using the Supabase database, we need to enter environment variables here, and the configuration is obtained from Supabase.

Railway supports automated deployment, custom domain names, and looks pretty good.

The use of Supabase will not be discussed, it is very simple.

at last

Railway seems to be a very new platform and is not perfect. At present, I have not found how to deploy the running queue service and timing script service. I do not plan to use Railway until I find these two solutions. If you don’t have these two requirements, you can try it.

Speaking of PaaS, Heroku has to be mentioned, but it seems to have lost its way after being acquired by Salesforce, which is a pity. I hope there will be more platforms in this industry. Competition is a good thing.

In addition, I heard that Fly.io is also a good platform. I can study it when I have time next time.

References

This article is reprinted from: https://blog.forecho.com/use-railway-and-supabase.html
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment