Setting up Redis Server and PHP Extension

Installing Redis

Extract the Redis package in the /usr/local/src directory:

tar -zxvf redis-4.0.8.tar.gz
cd redis-4.0.8
make MALLOC=libc

Install Redis binaries to /usr/local/bin:

cd src && make install

Starting Redis Server

Redis can be started in three different ways:

Foreground Mode

cd src
./redis-server

This method requires keeping the terminal window open, which is not ideal.

Background Mode

To run Redis in the background:

  1. Edit the redis.conf file and change:
daemonize no

to:

daemonize yes

  1. Move Redis to a project directory and start with configuration:
cp -r /usr/local/src/redis-4.0.8 /usr/local/redis
cd /usr/local/src/redis-4.0.8 && ./redis-server /usr/local/redis/redis.conf

  1. To stop Redis, find the process ID and kill it:
ps -aux | grep redis
kill -9 [process_id]

Configuring Auto-start on Boot

Create a Redis directory under /etc:

mkdir /etc/redis

Copy the Redis configuration file:

cp /usr/local/redis/redis.conf /etc/redis/6379.conf

Copy the Redis init script:

cp /usr/local/redis/utils/redis_init_script /etc/init.d/redisd

Add required metadata to the init script by editing /etc/init.d/redisd and inserting these lines after the shebang:

# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database

Enable auto-start:

cd /etc/init.d
chkconfig redisd on

Control the service using:

service redisd start
service redisd stop

Installing PHP Redis Extension

Download and extract the extension:

cd /usr/local/src
wget https://github.com/nicolasff/phpredis/archive/3.0.0.tar.gz
tar -zxvf 3.0.0.tar.gz
cd phpredis-3.0.0

Generate the configure script using phpize:

/usr/local/php/bin/phpize

If you encounter an error about missing autoconf, install dependencies:

cd /usr/local/src
wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
tar -zvxf m4-1.4.9.tar.gz
cd m4-1.4.9/
./configure && make && make install

cd ../
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
tar -zvxf autoconf-2.62.tar.gz
cd autoconf-2.62/
./configure && make && make install

Rerun phpize:

cd /usr/local/src/phpredis-3.0.0
/usr/local/php/bin/phpize

Configure, compile, and install:

./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

Enable the extension in PHP configuration:

echo 'extension=redis.so' >> /usr/local/php/etc/php.ini

Restart web server:

systemctl restart nginx

Tags: Redis PHP Linux server-configuration database

Posted on Sat, 16 May 2026 21:04:03 +0000 by rochakchauhan