DEV Community

Ankit Verma
Ankit Verma

Posted on

1

How to Set Up Laravel Queue Workers with Supervisor and Cron

📦 What is Supervisor?
Supervisor is a Linux process monitor that keeps your Laravel queue workers running continuously and restarts them automatically if they fail.

⏰ What is Crontab?
Crontab is a Unix utility that runs scripts or commands at scheduled times. In Laravel, this is used for running scheduled tasks defined in your app/Console/Kernel.php in Laravel 10+ routes/console.php .

Before you start, make sure you have:

  • Laravel project set up and ready to use
  • Root or sudo access to the server
  • Your project path and domain correctly configured

Step 1: Install Supervisor

Install Supervisor on Ubuntu:

sudo apt-get install supervisor
sudo service supervisor restart
Enter fullscreen mode Exit fullscreen mode

Step 2: Create a Supervisor Configuration File

Open the configuration file for editing:

sudo vim /etc/supervisor/conf.d/laravel-worker.conf
Enter fullscreen mode Exit fullscreen mode

Paste the following configuration:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/yourdomain.com/artisan queue:work
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/html/yourdomain.com/worker.log
stopwaitsecs=3600
Enter fullscreen mode Exit fullscreen mode

Replace /var/www/html/yourdomain.com/ with the actual path to your Laravel project.

Step 3: Start Supervisor with Your Configuration

Reload Supervisor to recognize the new config and start the worker:

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
Enter fullscreen mode Exit fullscreen mode

To check the worker status:

sudo supervisorctl status
Enter fullscreen mode Exit fullscreen mode

Step 4: Set Up Laravel Scheduler with Cron

Open the crontab configuration:

crontab -e
Enter fullscreen mode Exit fullscreen mode

Add this line to run Laravel's scheduler every minute:

* * * * * cd /var/www/html/yourdomain.com && php artisan schedule:run >> /dev/null 2>&1
Enter fullscreen mode Exit fullscreen mode

Replace the path with your actual Laravel app directory.

Optional: Uninstall Supervisor

If needed, you can remove Supervisor using:

sudo apt-get remove supervisor
sudo apt-get autoremove
Enter fullscreen mode Exit fullscreen mode

Questions or feedback? Drop a comment!

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!