Centos7 offline installation of redis and PHP extension redis

Linux install redis
Redis related packages

Phpredis – 2.2.4. Tar. Gz


Redis – 4.0.6. Tar. Gz

Link: https://pan.baidu.com/s/1eSOwqhO password: af4c

1. Unzip, compile and install tar-Zxvf Redis-4.0.6.tar.gz

CD redis – 4.0.6/SRC


make install

2. You can see some green files when moving ls redis-4.0.6/ SRC

mkdir -p /usr/local/redis/etc ###etc has a storage configuration file

mkdir -p /usr/local/redis/bin ###bin is used to store commands

Copy redis.conf under redis.4.0.6 to /usr/local/redis/etc/

cp ../redis. Conf/usr/local/redis/etc /

copy the green file under redis-4.0.6/ SRC folder to /usr/local/redis/bin

cp green file name /usr/local/redis/bin/



3. Start redIS service. Starting the RedIS service requires the command Redis-server./ Redis-server

Warning: no config file specified,

after the termination

/redis server/usr/local/redis/etc/redis. Conf

now redis is running in the foreground

redis runs in the background

vi /usr/local/redis/etc/redis.conf

search: /daemonize

changes the daemonize configuration entry to yes

save exit

./redis-server /usr/local/redis/etc/redis.conf

ps -ef | grep redis

pstree -p | grep redis ## tree display

netstat – NTLP | grep 6379 ### port

[[email protected] bin]$ /usr/local/redis/bin/redis-cli & gt;// hint

indicates successful client login

4. Join systemctl configure redis vi/usr/lib/systemd/system/redis. Service







ExecStart =/usr/local/redis/bin/redis server/usr/local/redis/etc/redis. Conf – daemonize no

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop =/usr/local/redis/bin/redis – cli – h – p 6379 shutdown




save exit

systemctl daemon-reload

systemctl start redis

systemctl enable redis

systemctl is-enabled redis

if an error occurs

systemctl enable redis

Failed to execute operation: Bad message

Please check the/usr/lib/systemd/system/redis. Service file

5. Install the PHPREdis-Develop.zip extension if you have PHP installed

download address: https://github.com/phpredis/phpredis/archive/develop.zip

unzip phpredis – develop. Zip

cd phpredis-develop


./configure –with-php-config=/usr/local/php7/bin/php-config


(see result: Don’t forget to run ‘make test’. That is success.)

make install

(see the results as follows: Installing Shared extensions:/usr/local/php7/lib/PHP/extensions/no – debug – non – ZTS – 20160303 /


: Shared extensions, has generated the dynamic link library file redis. So.

can check if there is redis.so

ls/usr/local/php7/lib/PHP/extensions/no – debug – non – ZTS – 20160303 /

file redis.so path




three files are the same file

Configure php.ini to add after extension


restart PHP

Test redis CD

vi test.php

< ?php

$redis = new redis();

$redis-> The connect (‘, 6379);

echo ‘Connection to server successfully’;

echo ‘Server is running:’ . $redis-> ping();


to perform the test. The PHP

php test.php

in case of Fatal error: Uncaught error: Class ‘redis’ not found

may be because running the PHP command and apache or ngnix may use a different php.ini. Even if you see redis loaded in php.ini, you also need to add redis module in php.ini to the PHP command line.


1. View phpinfo in php.ini location

2. Search the php.ini file location

3. Cp/usr/local/php7/etc/PHP ini/usr/local/php7/lib/PHP ini
4. Restart php-fpm nginx redis

5. Execute test.php

[[email protected] /]# php test.php

Connection to server successfullyServer is running:+PONG[[email protected] /]#

php -m | grep redis

Read More: