phpredis errors Class Redis not found in Linux
Asked Answered
R

3

9

I met a weied problem when installing phpredis by

cd phpredis && ./configure && make && make install

after that, I add

extension=redis.so

into php.ini.

I can get an OK by running

php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"

BUT when running http:127.0.0.1, nginx throw a error " Fatal error: Class 'Redis' not found in index.php"

<?php>
    $client = new Redis();
<?>

I guess this may be some problems related with environment...

Thanks for any advice!

Radicalism answered 21/7, 2014 at 6:15 Comment(0)
M
12

The command line probably does not use the same php.ini file than the web server. Use phpinfo(); to know which configuration file is loaded in both cases and then declare your extension in the ini file used by your web server.

Milanmilanese answered 21/7, 2014 at 11:50 Comment(4)
noooo... "Loaded Configuration File" idem with "php -i" and "phpinfo();" And I see "redis" section with "Redis Version" 3 below...Lanark
Sorry, I was drunk, with $r = new \Redis(); (with a backslash) it works. Probably looking the another error line with setOption(Redis::OPT_PREFIX...Lanark
I fixed uncommenting in /etc/php/conf.d/igbinary.ini and /etc/php/conf.d/redis.iniDittography
OMG, thank you so much. I fell so stupid.Crinoline
P
3

I had this issue minutes ago, and I solved it restarting the server, this way the server refresh *.ini files

Pfennig answered 13/4, 2018 at 20:8 Comment(2)
restarting apache did the jobLeo
Restarting apache did the job for me as wellAranyaka
S
0

If you're using composer and get the error "Class Redis not found" try put a backslash before the name class. Like this:

<?php
    $client = new \Redis();
<?
Steadman answered 7/2, 2022 at 3:16 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Eskridge

© 2022 - 2024 — McMap. All rights reserved.