Introduction
If you’ve ever deployed a Laravel app in production, you’ve probably run into this frustrating issue:
everything works perfectly during development, but the moment you close your SSH session or reboot the server, your queue:work process stops.
And when that happens, background jobs—like sending emails, importing files, or processing payments—suddenly halt.
That’s where Supervisor comes in.
Supervisor is a battle-tested process control system that ensures your Laravel queues keep running 24/7, even after reboots, crashes, or code updates. It’s one of those small, behind-the-scenes tools that separates a hobby project from a production-grade application.
In this 2025 step-by-step guide, you’ll learn exactly how to:
- Install and configure Supervisor on Amazon Linux 2023 (EC2)
- Set up Laravel to manage Redis queue workers automatically
- Keep jobs running after code deploys or server reboots
- Use systemd for stable startup and automatic recovery
- Add logging, scaling, and security optimizations for production
Let’s build a bulletproof queue system that never quits.
1. Why Laravel Redis Queues Need Supervisor
Laravel’s queue system is brilliant—it lets you offload heavy or time-consuming tasks to a background process. Whether you’re sending hundreds of emails, syncing large data sets, or processing imported files, queues keep your app fast and responsive.
But there’s a problem: The command you use to run queues—
php artisan queue:work
—only runs as long as your terminal session stays open. Once you close your SSH connection or deploy new code, that worker stops.
In production, that’s unacceptable. You can’t afford your jobs to silently stop.
Enter Supervisor
Supervisor is a lightweight process manager written in Python. It:
- Monitors and restarts queue workers automatically
- Ensures they start at boot time
- Keeps logs of worker activity and errors
- Lets you scale multiple worker processes easily
- Provides simple control via
supervisorctl
When configured properly, Supervisor gives you peace of mind—your Redis queues will always run in the background, even if you never log into the server again.
2. Prerequisites
Before diving in, make sure you have:
- Amazon Linux 2023 (EC2 instance)
- PHP 8.2+ and Composer installed
- Redis and
phpredisorpredisextension - A working Laravel 10 or 11 application
- SSH access as
ec2-userwithsudoprivileges
And confirm that your .env is correctly set up for Redis:
QUEUE_CONNECTION=redis
CACHE_DRIVER=redis
SESSION_DRIVER=redis
Once these are ready, let’s install Supervisor.
3. Installing Supervisor on Amazon Linux 2023
Unlike Ubuntu, Amazon Linux 2023 doesn’t include Supervisor in its default repositories.
We’ll install it manually using Python’s package manager (pip3).
Step 1: Install pip and Supervisor
sudo dnf install -y python3-pip
sudo pip3 install supervisor
Step 2: Create Supervisor directories
sudo mkdir -p /etc/supervisor/conf.d
sudo echo_supervisord_conf | sudo tee /etc/supervisord.conf > /dev/null
Step 3: Include additional config files
Open the main configuration file:
sudo nano /etc/supervisord.conf
At the bottom, add:
[include]
files = /etc/supervisor/conf.d/*.conf
Save and exit (Ctrl + O, Enter, Ctrl + X).
4. Configuring Supervisor with systemd
To make sure Supervisor starts automatically when your EC2 instance boots, we’ll wire it to systemd.
Step 1: Create the systemd unit file
sudo tee /etc/systemd/system/supervisord.service > /dev/null <<'SERVICE'
[Unit]
Description=Supervisor daemon
After=network.target
[Service]
ExecStart=/usr/local/bin/supervisord -n -c /etc/supervisord.conf
ExecStop=/usr/local/bin/supervisorctl shutdown
ExecReload=/usr/local/bin/supervisorctl reload
Restart=always
User=root
[Install]
WantedBy=multi-user.target
SERVICE
Step 2: Enable and start Supervisor
sudo systemctl daemon-reload
sudo systemctl enable --now supervisord
sudo systemctl status supervisord
You should see:
Active: active (running)
Now Supervisor will start automatically every time your server reboots.
5. Setting Up Laravel Queue Workers
We’ll configure Supervisor to manage your Laravel queue workers.
Step 1: Find your PHP path
which php
You’ll likely get /usr/bin/php.
Use that path in your configuration file.
Step 2: Create your worker configuration
sudo tee /etc/supervisor/conf.d/laravel-redis-queues.conf > /dev/null <<'CONF'
[program:laravel-redis-queue]
directory=/var/www/writeflow-ai
command=/usr/bin/php artisan queue:work redis --sleep=3 --tries=3 --timeout=120 --backoff=3 --verbose
autostart=true
autorestart=true
user=ec2-user
redirect_stderr=true
stdout_logfile=/var/www/writeflow-ai/storage/logs/queue-worker.log
stdout_logfile_maxbytes=20MB
stdout_logfile_backups=5
environment=APP_ENV="production",HOME="/home/ec2-user",PATH="/usr/local/bin:/usr/bin:/bin"
CONF
Step 3: Reload Supervisor
sudo /usr/local/bin/supervisorctl reread
sudo /usr/local/bin/supervisorctl update
sudo /usr/local/bin/supervisorctl status
If everything’s configured correctly, you’ll see:
laravel-redis-queue RUNNING pid 1234, uptime 0:00:03
6. Testing Your Queue Setup
Let’s make sure your queues actually run.
Step 1: Create a test job
php artisan make:job TestQueueJob
Open app/Jobs/TestQueueJob.php and modify the handle() method:
public function handle()
{
\Log::info('✅ Queue is working fine: '.now());
}
Step 2: Dispatch it
php artisan tinker --execute="App\\Jobs\\TestQueueJob::dispatch();"
Step 3: Check the logs
tail -f storage/logs/laravel.log
You should see:
[2025-10-10 21:33:05] production.INFO: ✅ Queue is working fine: 2025-10-10 21:33:05
Congratulations — your Laravel Redis queue is now fully supervised and production-ready.
7. Automatically Restart Workers After Code Deploys
Whenever you deploy new code or change your .env file, you must restart your queue workers to load the latest changes.
Instead of running long commands, create a helper script:
sudo tee /usr/local/bin/restart-workers.sh >/dev/null <<'SH'
#!/bin/bash
echo "🔄 Restarting Laravel queue workers..."
/usr/local/bin/supervisorctl reread
/usr/local/bin/supervisorctl update
/usr/local/bin/supervisorctl restart all
echo "✅ All workers restarted successfully."
SH
sudo chmod +x /usr/local/bin/restart-workers.sh
Now, after every deployment, just run:
sudo /usr/local/bin/restart-workers.sh
Simple, clean, and safe.
8. Keep Logs Manageable with Log Rotation
Supervisor creates separate log files for each worker. Over time, these can grow large. You can automate cleanup with logrotate.
sudo tee /etc/logrotate.d/laravel-supervisor >/dev/null <<'ROT'
/var/www/writeflow-ai/storage/logs/queue-worker.log {
weekly
rotate 5
missingok
notifempty
copytruncate
compress
}
ROT
This rotates logs weekly, keeps 5 backups, and compresses old ones.
9. Scaling Queue Workers
Got more traffic or background jobs piling up? Scale easily.
Edit your Supervisor config:
[program:laravel-redis-queue]
numprocs=2
process_name=%(program_name)s_%(process_num)02d
Then:
sudo /usr/local/bin/supervisorctl reread
sudo /usr/local/bin/supervisorctl update
sudo /usr/local/bin/supervisorctl status
Now you’ll have two concurrent workers processing jobs simultaneously.
10. Verify Everything After a Reboot
Reboot your EC2 instance to confirm auto-start behavior:
sudo reboot
Once the instance is back online:
sudo /usr/local/bin/supervisorctl status
Your queue should be running automatically — without you touching a thing.
11. Common Errors & Fixes
| Issue | Cause | Solution |
|---|---|---|
BACKOFF or FATAL |
Wrong PHP path | Run which php and update config |
Permission denied |
Wrong file owner | sudo chown -R ec2-user:ec2-user storage |
queue:work not processing |
Redis not running or wrong env vars | sudo systemctl restart redis |
| No logs | Wrong log file path | Check stdout_logfile in config |
Jobs stuck in failed_jobs |
Exceptions or timeout too short | Increase --timeout or inspect logs |
Quick Takeaways
✅ Use Supervisor to ensure your Laravel queues run continuously.
✅ Install via pip3 on Amazon Linux 2023 (not yum).
✅ Link Supervisor to systemd so it auto-starts on reboot.
✅ Add a restart script for clean deployments.
✅ Implement log rotation to prevent storage bloat.
✅ Scale workers easily with numprocs.
✅ Test with a sample job to confirm everything works.
Conclusion
When it comes to Laravel queue reliability, Supervisor is non-negotiable. Without it, your background jobs can silently stop, leading to failed emails, unprocessed tasks, or delayed user experiences.
By setting up Supervisor on Amazon Linux 2023, you’ve built a robust, self-healing background process system powered by Redis and systemd.
Your queues now:
- Run automatically after deploys or reboots
- Restart on crashes
- Scale seamlessly
- Log every event
That’s the kind of stability every serious Laravel application deserves.
Call to Action
If this guide helped, share it with your DevOps or Laravel team.
Need expert help right now?
- ✅ Hire me on Fiverr: Laravel/AWS Optimization & DevOps
- 🏢 Or work with our team at Ramlit Limited for enterprise-grade Laravel, AI, and cloud solutions.
Let’s make your queues bulletproof and your deployments effortless.
FAQs
1. Why use Supervisor instead of a cron job?
Because cron runs on fixed intervals, not continuously. Supervisor monitors queue:work in real-time and restarts it instantly on crash or reboot.
2. Can I use this setup for SQS or Database queues?
Absolutely. Just replace redis in the command with your queue driver (e.g., database or sqs).
3. How do I stop all queue workers?
Run:
sudo /usr/local/bin/supervisorctl stop all
4. What happens if I deploy new code without restarting workers?
They’ll keep running old code in memory. Always run supervisorctl restart all after a deploy.
5. Is this setup safe for production?
Yes. It’s clean, secure, and aligned with modern Amazon Linux 2023 practices.
Final Word: Your Laravel Redis queues are now unstoppable. No more downtime. No more manual restarts. Just pure, production-grade performance — powered by Supervisor.