We offer Redis on all our web hosting accounts and Agency services. We run Redis via socket on our servers, thus Laravel needs to be reconfigured to use it for e.g. queue workers (as Laravel usually expects Redis to be run on a specific port).
- Begin by entering that the Predis Composer package is required by the project. I.e., run the following command in the root of your project:
composer require predis/predis
This is needed since the PECL version of phpredis cannot be used to access Redis via socket. - Under the Redis settings in the
config/database.php
file of the project, add the following rows forscheme
andpath
:
'default' => [ 'url' => env('REDIS_URL'), 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', '6379'), 'database' => env('REDIS_DB', '0'), 'scheme' => env('REDIS_SCHEME', 'tcp'), 'path' => env('REDIS_PATH', ''), ], 'cache' => [ 'url' => env('REDIS_URL'), 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', '6379'), 'database' => env('REDIS_CACHE_DB', '1'), 'scheme' => env('REDIS_SCHEME', 'tcp'), 'path' => env('REDIS_PATH', ''), ],
- In your
.env
file for the project, replace all lines beginning withREDIS_*
with the following:
REDIS_CLIENT=predis REDIS_SCHEME=unix REDIS_PATH=/tmp/redis REDIS_PASSWORD=null REDIS_PORT=0
- To use Redis for queue management, update
QUEUE_CONNECTION
toredis
according to the default settings for Redis in Laravel. You can setredis
as bothCACHE_DRIVER
andSESSION_DRIVER
. - Clear the cache for all settings by running
php artisan config:cache
. This will apply the settings according to the instructions above.
If anything is added to the queue, Redis will manage it from now on.