環境: centos7 PHP7
1.切到準備安裝的目錄
cd /usr/local
2.下載Redis
wget http://download.redis.io/redis-stable.tar.gz
3.解壓
tar -zxf redis-stable.tar.gz
4.編譯
make
5.休息十秒鐘
6.進入src目錄
cd src
7.編譯檢查
make test
8.安裝
make install
9.切到外層將目錄改名
cd /usr/local
mv redis-stable redis
10.修改配置
vi redis/redis.conf
搜尋daemonize 改為 daemonize yes (是否守護程式)
搜尋pidfile 改為 pidfile /usr/local/redis/redis.pid
搜尋logfile 改為 logfile /usr/local/redis/redis.log
搜尋save 60 10000 改為 save 60 1000
搜尋#maxmemory <bytes> 改為 maxmemory 256M (最大允許使用記憶體)
遠端連線配置:
bind 127.0.0.1 改為 #bind 127.0.0.1 (註釋掉)
protected-mode yes 改為 protected-mode no
requirepass yourpassword (密碼)
11.啟動Redis
/usr/local/redis/src/redis-server
12.開機啟動
vi /etc/init.d/redis
輸入以下內容 路徑換成實際路徑:
#!/bin/bash
# chkconfig: 2345 10 90
# description: Start and Stop redis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis/src/redis-server
REDIS_CLI=/usr/local/redis/src/redis-cli
PIDFILE=/usr/local/redis/redis.pid
CONF="/usr/local/redis/redis.conf"
AUTH="1234"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed."
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE exists, process is not running."
else
PID=$(cat $PIDFILE)
echo "Stopping..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
sleep 2
while [ -x $PIDFILE ]
do
echo "Waiting for Redis to shutdown..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
儲存退出:wq
給個許可權:chmod 755 /etc/init.d/redis
13.開啟服務
/etc/init.d/redis start
如果看到以下資訊則成功
Starting Redis server...
Redis is running...
14.啟動客戶端:
/usr/local/redis/src/redis-cli
用一下set get
儲存資料正常
15.設定開機自啟
chkconfig redis on
安裝Redis擴充套件
16.下載地址:
https://github.com/phpredis/phpredis
用ftp傳到Linux (或者是右鍵點選 Download ZIP 按鈕 複製連結 使用wget直接下載)
17.移動到準備安裝的目錄
mv develop.zip /usr/local/develop.zip
18.解壓
unzip develop.zip
19.進入目錄中
cd phpredis-develop
20.執行PHP安裝目錄下的phpize
/usr/local/php7/bin/phpize
21.報錯資訊:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
解決辦法:
yum install m4
yum install autoconf
再次執行phpize:
/usr/local/php7/bin/phpize
22.搜尋php-config路徑
find /usr/local/php7/ -name php-config
得到/usr/local/php7/bin/php-config
23.配置
./configure --with-php-config=/usr/local/php7/bin/php-config
24.編譯
make
25.安裝
make install
出現如下結果:
26.編輯php.ini
vi /usr/local/php7/etc/php.ini
在一排extension的地方加入:
extension=redis.so
27.重啟Apache
systemctl restart httpd
若是Nginx
殺掉php-fpm程式
ps -ef | grep php-fpm
kill -9 ***
重新啟動php-fpm
/usr/local/php7/sbin/php-fpm -c /usr/local/php7/etc/php.ini
28.新建PHP檔案執行phpinfo()
搜尋有無Redis擴充套件
29.執行以下程式碼 如果存取正常 則安裝成功
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->set("name", "hello world");
echo $redis->get("name");
感謝閱讀