mac 下安裝redis擴充套件
在php中使用redis的時候可能會報 ‘redis’ class not found的錯誤,這是因為沒有安裝redis擴充套件導致的,以下步驟是在mac下安裝phpredis的過程:
1.下載phpredis原始碼
使用git下載phpredis的包,git地址:https://github.com/nicolasff/phpredis
git clone https://github.com/nicolasff/phpredis.git
2.安裝phpredis
進入包中並執行phpize命令
cd phpredis-master
phpize
出現以下畫面表示成功
編譯並執行安裝
./configure --with-php-configure=/usr/bin/php-config
make
make install
當出現以下畫面時表示安裝成功:
3.配置php擴充套件
開啟php.ini檔案,在最後新增以下內容,並重啟服務
extension=redis.so
4.檢查安裝是否成功
php -m | grep redis
如果出現redis,則說明安裝成功。
5.可能出現的問題
5.1 執行phpize時可能會出現以下錯誤:
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
解決方案:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/include
5.2執行phpize時可能出現錯誤:
Cannot find autoconf
$PHP_AUTOCONF environment variable.Then, rerun this script.
這是因為phpize對autoconf有依賴,需要安裝autoconf,使用brew工具進行安裝
brew install autoconf