Install phpredis MAC OSX
Asked Answered
G

7

40

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

Geisler answered 18/8, 2018 at 11:13 Comment(6)
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.Urey
Hi i have inserted homebrew install problem in image here : i.sstatic.net/jJgg7.png I need to install php-redis . Already install redis with : brew install redis which is working fine.Geisler
See here but adapt for Redis https://mcmap.net/q/393426/-homebrew-install-new-formula-php72-imagickDivinity
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.Nightshirt
@MarkSetchell point where you wrote " brew options this", there is no options for php-redis.Geisler
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.Divinity
H
83
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 [email protected]
make test

You can check working or not

php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"
Hypercatalectic answered 22/10, 2018 at 8:38 Comment(5)
hi, this is a good guide to install phpredis, but where should i put phpredis directory ?Rosalie
@Rosalie : you can download in Download folderHypercatalectic
if it doesn't work for you on OSX Mojave, this guy is your friend: https://mcmap.net/q/21856/-can-39-t-compile-c-program-on-a-mac-after-upgrade-to-mojaveImmoderation
It's work when I have put the complete path or redis.so in my php.iniUnmindful
I have update [email protected] again repeat above steps and working fineHypercatalectic
S
55

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.

Staub answered 22/9, 2019 at 15:48 Comment(6)
Also after upgrading to PHP 7.4, I had to reinstall redis ext with pecl: pecl uninstall redis, then pecl install redisSansbury
Worked for me as well for PHP 7.3. ThanksSpanishamerican
If you get: Warning: mkdir(): File exists in System.php on line 294 error, run pecl config-get ext_dir | pbcopy, then mkdir -p {paste clipboard value}, then sudo pecl install redis-5.3.2Soapwort
pecl install redis was not working for me without sudo: superuser.com/a/1707730/79629Seeseebeck
If the extension isn't loading; in my case pecl installed redis.so in a different location. pecl install redis-x outputs this. After updating the top line in the php.ini file to the correct location the extension loaded correctly.Gasperoni
Just a note here that the install may not add the line extension=redis.so to php.ini, if its not in the default location, so you may need to aad it manually. Here is what the install says after installing configuration option "php_ini" is not set to php.ini location You should add "extension=redis.so" to php.iniBocock
T
12

If what mwal wrote above doesn't work (please try their 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/[email protected]/7.3.21/pecl/20180731/redis.so (assuming you are using [email protected])

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

extension="/usr/local/Cellar/[email protected]/7.3.21/pecl/20180731/redis.so"
Tuppence answered 7/10, 2020 at 3:51 Comment(0)
H
4

If someone gets an error during sudo pecl install redis

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

PHP Warning: mkdir(): File exists in /opt/homebrew/Cellar/-----/pear/System.php on line 294

that means you need to create the broken directory manually. Try to create the directory...

pecl config-get ext_dir | pbcopy
mkdir -p {paste clipboard value}
# in my case, it was
mkdir -p /opt/homebrew/lib/php/pecl/20200930

Now try to install any pecl extensions.

sudo pecl install redis

After installing any extension, restart php

brew services restart php

Happy coding :)

Heulandite answered 4/2, 2023 at 3:4 Comment(1)
This is what I needed for installing on my machine. Thank you!Bicollateral
H
2

Here are steps to use pickle, for PHP >= 7.3 (tested with 8.1):

  1. brew install pickle
  2. pickle install redis
  3. Find your php.ini location via php -i|grep php.ini
  4. Edit the php.ini, insert extension=redis. Preferable at Dynamic Extensions section.
  5. No restart of Apache httpd service is required. You may test your PHP code with Redis

Bonus

If you use VS Code, to enable intellisense / auto complete, at Preference -> paste intelephense.stubs at Search setting box -> Add Item -> select redis.

Holt answered 27/10, 2022 at 3:33 Comment(1)
amazing.. working with PHP 8.2Laine
E
0

If you got the following error,

Please make sure the PHP Redis extension is installed and enabled

despite doing everything in the verified answer above, try valet restart . It worked for me

Etymology answered 14/7, 2022 at 21:2 Comment(0)
R
0

I have tried all these solutions but didn't work for me for a while so I tried this link https://developer.redis.com/develop/php/ from the original docs and it works as charm

Rudder answered 29/10, 2022 at 2:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.