redis_php

Many applications such as Laravel rely on Redis for tasks, so having a local Redis instance running for local development is a great idea. But in order to best communicate with Redis you will need the PHPRedis package installed locally. I ran into a handful of problems getting it installed locally, here is the best steps I learned.

If you have installed PHP, or an updated version of it locally via Homebrew you should already have PECL installed so to start off installing the PHPRedis extension is as easy as:

pecl install redis

You may run into the follow error at this step:

Warning: mkdir(): File exists in System.php on line 294

Warning: mkdir(): File exists in ↵
/usr/local/Cellar/php/7.4.8/share/php/pear/System.php on line 294
ERROR: failed to mkdir /usr/local/Cellar/php/7.4.8/pecl/20190902

If so the fix is simple. Simply back up the offending symlink /usr/local/Cellar/php/7.4.8/pecl to somewhere else and delete it for now:

rm /usr/local/Cellar/php/7.4.8/pecl

Note, your php version may be different so that file pathing would be dependent on your local version rm /usr/local/Cellar/php/7.4.8/pecl

After PECL successfully installs PHPPredis you should see something similar to the following:

Build process completed successfully
Installing '/usr/local/Cellar/php/7.4.8/pecl/20190902/redis.so'
install ok: channel://pecl.php.net/redis-5.3.1
Extension redis enabled in php.ini

Keep not of that "Installing" path for later

Next you will need to remove the following line from your php.ini file:

extension="redis.so"

To find your php.ini's location you can run php --ini and it should be listed as "Loaded Configuration File". The line you need to remove should be right at the top.

Next create the file /usr/local/etc/php/7.4/conf.d/ext-redis.ini (Again keep in mind your PHP version may be different) and add the following content to it:

[redis]
extension="/usr/local/Cellar/php/7.4.8/pecl/20190902/redis.so"

Note that the extension is the "Installing" path we noted down earlier.

Finally, restart PHP with brew services restart php and you should be all set!

To test that everything works run php -i | grep Redis and you should see an output like:

Redis Support => enabled
Redis Version => 5.0.2

Good luck out there!