Mac環(huán)境下安裝PhpRedis
首先上項目地址PhpRedis
坑1
自帶PHP和MAMP下的PHP
項目地址中有個brew install php55-redis
安裝方法,剛開始就直接用這個語句安裝,最后發(fā)現(xiàn)不對,這個安裝到的是Mac下自帶的Php版本上了,而我自己使用的是MAMP,所以我只能手動安裝(當然我不知道brew能否指定安裝到MAMP下,希望懂的大佬指點一下)
了解了上面那個坑以后,就簡單了,首先進入/Applications/MAMP/bin/php/php7.1.8
目錄下,這里的7.1.8可以換成你對應的版本目錄,然后依次執(zhí)行以下命令
git clone https://github.com/phpredis/phpredis
cd phpredis
phpize
./configure --with-php-config=/Applications/MAMP/bin/php/php7.1.8/bin/php-config
make
sudo make install
以上命令如果有提示沒有權限,請在命令前方填寫sudo
坑2
執(zhí)行到phpize
的時候會出現(xiàn)如下
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
注意看最后那2行Cannot find autoconf
,剛開始我就沒注意看這個,然后就開始執(zhí)行./configure
就提示./configure: command not found
然后需要安裝一下autoconf
,使用brew install autoconf
安裝,如何安裝brew
請自行搜索額
然后在輸入sudo phpize
$ sudo phpize
Password:
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
就會發(fā)現(xiàn)沒有那行提示了
然后在輸入./
那一堆,就不會提示錯誤了.如下圖
$ ./configure --with-php-config=/Applications/MAMP/bin/php/php7.1.8/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
然后make && make install
編譯即可,如下成功
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /Applications/MAMP/bin/php/php7.1.8/lib/php/extensions/no-debug-non-zts-20160303/
然后還需要在php.ini中最后添加一行代碼extension=redis.so
,然后重啟你的Apache或者Nginx
即可,這里改php.ini也是在MAMP里改
File->Edit Template->PHP(php.ini)
測試
首先打開終端輸入redis-server
啟動redis
(如何安裝redis
也是使用brew
命令brew install redis
)
打開php文件寫代碼
public function index(){
$redis = new \Redis();
$redis->connect('127.0.0.1',6379);
$redis->set('test','測試');
echo $redis->get('test');
exit();
}
接著使用postman
或者直接瀏覽器訪問對應的地址,成功出現(xiàn)測試
至此,安裝phpredis
以及測試都已完成,收工,文中不對的地方還請指出來!