1、解壓源碼包
tar -zxvf phpredis.tar.gz
2、phpize
ann@AnnS:phpredis$ phpize //如果未安裝,它會提示對應命令安裝
3、./confure | make | make install
編譯成功後,會有redis.so擴展包文件。
4、添加配置
在php.ini中修改
extension_dir = "redis.so文件所在路徑"
extension = "redis.so"
5、重啓apache
service apache2 restart
安裝成功的話,phpinfo() 裏會看到 redis 插件。
6、測試
<?php
$redis = new $Redis();
$host = '127.0.0.1';
$port = 6379';
$redis->connect($host, $port);
$redis->set('linux', 'linux testing');
$data = $redis->get('linux');
echo $data;