以前一直遇到,Module compiled with module API=20090626這個坑問題!!!php
NOTICE: PHP message: PHP Warning: PHP Startup: redis: Unable to initialize module Module compiled with module API=20090626 PHP compiled with module API=20131226 These options need to match in Unknown on line 0
當服務器中安裝了2個以上的php環境時會出現以上錯誤,這是因爲phpize編譯的版本不一致html
問題詳解,然並卵。。。http://blog.csdn.net/justin_bkdrong/article/details/46738629nginx
改extension_dir,效果不明顯。。。https://segmentfault.com/q/1010000000603251git
後來按照下面的步驟安裝成功!!!github
開始在 PHP 中使用 Redis 前, 咱們須要確保已經安裝了 redis 服務及 PHP redis 驅動,且你的機器上能正常使用 PHP。 接下來讓咱們安裝 PHP redis 驅動:下載地址爲:https://github.com/phpredis/phpredis/releases。redis
$ wget https://github.com/phpredis/phpredis/archive/2.2.4.tar.gz
如下操做須要在下載的 phpredis 目錄中完成:shell
$ cd phpredis-2.2.7 # 進入 phpredis 目錄 $ /usr/local/php/bin/phpize # php安裝後的路徑,寫全phpize的路徑
$ ./configure --with-php-config=/usr/local/php/bin/php-config $ make && make install #配置時 要將php-config的路徑附上
若是你是 PHP7 版本,則須要下載指定分支:apache
git clone -b php7 https://github.com/phpredis/phpredis.git
vi /usr/local/php/lib/php.ini
增長以下內容:segmentfault
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20090626" extension=redis.so
安裝完成後重啓php-fpm 或 apache。查看phpinfo信息,就能看到redis擴展。服務器
cd /usr/local/nginx/html touch redis.php vi redis.php
編輯
<?php //鏈接本地的 Redis 服務 $redis = new Redis(); $redis->connect('127.0.0.1', 6379); echo "Connection to server sucessfully"; echo "Server is running: " . $redis->ping(); //設置 redis 字符串數據 $redis->set("tutorial-name", "Redis tutorial"); // 獲取存儲的數據並輸出 echo "Stored string in redis:: " . $redis->get("tutorial-name"); ?>
保存,!wq
X-shell新建一個鏈接,開啓redis服務
/usr/local/src/redis-3.0.6/src/redis-server
訪問 IP/redis.php
參考:http://www.runoob.com/redis/redis-php.html