How to install Redis on CentOS 6/7

MooseLucifer

Well-known member
Registered
Joined
May 20, 2016
Messages
149
Points
28
Redis fully supports similar functions to Memcached but retrieve and load data faster than memcached.

In this thread, I will guide you to install Redis on CentOS, configure Redis to work on WordPress and Magento.

Instructions for installing Redis

To Redis can work with Magento, we will need to install Redis server with PHP extension, for PhpRedis can connect with Redis.

1. Add repo epel, remi

Code:
## CentOS 7 ##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

## CentOS 6 ##
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
2. Install Redis and PhpRedis extension

Code:
## PHP 5.6 ##
yum --enablerepo=remi,remi-php56 install redis php-pecl-redis
service php-fpm restart

## PHP 5.5 ##
yum --enablerepo=remi,remi-php55 install redis php-pecl-redis
service php-fpm restart
- Start Redis automatically when booting

Code:
chkconfig redis on
service redis start
Check Redis is working or not

1. Check the Redis server

Code:
redis-cli ping
If the result is PONG then ok

2. Check PhpRedis extension

Code:
php -m | grep redis
If the result returned is Redis then ok

3. Redis shell tools

The default, Redis will install with a tool comment is Redis-cli

After launch Redis, you can use some command like:

Code:
FLUSHALL clear all databases
SELECT # select database under index #
FLUSHDB empty currently selected database
KEYS * list all keys from currently selected
See full list of commands here.

Using Redis for WordPress

After the installation is completed and activated Redis service, you just need to install Redis Object Cache plugin, activate it and all done, very simple.

Using Redis with Magento

With Magento, Redis supports different versions. In case your Magento version does not support Redis backend cache or session (or both), you can use extensions to install.

Magento CE >= 1.7.0.0 và < 1.8.0.0
Session storage - not supported
Cache backend non-support, class name after installation is Cm_Cache_Backend_Redis

Magento CE >= 1.8.0.0
Session storage - Support
backed Cache backend, class name after installation is Mage_Cache_Backend_Redis

Magento EE> = 1.13.0.0 and <1.13.1.0
Session storage - not supported
Cache backend - support, class name after installation is Mage_Cache_Backend_Redis

Magento EE> = 1.13.1.0

Session storage - Support
Cache backend - support, class name after installation is Mage_Cache_Backend_Redis

Use Redis as backend cache

To activate Redis , simply edit the file app/etc/local.xml, add the following line into corresponding position to use database 0

Code:
<config>
    <global>
 
        <!-- other configuration nodes -->
 
        <cache>
          <backend>[B]CACHE_BACKEND_CLASS_NAME[/B]</backend>
          <backend_options>
            <server>127.0.0.1</server>              <!-- or absolute path to unix socket -->
            <port>6379</port>
            <persistent></persistent>               <!-- Specify a unique string like "cache-db0" to enable persistent connections. -->
            <database>0</database>
            <password></password>
            <force_standalone>0</force_standalone>  <!-- 0 for phpredis, 1 for standalone PHP -->
            <connect_retries>1</connect_retries>    <!-- Reduces errors due to random connection failures -->
            <read_timeout>10</read_timeout>         <!-- Set read timeout duration -->
            <automatic_cleaning_factor>0</automatic_cleaning_factor> <!-- Disabled by default -->
            <compress_data>1</compress_data>        <!-- 0-9 for compression level, recommended: 0 or 1 -->
            <compress_tags>1</compress_tags>        <!-- 0-9 for compression level, recommended: 0 or 1 -->
            <compress_threshold>20480</compress_threshold>  <!-- Strings below this size will not be compressed -->
            <compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy -->
          </backend_options>
        </cache>
 
        <!-- other configuration nodes -->
 
    </global>
</config>
Replacce CACHE_BACKEND_CLASS_NAME by class name as mentioned above.

After activating Redis, you can delete the entire content of the folder var/cache. To check Redis if it is working or not, run Redis-cli tool, then use the following commands with the database 0

Code:
SELECT 0
KEYS *
Otherwise, you can use phpRedisAdmin to track the status of caching on your web browser.

If you have some thought about using Redis, please write down and I look forward to reading all your reviews about this caching solution.
 
Newer Threads
Latest Threads
Recommended Threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top