# Configuring Magento to use memcached

> Configure Magento to use Memcached for sessions and caching, so frequently used data comes from memory and pages load faster.

Source: https://helpcenter.ruachost.com/apps/magento/configuring-magento-to-use-memcached/

**Memcached** is a high‑performance, distributed memory caching system that speeds up Magento by storing frequently accessed data in RAM. On **ruachost.com**, you can configure Magento to use Memcached for sessions and caching to improve page load times.

## Why Use Memcached?

- Reduces database load by caching queries and objects.
- Improves site speed and scalability.
- Ideal for busy Magento stores with high traffic.

## Steps to Configure Magento with Memcached

### Step 1: Ensure Memcached is Available

- On **Managed VPS/Dedicated Servers** → Memcached can be installed by Ruachost support.
- On **Unmanaged VPS** → Install Memcached manually via SSH (`yum install memcached` or `apt-get install memcached`).
- Memcached is not available on every shared hosting plan. [Contact Ruachost support](https://dashboard.ruachost.com/submitticket.php) to confirm availability for your account.

### Step 2: Configure Magento 2 to Use Memcached

1. Log in via **SSH**.
2. Navigate to your Magento installation directory:

   ```bash
   cd ~/public_html
   ```
3. Open the `app/etc/env.php` file in a text editor.
4. Locate the session configuration section:

   ```
   'session' => [
       'save' => 'files',
   ],
   ```
5. Modify it to use Memcached:

   ```
   'session' => [
       'save' => 'memcached',
       'save_path' => '127.0.0.1:11211',
   ],
   ```
6. Save changes. ✅ Magento will now use Memcached for session storage.

### Step 3: Configure Magento 1.9 and Older Versions

1. Log in via **SSH**.
2. Navigate to your Magento installation directory.
3. Open the `app/etc/local.xml` file in a text editor.
4. Add the following lines inside the `<global>` section:

   ```
   <session_save><![CDATA[memcached]]></session_save>
   <session_save_path><![CDATA[127.0.0.1:11211]]></session_save_path>
   ```
5. Save changes. ✅ Magento will now use Memcached for session storage.

## Important Notes

- Always back up your site before editing configuration files.
- Replace `127.0.0.1:11211` with the correct host and port if Memcached runs on a different server.
- For advanced setups, you can configure Memcached for **page caching** as well.
