centos6.8安裝redis,php-redis擴展
阿新 • • 發佈:2018-04-21
redis phpredis擴展一、安裝redis
下載安裝redis,官網:https://redis.io/download cp redis.conf /usr/local/redis/etc/
cd /usr.local/redis/etc/
vim redis.conf // /opt/app/php/bin/phpize
//或者
//檢查php擴展,出錯的話:bash: phpize: command not found
//yum install php-devel
//我是安裝php56u的所以:yum install php56u-devel
)
C #phpize
Configuring for:
下載安裝redis,官網:https://redis.io/download
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar xzf redis-3.2.8.tar.gz
cd redis-3.2.8
make
沒有報錯的話,redis 就安裝好了。
配置環境變量
echo ‘export PATH=$PATH:/usr/local/redis/bin‘ >> /etc/profile
. /etc/profile
配置 redis.conf
cd redis-3.2.3
// 進入redis 源碼包目錄
mkdir /usr/local/redis/etc/
cd /usr.local/redis/etc/
vim redis.conf
//redis.conf daemonize yes //後臺運行 pidfile /var/run/redis/redis.pid port 6379 tcp-backlog 128 // tcp隊列長度,默認為512,CentOS系統默認為128,此值不應該大於操作系統的該值 logfile "/var/log/redis/redis.log" dir /var/redisdb // redis數據存儲目錄 // 其他參數目前就不需要了 配置redis的服務腳本 useradd -r -s /sbin/nologin -M redis mkdir /var/run/redis mkdir /var/log/redis mkdir /var/redisdb chown redis:redis /var/run/redis chown redis:redis /var/log/redis chown redis:redis /var/redisdb #!/bin/sh #chkconfig: 35 84 16 #Simple Redis init.d script conceived to work on Linux systems #as it does use of the /proc filesystem. . /etc/rc.d/init.d/functions . /etc/sysconfig/network [ "$NETWORKING" = "no" ] && exit 0 REDISPORT=6379 BASEDIR=/usr/local/redis EXEC=$BASEDIR/bin/redis-server CLIEXEC=$BASEDIR/bin/redis-cli PIDFILE=/var/run/redis/redis.pid CONF="$BASEDIR/etc/redis.conf" function start() { if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo -n "Starting Redis server..." daemon --user=redis --pidfile=$PIDFILE $EXEC $CONF #$EXEC $CONF echo fi } function stop() { if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." #$CLIEXEC -p $REDISPORT shutdown killproc -p $PIDFILE $EXEC -INT echo -n "Waiting for Redis saving data & shutdown ." while [ -x /proc/${PID} ] do sleep 1 echo -n "." done echo -e "\nRedis stopped" fi } case "$1" in start) start ;; stop) stop ;; status) status -p $PIDFILE $EXEC ;; restart) stop start ;; *) echo "Please use start or stop as first argument" ;; esac
二、安裝php的redis模塊 phpredis
為什麽要用phpize,我們在安裝php時:
後面的參數是我們要的模塊,但是隨著工作的需要,我們還要在加些模塊,又不想重新編譯php,這些我們就可以
用phpize了。
1.下載phpredis
#wget下載github上的文件
wget https://github.com/nicolasff/phpredis/archive/master.zip
2.開始編譯phpredis擴展
A #unzip master.zip
B #解壓後進入 cd phpredis-master
(#phpize 執行此命令
//I,先find / -name ‘phpize‘ ,如果找到就完成命令執行如
//或者
//檢查php擴展,出錯的話:bash: phpize: command not found
//yum install php-devel
//我是安裝php56u的所以:yum install php56u-devel
)
C #phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20050922
Zend Extension Api No: 220051025
D config配置
#./configure --with-php-config=/usr/local/bin/php-config (此目錄為php安裝的php-config,find找下)
make
make install
成功後出現:
Installing shared extensions: /usr/lib/php/modules/
#ls /usr/lib/php/modules/
dbase.so ldap.so pdo.so pdo_sqlite.so phpcups.so redis.so snmp.so
有需要的模塊名稱說明安裝完畢
3.安裝配置phpredis擴展
修改php.ini配置文件
vim /etc/php.ini (找到php安裝目錄下這個配置文件)
extention="redis.so"
//添加這一行擴展配置
4, 重啟php-fpm服務
service php-fpm restart
5 .測試擴展庫是否正常運行
//在git clone下來的phpredis文件夾
php tests/TestRedis.php --class Redis
centos6.8安裝redis,php-redis擴展