How to install PHP redis extension on Linux

Before install redis extension in PHP, please make sure that you have installed the redis server and can use PHP related commands on your machine, because we need them later.

  • STEP 1: Installation
# download source code
$ git clone

# enter the source code directory
$ cd phpredis

# phpize is tool for extension installation in php and it will generate compiling environment
$ /path/phpize  --with-php-config=/path/php-config

# compile
$ ./configure

# install
sudo make
sudo make install

when see this below, is means that you have installed it successfully.

Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20180731/
  • STEP 2: modify php.ini and make it work

find your php.ini and add this:


then restart your fpm or apache.

  • STEP 3: Testing

Here is a test php script, run it in your linux server:

    // create a redis instance
	$redis = new Redis();
    // connect redis server, modify your redis server address and port
	$redis->connect('', 6379);
	echo "connect\n";
	echo 'running: ' . $redis->ping();

The script will print this if it works:

$ php redisTest.php
running: pong

Feel free if you have any problem.