Toll Free 88808-24000 sales@treewalkerlabs.com

In the previous post “Install Redis on Amazon EC2 Server” we had seen the process to install Redis on the server. In this article we will see how to integarte the Redis with Magento1.x

There are few php extension we need to install before we do integration with Magento. In my case my php version is 5.6.x.

PhpRedis - PHP extension from Nicolas Favre-Felix, which allows to access to Redis from php. This extension we need to install.

To install the above extension we need to make sure that pear library is installed. To install pear below are the steps :
yum install php-pear

Install necessary packages
yum install php56-devel // This is applicable if you having PHP 5.6 version

Now to install phpRedis we need to download the package
cd /usr/local/src
sudo wget https://github.com/phpredis/phpredis/archive/master.zip -O phpredis.zip
sudo unzip phpredis.zip
cd phpredis
sudo phpize && sudo ./configure && sudo make && sudo make install

After the installation is complete we need to enable the Redis extension in the php.ini . Using phpinfo you can get to know where is your php.ini and other extensions ini files are located.
In my case the php extension ini files are located this path /etc/php-5.6.d/. create a file by name redis.ini and add the extension in that


sudo vi /etc/php-5.6.d/redis.ini

Add the below line code to it and save

extension=redis.so

Configure Magento1.9.x with Redis
Go to your magento root and open the below file
sudo vi app/etc/modules/Cm_RedisSession.xml

Enable it by setting active to true

<config>
<modules>
<Cm_RedisSession>
<active>true</active>
<codePool>community</codePool>
</Cm_RedisSession>
</modules>
</config>

Then, edit the ‘local.xml’ file located in magento directory

vi /magento-root-dirrectory/app/etc/local.xml


<global>

<cache>

<backend>Cm_Cache_Backend_Redis</backend>

<backend_options>

<server>127.0.0.1</server> <!– or absolute path to unix socket –>

<port>6379</port><port>6379</port>

<persistent></persistent> <!– Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 –>

<database>0</database> <!– Redis database number; protection against accidental data loss is improved by not sharing databases –>

<password></password> <!– Specify if your server requires authentication –>                            <force_standalone>0</force_standalone>  <!– 0 for phpredis, 1 for standalone PHP –> <connect_retries>1</connect_retries>    <!– Reduces errors due to random connection failures; a value of 1 will not retry after the first failure –>           <read_timeout>10</read_timeout>         <!– Set read timeout duration; phpredis does not currently support setting read timeouts –>

<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, lz4 (as l4z) and snappy –> <use_lua>0</use_lua> <!– Set to 1 if Lua scripts should be used for some operations –>

<backend_options>

</cache>

<!–session_save><![CDATA[files]]></session_save–>

<session_save>db</session_save>

<redis_session>

<host>127.0.0.1</host>

<port>6379</port>

<password></password> <!– Specify if your server requires authentication –>
<timeout>2.5</timeout> <!– This is the connection timeout, not the locking timeout –>
<persistent></persistent> <!– Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 –>
<db>0</db> <!– Redis database number; protection from accidental loss is improved by using a unique DB number for sessions –>
<compression_threshold>2048</compression_threshold> <!– Set to 0 to disable compression (recommended when suhosin.session.encrypt=on); known bug with strings over 64k: https://github.com/colinmollenhour/Cm_Cache_Backend_Redis/issues/18 –>
<compression_lib>gzip</compression_lib> <!– gzip, lzf, lz4 or snappy –>
<log_level>1</log_level> <!– 0 (emergency: system is unusable), 4 (warning; additional information, recommended), 5 (notice: normal but significant condition), 6 (info: informational messages), 7 (debug: the most information for development/testing) –>
<max_concurrency>6</max_concurrency> <!– maximum number of processes that can wait for a lock on one session; for large production clusters, set this to at least 10% of the number of PHP processes –>
<break_after_frontend>5</break_after_frontend> <!– seconds to wait for a session lock in the frontend; not as critical as admin –>
<fail_after>10</fail_after> <!– seconds after which we bail from attempting to obtain lock (in addition to break after time) –>
<break_after_adminhtml>30</break_after_adminhtml>
<first_lifetime>600</first_lifetime> <!– Lifetime of session for non-bots on the first write. 0 to disable –>
<bot_first_lifetime>60</bot_first_lifetime> <!– Lifetime of session for bots on the first write. 0 to disable –>
<bot_lifetime>7200</bot_lifetime> <!– Lifetime of session for bots on subsequent writes. 0 to disable –>
<disable_locking>0</disable_locking> <!– Disable session locking entirely. –>
<min_lifetime>60</min_lifetime> <!– Set the minimum session lifetime –>
<max_lifetime>2592000</max_lifetime> <!– Set the maximum session lifetime –>

</redis_session>

</global>

 

 

Clear all the cache and sessions and Flush Magento Cache

rm -rf /var/www/html/magento/var/session/*

rm -rf /var/www/html/magento/var/cache/*

Login to Admin > System > Cache Management
Click “Flush Magento Cache”

Now restart the Redis server

service redis-server restart

Check if Redis is working or not

redis-cli ping

If the result is PONG .. be happy its working

To get the information and statistics of Redis server
redis-cli info

Hope this article would be helpful..