Posts Learn Components Snippets Categories Tags Tools About
/

Installing PHPRedis on MacOS

Learn how to set up / installing PHPRedis on MacOS the easy way

3 years ago

15 mins read

12625 views

When working with Redis in Laravel, they are encouraged to install PHPRedis extension via PECL. This extension is the new recommended over the old predis/predis package as it's no longer maintained and it's more performant.

Installing Laravel Valet

I am making use of Laravel Valet to run my Laravel locally and after a fresh install, I went and right away install Redis using Homebrew (make sure to have it installed).
To install Redis, run the following command.
brew install Redis
Next, make sure to start Redis and restart Laravel Valet.
brew services start redis

valet restart
Now when you run brew services list you will be able to see Redis running on your machine.

Installing PHPRedis

To install PHPRedis we have to use PECL which is a PHP extension repository and to do so run the command below.
pecl install redis
Once it's installed we have to update our php.ini and since we are installing the PHP via Homebrew, the location will be in /usr/local/etc/php/[your-php-version].

Inside the php.ini file, remove extension="redis.so" and we'll have to create ext-redis.ini inside the conf.d directory.

Inside the ext-redis.ini you need to provide the Redis extension path and it will look like below.
[redis]
extension="/usr/local/Cellar/php/[your-php-version]/pecl/[the-installation-date]/redis.so"
Once you have defined that, save it and restart PHP via Laravel Valet valet restart.

Add PHPRedis to your Laravel Application

The next step is to add phpredis into your laravel environment variable and we can do this by defining this config.
REDIS_CLIENT=phpredis
By now you will have the extension and package installed and if you are using Laravel Horizon you can run php artisan horizon and your queue will start being processed.

Update *2 March 2020*


Do note that depending on the version of brew you installed, the location has moved to a different directory.
/opt/homebrew/Cellar/php/[your-php-version]/pecl/[the-installation-date]/redis.so

Alternative Tags

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for Installing PHPRedis on MacOS

)