Home / Tutorials / Installing PHPRedis on MacOS
Installing PHPRedis on MacOS cover

Installing PHPRedis on MacOS

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

15 mins

12.7K

3 years ago

1 comments

Beginner

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
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

A

Alaz

3 months ago

Loving this redis tutorial!

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this