Posts Learn Categories Tags About
Installing PHPRedis on MacOS cover

Installing PHPRedis on MacOS

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

6 months ago

15 mins read


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="" 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.

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.

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.