Hosting Laravel 12 on fly.io

Published on Aug 17, 2025

Illustration by fly.io / Annie Ruygt

The official documentation from fly.io on how to host Laravel projects on their infrastructure is awesome, and I'm not going to repeat any of it. If you are considering hosting your Laravel app on fly.io - read trough all of that first. What I will do is to point out what I have learned after hosting Laravel apps on fly.io since early 2024.

Adding trusted proxies

Even though the Dockerfile generated by flyctl tries to configure the trusted proxies for you, my experience is that it is better to just add$middleware->trustProxies(at: '*'); to your withMiddleware() method in boostrap/app.php like this:

Code example

This ensures that any FORWARDED headers generated by the Fly Proxy is trusted by Laravel. If not Laravel will generate plain HTTP links, and report the Fly Proxy IP-address as the user IP. You will also get in trouble when using signed URLs, for example when verifying user email addresses.

Cron and queues

The official documentation from fly.io on how to run cron and queue workers describes the process configuration. This creates an additional machine for just running cron, and one (or multiple) for running the queue worker. This is fine for larger apps, but it costs money.
It is possible to run both the cron deamon and the queue worker on the same machine that serve your web requests.

Cron

Go to your .fly/supervisor/conf.d directory that flyctl created for you when you ran fly launch and create a file called crond.conf with the following content.

[program:crond]
command=cron -f
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stdout_events_enabled=true
stderr_events_enabled=true

Queue worker
Go to your .fly/supervisor/conf.d directory that flyctl created for you when you ran fly launch and create a file called worker.conf with the following content.[program:worker]
command=php /var/www/html/artisan queue:work
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stdout_events_enabled=true
stderr_events_enabled=true
user=www-data

Maintainance driver
If you don't have any shared fly volumes set up, set APP_MAINTENANCE_DRIVER = 'cache' in your fly.toml in order for all of your machines to enter maintenance mode when you run php artisan down.