Add memcached Support to Magento

After you successfully install memcached and pecl/memcached (memcached PHP support), you will next want take full advantage of it by enabling native support for memcached in magento.

NOTE: you must have memcached and pecl/memcached already installed. Otherwise your Magento installation will break if you try following this guide.

Ok... now that the warning is out the way. Here's how we do it...

Edit your local.xml

vi ./app/etc/local.xml

Add the following between

<!-- https://github.com/Inchoo/Inchoo_PHP7/wiki/Memcache -->
 
        <session_save><![CDATA[memcached]]></session_save>
        <session_save_path><![CDATA[localhost:11211]]></session_save_path>
        <cache>
          <backend>memcached</backend>
          <memcached>
            <servers>
                <server>
                    <host><![CDATA[localhost]]></host>
                    <port><![CDATA[11211]]></port>
                    <persistent><![CDATA[1]]></persistent>
                </server>
            </servers>
            <compression><![CDATA[0]]></compression>
            <cache_dir><![CDATA[]]></cache_dir>
            <hashed_directory_level><![CDATA[]]></hashed_directory_level>
            <hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
            <file_name_prefix><![CDATA[]]></file_name_prefix>
          </memcached>
        </cache>

Example: so your file looks something like this:

<config>
    <global>
        <install>
            <date><![CDATA[Sat, 12 Mar 2014 01:37:51 +0000]]></date>
        </install>
        <crypt>
            <key><![CDATA[YOURKEY]]></key>
        </crypt>
        <disable_local_modules>false</disable_local_modules>
        <resources>
            <db>
                <table_prefix><![CDATA[]]></table_prefix>
            </db>
            <default_setup>
                <connection>
                    <host><![CDATA[localhost]]></host>
                    <username><![CDATA[DBUSERNAME]]></username>
                    <password><![CDATA[PASSWORD]]></password>
                    <dbname><![CDATA[wholesalep_gd]]></dbname>
                    <initStatements><![CDATA[SET NAMES utf8]]></initStatements>
                    <model><![CDATA[mysql4]]></model>
                    <type><![CDATA[pdo_mysql]]></type>
                    <pdoType><![CDATA[]]></pdoType>
                    <active>1</active>
                </connection>
            </default_setup>
        </resources>
<!--   <session_save><![CDATA[db]]></session_save> -->
<!-- https://github.com/Inchoo/Inchoo_PHP7/wiki/Memcache -->
 
        <session_save><![CDATA[memcached]]></session_save>
        <session_save_path><![CDATA[localhost:11211]]></session_save_path>
 
        <cache>
          <backend>memcached</backend>
          <memcached>
            <servers>
                <server>
                    <host><![CDATA[localhost]]></host>
                    <port><![CDATA[11211]]></port>
                    <persistent><![CDATA[1]]></persistent>
                </server>
            </servers>
            <compression><![CDATA[0]]></compression>
            <cache_dir><![CDATA[]]></cache_dir>
            <hashed_directory_level><![CDATA[]]></hashed_directory_level>
            <hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
            <file_name_prefix><![CDATA[]]></file_name_prefix>
          </memcached>
        </cache>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <frontName><![CDATA[gdadmin]]></frontName>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

Alright... that should do it... You don't need to restart, just visit your site, and if it's still up, that means it's working! KAPOW!

Tags: magento memcached Linux