Magento Community Edition is a flexible and robust open source content management system for e-commerce web sites. In this tutorial we will show you how to install Magento and configure Redis (an open source advanced key-value cache and store) for back end caching on an Ubuntu VPS.
Download the latest version of Magento from www.magentocommerce.com, extract it and move the Magento installation to the ‘/var/www/html/magento/’ directory on your VPS:
cd /root/ wget http://www.magentocommerce.com/downloads/assets/1.9.0.1/magento-1.9.0.1.tar.gz tar -xzvf magento-1.9.0.1.tar.gz mv /root/magento /var/www/html/magento/
Set proper permissions:
chown www-data:www-data -R /var/www/html/magento/ cd /var/www/html/magento chmod -R o+w app/etc/ chmod -R o+w var/ chmod -R o+w media/
Create a new database for Magento:
mysql -u root -p mysql> create database magentodb; mysql> GRANT ALL PRIVILEGES ON magentodb . * TO magento@'localhost' IDENTIFIED BY 'your-password' WITH GRANT OPTION; mysql> flush privileges; mysql> quit
Install Redis:
apt-get install redis-server
Install phpRedis extension via PECL:
apt-get install php5-dev pecl install redis
Add ‘extension=redis.so’ to the ‘php.ini’ configuration file. To locate the ‘php.ini’ configuration file, use the following command:
php -i | grep php.ini Configuration File (php.ini) Path => /etc/php5/cli Loaded Configuration File => /etc/php5/cli/php.ini
Or, create ‘redis.ini’ file in the ‘/etc/php5/mods-available/’ directory:
vi /etc/php5/mods-available/redis.ini
and add these lines:
; configuration for php Redis module extension=redis.so
Then, run the following command:
php5enmod redis
Also, enable PHP mcrypt extension as it is required by Magento:
php5enmod mcrypt
Create a new virtual host directive in Apache. For example, create a new Apache configuration file named ‘magento.conf’:
vi /etc/apache2/sites-available/magento.conf
and add the following lines:
<VirtualHost *:80> ServerAdmin admin@your-domain.com DocumentRoot /var/www/html/magento/ ServerName your-domain.com ServerAlias www.your-domain.com <Directory /var/www/html/magento/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/your-domain.com-error_log CustomLog /var/log/apache2/your-domain.com-access_log common </VirtualHost>
Restart Apache for the changes to take effect using the following command:
service apache2 restart
Open http://your-domain.com/index.php/install and follow the easy instructions.
To configure Magento to use Redis, edit ‘/var/www/html/magento/app/etc/modules/Cm_RedisSession.xml’ file and change:
<active>false</active>
to:
<active>true</active>
Then, edit the ‘local.xml’ file located to the ‘/var/www/html/magento/app/etc/’ directory:
vi /var/www/html/magento/app/etc/local.xml
and add the following lines after <session_save><![CDATA[files]]></session_save>
<cache>
<backend>Mage_Cache_Backend_Redis</backend>
<backend_options>
<server>127.0.0.1</server>
<port>6379</port>
<persistent></persistent>
<database>0</database>
<password></password>
<force_standalone>1</force_standalone>
<connect_retries>1</connect_retries>
<read_timeout>10</read_timeout>
<automatic_cleaning_factor>0</automatic_cleaning_factor>
<compress_data>1</compress_data>
<compress_tags>1</compress_tags>
<compress_threshold>20480</compress_threshold>
<compression_lib>gzip</compression_lib>
</backend_options>
</cache>
Next, delete cache and sessions:
rm -rf /var/www/html/magento/var/session/* rm -rf /var/www/html/magento/var/cache/*
Or, log in to the Admin panel as an administrator, click ‘System’ > ‘Cache Management’, then click ‘Flush Magento Cache’.
That is it. Magento is installed and configured to use Redis as back end cache.
Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Magento and enable Redis as back end cache for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.
Cool, thanks
thnkiouuuuuuuuu very helpful :)
Thank you. That works like charm.
Hi peeps,
I have installed the Redis as per given above. Then how can i check the redis cache working in my project?
Thanks peeps!
To check if everything works fine you can use ‘redis-cli’ command.