Announcement

Collapse
No announcement yet.

How to setup memcached on Magento

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to setup memcached on Magento

    Memcached is a general-purpose distributed memory caching system. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source must be read. Memcached is free and open-source software, licensed under the Revised BSD license. Memcached runs on Unix-like operating systems and on Microsoft Windows. It depends on the libevent library.



    How To Enable 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:
    Code:
    'session' => [
        'save' => 'files'
      ],


    3.Modify this section as follows:
    Code:
    'session' => [
        'save' => 'memcached',
        'save_path' => '127.0.0.1:11211'
      ],

    Save your changes to the env.php file. Memcached is now enabled.




    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:
    Code:
    <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>

    3. Save your changes to the local.xml file. Memcached is now enabled.




    Verify memcached is working with Magento

    To verify memcached works with Magento:

    1. Delete the contents of the following directories under your Magento installation directory:

    Code:
    rm -rf var/cache/* var/page_cache/* var/session/*

    2. Go to any page on the storefront.


    3. Log in to the Magento Admin and browse to several pages.

    If no errors display, congratulations! memcached is working! You can optionally look at memcached storage as discussed in the next step.

    If errors display (such as an HTTP 500 (Internal Server Error)), enable developer mode and diagnose the issue. Make sure memcached is running, configured properly, and that env.php has no syntax errors.


    4. (Optional.) Use Telnet to look at memcached storage.

    Code:
    telnet <memcached host or ip> <memcached port>
    Code:
    stats items

    The results display similar to the following:

    ```terminal STAT items:3:number 1 STAT items:3:age 7714 STAT items:3:evicted 0 STAT items:3:evicted_nonzero 0 STAT items:3:evicted_time 0 STAT items:3:outofmemory 0 STAT items:3:tailrepairs 0
    Last edited by DaMysterious; 10-24-2019, 08:51 PM.
Working...
X