1. 程式人生 > >mac 下安裝redis擴充套件

mac 下安裝redis擴充套件

    在php中使用redis的時候可能會報 ‘redis’ class not found的錯誤,這是因為沒有安裝redis擴充套件導致的,以下步驟是在mac下安裝phpredis的過程:

1.下載phpredis原始碼

使用git下載phpredis的包,git地址:https://github.com/nicolasff/phpredis

  1. git clone https://github.com/nicolasff/phpredis.git

2.安裝phpredis

進入包中並執行phpize命令 

  1. cd phpredis-master

  2. phpize

出現以下畫面表示成功


編譯並執行安裝

  1. ./configure --with-php-configure=/usr/bin/php-config

  2. make

  3. make install


當出現以下畫面時表示安裝成功:

3.配置php擴充套件

開啟php.ini檔案,在最後新增以下內容,並重啟服務

  1. extension=redis.so


4.檢查安裝是否成功

  1. php -m | grep redis

如果出現redis,則說明安裝成功。

5.可能出現的問題

5.1 執行phpize時可能會出現以下錯誤:

  1. grep: /usr/include/php/main/php.h: No such file or directory

  2. grep: /usr/include/php/Zend/zend_modules.h: No such file or directory

  3. grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory

  4. Configuring for:

  5. PHP Api Version:

  6. Zend Module Api No:

  7. Zend Extension Api No:


解決方案:

  1. sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/include

5.2執行phpize時可能出現錯誤:

  1. Cannot find autoconf

    .Please check your autoconf installation and the

  2. $PHP_AUTOCONF environment variable.Then, rerun this script.

這是因為phpize對autoconf有依賴,需要安裝autoconf,使用brew工具進行安裝

  1. brew install autoconf