Php – How to install Predis

apache-2.2PHPredis

I am trying to install Predis, but keep getting a 500 Server errror. Here is what I have done.

1.) Have apache and php installed on Ubuntu Natty.

2.) Used the instructions on this page http://redis.io/download to download Redis.

3.) Ran the following example to confirm that Redis is working:

$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

4.) Have a local website at /home/user/Dropbox/documents/www/mywebsite.com/index.php and have confirmed that php is working.

5.) Downloaded the .zip version of Predis ( https://github.com/nrk/predis Version: v0.6.6-PHP5.2 ), and unzipped the contents to /home/user/Dropbox/documents/www/mywebsite.com/. So now Predis is here: /home/user/Dropbox/documents/www/mywebsite.com/nrk-predis-3bf1230/

6.) Opened the /home/user/Dropbox/documents/www/mywebsite.com/index.php page. Here is its contents:

<?
define("PREDIS_BASE_PATH", "nrk-predis-3bf1230/lib/");
spl_autoload_register(function($class) {
$file = PREDIS_BASE_PATH.strtr($class, '\\', '/').'.php';
 if (file_exists($file)) {
require $file;
 return true;
 }
 });
 $redis = new Predis_Client();
 $redis->set('foo', 'bar');
 $value = $redis->get('foo');
 ?>

I have tried changing:

$redis = new Predis_Client();

to:

$redis = new Predis\Client();

Have tried changing the the PREDIS_BASE_PATH to:

/nrk-predis-3bf1230/lib
/home/user/Dropbox/documents/www/mywebsite.com/nrk-predis-3bf1230/lib/
/home/user/Dropbox/documents/www/mywebsite.com/nrk-predis-3bf1230/lib

Have done a chmod +x on both:

/home/user/Dropbox/documents/www/mywebsite.com/nrk-predis-3bf1230/
/home/user/Dropbox/documents/www/mywebsite.com

And doing all of the above always results in a 500 server error.

What am I doing wrong?

Best Answer

When using Predis v0.6.x you just need to pick the file lib/Predis.php from the zip and require() it in your scripts. Autoloading is not needed with versions of Predis prior to v0.7.0-dev, which is the current development version of the library in the master branch of the git repository.