+91 88 00 563434 [email protected] Blog open-book Knowledge Base

Find Solutions in Our Knowledge Base

Install Redis and Redis-PHP in DirectAdmin

You are here:
Sharing is Caring

 

Redis

Redis is a system for managing databases. It is commonly used as a message broker, cache, and in-memory data structure store. It is often referred to as a data structure server, where keys can contain strings, hashes, lists, sets, and sorted sets. Redis is written in ANSI C and runs in most POSIX systems. We can perform atomic operations on these data types, such as computing set intersection, appending to a string, pushing an element to a list, and incrementing the value in a hash.

 

Install Redis

1) Connect to the server via SSH.

#ssh [email protected] -p xxxx

2) Open a screen session using the following command.

#screen -U -S name

3) Ensure that your server is up-to-date by running the following command.

#yum update

4) Install the redis package using:

#yum install redis

5) Now the system will install redis and start the daemon.

#service redis start

6) Configure Redis to automatically start on boot.

#chkconfig redis on

7) Test if redis is up and running on the system by using the following command.

#redis-cli MONITOR

 

Configure Redis

Configure some basic persistence and tuning options for redis.

1) Set the following values for the appendonly and appendfsync settings in redis.conf.

#vi /etc/redis.conf

appendonly yes

appendfsync everysec

2) Restart redis.

#service redis restart

It is necessary to set the Linux kernel overcommit memory setting to 1.

In /etc/sysctl.conf, add vm.overcommit_memory = 1  and then reboot or run the command sysctl vm.overcommit_memory=1 for this to take effect immediately.

Make sure to set up some swap space on your system (we recommend as much swap as memory). This is because if the Redis instance accidentally consumes too much memory and your system doesn’t have enough swap space, either the Redis will crash or the Redis process will be killed by the Linux kernel OOM killer.

 

Install Igbinary

We can use Igbinary instead of the standard php serializer because Igbinary is a drop-in replacement for the standard php serializer. Igbinary stores php data structures in a compact binary form rather than saving as a textual representation, which consumes more time and space. When using Memcached or similar memory-based storages for serialized data, the savings are significant. The storage use can be reduced by 50%.

 

1) Install Igbinary via pecl.

#pecl install igbinary igbinary-devel

2) Install the Redis PHP extension.

# cd /opt/

# wget https://github.com/nicolasff/phpredis/tarball/0ae592b

# tar xzvf 0ae592b

# rm -f 0ae592b

# cd phpredis-phpredis-0ae592b/

# /usr/local/bin/phpize

# ./configure –enable-redis-igbinary –with-php-config=/usr/local/bin/php-config

# make -j 4

# make install

 

Configure PHP for Redis-PHP

1) Add the following extensions to /usr/local/lib/php.ini.

# vi /usr/local/lib/php.ini

extension=igbinary.so

extension=redis.so

2) Restart Apache web server.

# service httpd restart

3) Check whether it’s loaded in the PHP :

# php -m | grep -E ‘redis|igbinary’

 

If you need any further assistance, please contact our support department.

 


Sharing is Caring

Leave a Comment

Table of Contents