How to Setup Laravel Queue on Production
Hell artisan in this laravel queue on production tutorial i will explain how to setup laravel queue on production in linux server. In this laravel queuework on production example i will explain step by step so that you can understand better.
In this article, you will learn how to set up Laravel Queues/Jobs on production in ubuntu server. SO if you don't know how to do that then you are a right place. I hope you will enjoy this laravel queue:work on production tutorial. Let's start.
First step you have to connect to your ubuntu server and go to your existing laravel project then run the below command to create required tables in the database.
php artisan queue:table
Then we need to migrate the tables with the help of the below command:
php artisan migrate
We know that Laravel queues provide a unified queueing API across a variety of different queue backends, such as Amazon SQS, Redis, or even a relational database. So, we need to setup .env file to execute the jobs using database.
QUEUE_DRIVER=database //or QUEUE_CONNECTION=database
To automate the queue job we need to install a supervisor. So let's install it via command line.
sudo apt-get install supervisor
Now we have to create supervisor config file at /etc/supervisor/conf.d queue-worker.conf.
cd /etc/supervisor/conf.d nano queue-worker.conf
[program:queue-worker] process_name = %(program_name)s_%(process_num)02d command=php /var/www/html/your-project-folder/artisan queue:listen autostart=true autorestart=true user=root numprocs=1 redirect_stderr=true stdout_logfile=/var/www/html/your-project-folder/public/worker.log
Then we need tp reread the supervisor the config file
And now finally activate the process
Read also: Laravel 8.x Queues Example with Redis and Horizon
Hope it can help you.