23

Can anyone help me install php-redis in MAC OSX .

brew install php-redis

not working.

pecl install php-redis

also not working getting -

invalid package name/package file "php-redis".

Homebrew Error:

homebrew_error

Ankit Jain
  • 473
  • 1
  • 4
  • 17
  • 4
    It'd be `pecl install redis`, and "not working" is pretty vague. Give us the errors/difficulties you encountered and maybe we can help with the Homebrew side. – ceejayoz Aug 18 '18 at 11:21
  • Hi i have inserted homebrew install problem in image here : https://i.stack.imgur.com/jJgg7.png I need to install php-redis . Already install redis with : brew install redis which is working fine. – Ankit Jain Aug 18 '18 at 11:38
  • See here but adapt for Redis https://stackoverflow.com/a/50529784/2836621 – Mark Setchell Aug 18 '18 at 12:12
  • 1
    `pecl help` is useful to discover `pecl search` which is useful , like : `pecl search edis` would have given you the answer you are looking for. – YvesLeBorg Aug 18 '18 at 13:48
  • @MarkSetchell point where you wrote " brew options this", there is no options for php-redis. – Ankit Jain Aug 19 '18 at 07:10
  • Exactly, that's what I am saying. There is no `php-redis` any more, that's why you cannot do `brew install php-redis` nor `brew options php-redis`. You need to use `pecl` to install Redis and make it known to PHP. – Mark Setchell Aug 19 '18 at 07:17

3 Answers3

60
git clone https://www.github.com/phpredis/phpredis.git
cd phpredis
phpize && ./configure && make && sudo make install

Add extension=redis.so in your php.ini

brew services restart php@7.2
make test

You can check working or not

php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"
Nanhe Kumar
  • 14,282
  • 3
  • 74
  • 66
36

As of 2019, with homebrew php7.2 and up, pecl is now installed by default alongside the php binaries.

To see this for yourself type which pecl.

Steps to install

  1. Check your version of redis, then find a suitable version of the extension here.

  2. If unfamiliar with pecl, type pecl to see the options.

  3. Issue pecl install redis-5.0.2. (or your version). Enter no to each question asked if you're not sure.

  4. If that succeeds check the new file it created at: /usr/local/lib/php/pecl/20180731/redis.so

  5. The install will have added extension="redis.so" to top of your php ini. Check that by opening the file /usr/local/etc/php/7.3/php.ini. (assuming you're on 7.3 there)

  6. brew services restart php.

  7. php -i | grep Redis

Redis Support => enabled
Redis Version => 5.0.2

This is what I just did in September 2019 and it works for me.

mwal
  • 2,435
  • 22
  • 32
4

If what mwal wrote above doesn't work (please try his/her answer first),

first, try to uninstall first (if you have it but broken):

sudo pecl uninstall redis 

and after that run:

sudo pecl install redis

After that, ini the php.ini, use full path for the extension.

Mine was /usr/local/Cellar/php@7.3/7.3.21/pecl/20180731/redis.so (assuming you are using php@7.3)

so at the top of my php.ini file is like this:

extension="/usr/local/Cellar/php@7.3/7.3.21/pecl/20180731/redis.so"
Abdul Rahman A Samad
  • 1,011
  • 15
  • 20