When using:
QUEUE_CONNECTION=databaseon production, you must run a queue worker continuously. Otherwise queued jobs such as password reset emails, notifications, and other background tasks will remain in the jobs table and never be processed.
QUEUE_CONNECTION=database
MAIL_MAILER=smtp
MAIL_HOST=your-smtp-host
MAIL_PORT=587
MAIL_USERNAME=your-username
MAIL_PASSWORD=your-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=no-reply@yourdomain.com
MAIL_FROM_NAME="${APP_NAME}"Run the following on production:
php artisan queue:table
php artisan queue:failed-table
php artisan migrateIf the migrations already exist, Laravel may report that they have already been created. That is expected and safe to ignore.
After updating .env, refresh Laravel's cached configuration:
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cacheFor a quick manual test, start a worker:
php artisan queue:work database --tries=3 --timeout=90Leave the terminal running and test a password reset email. If the email is sent successfully, the queue is working.
For production deployments, use Supervisor to keep the worker running.
Create a Supervisor configuration file:
sudo nano /etc/supervisor/conf.d/books-queue.confAdd:
[program:project-name-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/project/artisan queue:work database --sleep=3 --tries=3 --timeout=90
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/path/to/project/storage/logs/queue-worker.logReload Supervisor:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start books-queue:*After every deployment:
php artisan migrate --force
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan queue:restartqueue:restart is important because it signals existing workers to gracefully restart and load the latest application code.
View failed jobs:
php artisan queue:failedRetry all failed jobs:
php artisan queue:retry allFor applications using QUEUE_CONNECTION=database, password reset emails and other queued mail notifications depend on an active queue worker. If no worker is running, jobs will accumulate in the jobs table and will not be processed until a worker starts.