How to configure Magento to use memcached

This article describes how to configure Magento to use memcached.

Memcached is an open-source memory object caching system that web sites can use to help accelerate page load times. Memcached works by caching in RAM frequently accessed data, such as the results of API calls, database calls, and more.

  • If you have a managed VPS or managed Dedicated Server, please open a support ticket on the Customer Portal at https://my.a2hosting.com and request memcached for your system. We will install it for you.
  • If you have an unmanaged VPS or unmanaged Dedicated Server, you can install memcached yourself.
  • If you have a Turbo Boost or Turbo Max Web Hosting account, you should not follow the procedures in this article. Instead, use the A2 Optimized plugin to configure and manage memcached for your application.
  • Memcached is not supported on non-Turbo shared hosting accounts at this time.

Enabling memcached for Magento 2

To enable memcached for Magento 2, you must change some settings in the env.php file. To do this, follow these steps:

  1. Using your preferred text editor, navigate to the directory where you installed Magento, and then open the app/etc/env.php file.
  2. Locate the following section in the env.php file:
      'session' => [
        'save' => 'files'
      ],
    
  3. Modify this section as follows:

      'session' => [
        array (
          'save' => 'memcached',
          'save_path' => '127.0.0.1:11211'
        ),
      ],
    
  4. Save your changes to the env.php file. Memcached is now enabled.

    For additional information about how to configure memcached with Magento 2, please visit http://devdocs.magento.com/guides/v2.0/config-guide/memcache/memcache_magento.html.

Enabling memcached for Magento 1.9 and older versions

To enable memcached for Magento 1.9 and older versions, you need to add some settings to the local.xml file. To do this, follow these steps:

  1. Using your preferred text editor, navigate to the directory where you installed Magento, and then open the app/etc/local.xml file.
  2. Add the following lines just before the closing </global> tag:
    <cache>
        <backend>memcached</backend>
        <memcached>
            <servers>
                <server>
                    <host><![CDATA[127.0.0.1]]></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>
    
    If these lines are not contained in the <global> section, Magento will not use memcached.
  3. Save your changes to the local.xml file. Memcached is now enabled.

More Information

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.