Content Index
In this post, we will see how to install Redis for development in Laravel, whether you want to use it for the cache system, the queue and job system, etc.
Windows, MacOS with Dbngin and Laravel Herd
If you are using Laravel Dbngin on MacOS/Windows along with Laravel Herd, you can create a database while preserving the default configuration:
Laragon on Windows
If you use Laragon, you need to configure a DLL according to the version you are using; more information on the official Laragon forum:
https://dev.to/dendihandian/installing-php-redis-extension-on-laragon-2mp3
You must download the Windows DLL according to the version you are running, NTS or TS and your PHP version; in my case, it is NTS:
Download the DLL from:
https://pecl.php.net/package/redis
Then copy the DLL into the PHP version you are running in Laragon; for example:
C:\laragon\bin\php\php-8.XX-nts-Win32-vs16-x64\ext
And activate the extension:
In Laragon, Redis comes installed by default. Previously, we configured the DLL or database connector to run the Redis database:
C:\laragon\bin\redis\redis-x6XX\redis-server.exe
And you will see a window like the following:
Which indicates that Redis is running and ready to use; likewise, you can test the status of redis by running:
$ redis-cliIf you see a message like the following:
Could not connect to Redis at 127.0.0.1:6379: A connection could not be established because the target machine expressly denied it.
not connected>
It means you have issues with the execution of the database engine.
You can also run:
$ redis-cli$ 127.0.0.1:6379> pingAnd you should see as output:
PONG
On Linux:
$ sudo apt-get install redis php8.3-redis
$ sudo systemctl restart php8.3-fpm.serviceAdditional Configurations
It might be necessary to install the Predis package to your Laravel project via Composer:
$ composer require predis/predisWhich is the client or connector so you can use Redis in Laravel. To use Redis for the database, it shouldn't be necessary, so only install it if needed.
In case you want to change any redis configuration parameter, you can specify it in the following way:
.env
REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379Indicate the connection options to Redis (just like with any other database):
config/database.php
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
'cache' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
],
];config\cache.php
'redis' => [
'driver' => 'redis',
'connection' => env('REDIS_CACHE_CONNECTION', 'cache'),
'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'),
],Finally, we configure the connector to be Redis either in the .env:
.env
CACHE_STORE=redisAnd/or configuration file:
config\cache.php
'default' => env('CACHE_STORE', 'redis')And that would be all; by changing the cache system, it is independent of the implementation we are going to perform.