I am a PHP/Laravel developer. I currently run my apps on a traditional cloud VPS provider but really want to get away from managing servers. I have not been able to find any guides on your site or even external blog posts about getting Laravel running on Fly.
Doing some digging I found this post about multi process apps so it looks like that would be an easy way to run queue workers by defining a worker process and having it run Laraverl’s queue worker command
php artisan queue:work
I am not 100% sure what to do for the command for the web process. Would I need to start nginx or something?
I am also not sure what to do for scheduled tasks. It seems a year ago you said cron tasks were coming in a few months But that was almost exactly a year ago and I have not seen any more recent updates on that. For Laravel specifically we would normally schedule a cron to run
php artisan schedule:run every minute and the Laravel code would handle the rest.
I also can’t seem to find a good source for how to scale processes. Like if my queue is backing up to add more workers or if I am getting alot of web requests to scale up more web processes.
Yep, it’s not quite as simple as running e.g a Node app because PHP doesn’t include its own web server. You need to run Apache/Nginx in front to proxy requests to it. And so to run both in a single app/vm, you need a supervisor (or equivalent) process to keep both PHP and Nginx running. But it’s absolutely do-able.
Take a look at GitHub - fly-apps/fly-hello-laravel: Sample Laravel app for deployment on Fly.io
That’s the demo Laravel app with its default home page (the example app the Laravel CLI makes). But the changes made to that app (and so the changes needed to deploy your own app) are listed too, from this bit onwards GitHub - fly-apps/fly-hello-laravel: Sample Laravel app for deployment on Fly.io
It uses pretty default settings e.g for PHP conf files and so those can be modified as needed. Hopefully the repo goes into sufficient detail on that.
You make a good point about workers. Indeed, Fly doesn’t provide a cron-as-a-service. There is a brief reference to how that might be done within that repo. I didn’t get as far as actually trying it though Hence the blocks are commented out. But in theory you should be able to get supervisor to run child workers within the same app to run workers to process the queue behind the scenes. I’d strongly recommend experimenting with that on a demo app first. You don’t want the workers to go sending out alerts or whatever it is yours do unexpectedly. But if you look from this line onwards it should be reasonably clear by the task name what it would do so you can uncomment each block as needed: fly-hello-laravel/supervisor.conf at main · fly-apps/fly-hello-laravel · GitHub
And then you’d adjust the tasks the supervisor runs to match that. Currently you’ll see it is running just the nginx and php-fpm tasks (as mentioned above). This line: fly-hello-laravel/supervisor.conf at main · fly-apps/fly-hello-laravel · GitHub
Hopefully that should get you started.
There are certainly other approaches to doing it, like using a base image that includes nginx+php already. But I figured using an empty base OS gives total freedom to install whatever is needed and do other stuff. Like if you want to install Redis, or do other things.
So the “coming soon” for crons never happened? Because without that I don’t think there is a way to run it, maybe a simple app that doesn’t have any scheduled tasks but that’s not my app.
Seems like such a basic mandatory feature to not have tbh. How hard is it to parse the fly.toml for crons and schedule them in the host machine to run a command in the container on the set schedule.
We’d love to offer scheduled tasks. We haven’t done it yet beause we’re focusing first on parts of the platform that users can’t manage themselves, but that affect everyone, like stability, performance and support for regional deployments.
Meanwhile, here’s another example on how to use
supercronic to run jobs on your Fly VM. By cobbling this together with the example posted by @greg, we could make this work. Happy to help!
Side note: We’ve just hired a Laravel expert to focus full-time on making Laravel great on Fly
Further to that from @joshua, until Fly do provide scheduled tasks, there are other managed schedulers. Like Cloud Scheduler | Google Cloud . I’ve used that to initiate http requests to my apps. Seems to work pretty well.
@joshua looks like both your links are to Chris’ tweet. Glad to hear you got someone specifically for Laravel, I would expect he will be able to provide some solid complete examples of how to get Laravel running on your platform rather than me having to figure it out on my own because quite frankly I just don’t have the time to be figuring it all out on my own.
@greg makes a good point about having a 3rd party service use a web route that could trigger the scheduler, seems kinda hacky, but would be easy enough and should work just fine for now. I was honestly surprised it doesn’t exist as crons seems so basic and necessary for all types of apps, not even Laravel specific.