Bakadur's Notes
BAKADUR
Laravel

How to Run php artisan queue:work at all time

Read Count 1,220 pts
  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 
  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:

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.

Let's Connect

Have a question about anything here? Drop a message below.

Email Address
Enter a valid email address
Message
Message cannot be empty