1.8 KiB
1. Install Redis and PHP Extension
Start by installing Redis and the PHP extension to enable your PHP code to communicate with Redis.
On Debian/Ubuntu:
sudo apt update
sudo apt install redis-server php-redis
Restart your PHP service (e.g., PHP-FPM) to load the extension:
sudo systemctl restart php8.4-fpm
2. Configure the .env File
Modify the following lines in your .env file to tell Laravel to use Redis.
CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis
REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
3. Install and Configure Supervisor
Supervisor is needed to manage your queue workers and automatically restart them on crashes.
sudo apt install supervisor
Create the configuration file for your worker:
sudo nano /etc/supervisor/conf.d/atomcms-worker.conf
Paste the following code into the file and save it. Make sure you use the atomcms path.
[program:atomcms-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/atomcms/artisan queue:work redis --sleep=3 --tries=3 --max-jobs=500
autostart=true
autorestart=true
user=www-data
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/atomcms/storage/logs/worker.log
stopwaitsecs=3600
4. Finalize and Test
Ensure that the logs directory and your entire project have the correct permissions for the www-data user.
sudo chown -R www-data:www-data /var/www/atomcms
Load the Supervisor configuration and start the workers.
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start atomcms-worker:*
You can check the status of your workers with:
sudo supervisorctl status
If you see RUNNING, your setup is correct, and your application is optimally configured.