How to Run php artisan queue:work at all time

Date : 24-10-2023
  1. Install Supervisor:
  2. If Supervisor is not already installed on your server, you can typically install it using your package manager. For example, on Ubuntu, you can install it with:
sudo apt-get install supervisor 
  1. Create a Supervisor Configuration File:
  2. Create a Supervisor configuration file for your Laravel queue worker. You can create a file named laravel-queue-worker.conf in the /etc/supervisor/conf.d/ directory. Use a text editor to create the file:
sudo nano /etc/supervisor/conf.d/laravel-queue-worker.conf 
  1. Inside the configuration file, add the following content:
[program:laravel-queue-worker] process_name=%(program_name)s_%(process_num)02d command=php /path/to/your/laravel/project/artisan queue:work autostart=true autorestart=true user=your-username numprocs=1 redirect_stderr=true stdout_logfile=/path/to/your/laravel/project/storage/logs/worker.log 
  • Replace /path/to/your/laravel/project with the actual path to your Laravel project.
  • Set your-username to the username you use for your web server (e.g., www-data).
  1. Update Supervisor and Start the Worker:
  2. After saving the Supervisor configuration, update Supervisor to read the new configuration and start the Laravel queue worker:
sudo supervisorctl rereadsudo supervisorctl updatesudo supervisorctl start laravel-worker.conf
  1. sudo supervisorctl start laravel-worker.confThis will start the queue worker as a background service, and Supervisor will ensure it runs continuously.
  2. Monitoring the Queue Worker:
  3. You can check the status of the queue worker using Supervisor:
  • To check the status: sudo supervisorctl status
  • To stop the worker: sudo supervisorctl stop laravel-queue-worker:*
  • To start the worker: sudo supervisorctl start laravel-queue-worker:*
  • To restart the worker: sudo supervisorctl restart laravel-queue-worker:*

By following these steps, you'll have set up Supervisor to run the Laravel queue worker


php artisan queue:restart


When we make changes to the file, they won't take effect until you run the above code. So, to ensure that any changes you've made are applied, please run php artisan queue:restart.