雖然Laravel可以通過安裝predis/predis:~1.1
對Redis進行操作,但是還是想脫離框架,用PHP
操作Reids
,通過安裝PHP Redis
既可實現,以下是具體的安裝步驟:
下載最新安裝包
vagrant@homestead:/usr/local/src$ sudo git clone https://github.com/phpredis/phpredis.git
Cloning into 'phpredis'...
remote: Enumerating objects: 41, done.
remote: Counting objects: 100% (41/41), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 10462 (delta 19), reused 17 (delta 7), pack-reused 10421
Receiving objects: 100% (10462/10462), 6.38 MiB | 31.00 KiB/s, done.
Resolving deltas: 100% (7214/7214), done.
使用phpize命令完成php環境的檢測
vagrant@homestead:/usr/local/src$ cd phpredis/
vagrant@homestead:/usr/local/src/phpredis$ sudo /usr/bin/phpize7.3 #不同php版本的情況下phpize版本不同
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
vagrant@homestead:/usr/local/src/phpredis$ sudo ./configure --with-php-config=/usr/bin/php-config7.3
編譯安裝
vagrant@homestead:/usr/local/src/phpredis$ sudo make && make install
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/lib/php/20180731/
Makefile:87: recipe for target 'install-modules' failed
make: *** [install-modules] Error 1
檢視擴充套件
vagrant@homestead:/usr/local/src/phpredis$ php -i|grep extension_dir
extension_dir => /usr/lib/php/20180731 => /usr/lib/php/20180731
把redis.so擴充套件模組移入PHP擴充套件目錄中
vagrant@homestead:/usr/local/src/phpredis$ sudo mv ./modules/redis.so /usr/lib/php/20180731/
新增PHP配置檔案的ini檔案
建立檔案
vagrant@homestead:/usr/local/src/phpredis$ sudo touch /etc/php/7.3/fpm/conf.d/20-redis.ini
使用vi編輯器寫入如下內容:
extension=redis.so
重啟php-fpm
vagrant@homestead:/usr/local/src/phpredis$ sudo service php7.3-fpm restart
檢視是否安裝成功
<?php
phpinfo();
?>
如果看到Redis的擴充套件則安裝成功
終端無法連線homestead的Reids
1)修改redis配置檔案(預設路徑/etc/redis/redis.conf)
bind 127.0.0.1 修改為 bind 0.0.0.0
2)修改完配置後重啟redis
執行命令sudo service redis restart後,使用redis-cli訪問redis