Skip to main content

How to Enable Memcached and Turbo Cache on A2 Hosting via cPanel

 You are likely paying a premium for A2 Hosting’s "Turbo" plans to improve your Time to First Byte (TTFB) and handle high-concurrency traffic. However, there is a pervasive configuration gap in how these accounts are provisioned.

While the LiteSpeed Web Server is active, the Object Cache layer—specifically Memcached—is often disabled at the PHP level by default.

If you have installed the LiteSpeed Cache plugin but failed to manually enable the PHP extension, your "Turbo" features are running at half capacity. Your database is still getting hammered by redundant queries that should be stored in RAM.

This guide provides the technical steps to enable the Memcached extension in cPanel and properly configure the LiteSpeed Cache (LSCache) plugin to utilize it.

The Architecture: Why Your Cache is Failing

To understand the fix, you must understand the failure point. A2 Hosting uses CloudLinux with CageFS to isolate accounts. While the Memcached daemon is running on the server, your specific PHP environment cannot communicate with it out of the box.

The communication chain works like this:

  1. WordPress (LSCache Plugin): Requests a cached object.
  2. PHP Runtime: Attempts to open a socket to the Memcached daemon.
  3. Memcached Daemon: Stores/Retrives the data in RAM.

If the memcached PHP extension is not loaded, Step 2 fails silently. The LSCache plugin will simply default to "OFF" or revert to disk-based caching, which is significantly slower than RAM-based object caching.

Phase 1: Enabling the PHP Extension in cPanel

You must explicitly tell the CloudLinux PHP selector to load the Memcached library.

  1. Log in to your cPanel.
  2. Scroll to the Software section.
  3. Click on Select PHP Version. Do not confuse this with "MultiPHP Manager"; you need the CloudLinux selector.
  4. Ensure you are on the Extensions tab.
  5. Locate your current PHP version in the dropdown (e.g., 8.1 or 8.2).

The Critical Selection: memcached vs memcache

You will likely see two options: memcache and memcached.

Check the box for memcached (with a 'd').

  • memcache (No 'd'): An older, procedural procedural extension that is largely deprecated in modern development.
  • memcached (With 'd'): The modern extension based on libmemcached. It supports binary protocol, sessions, and is the standard requirement for the LiteSpeed Cache plugin.

Once checked, the setting saves automatically. You do not need to restart Apache; the change is immediate for new PHP processes.

Phase 2: Configuring WordPress LiteSpeed Cache

With the bridge built, you must now configure the application to cross it.

  1. Log in to your WordPress Dashboard.
  2. Navigate to LiteSpeed Cache > Cache.
  3. Select the Object Cache tab.

Configure the settings exactly as follows to match A2’s shared architecture:

  • Object Cache: ON
  • Method: Memcached
  • Host: localhost
  • Port: 11211
  • Default Object Lifetime: 360 (or your preferred TTL)
  • Username/Password: Leave empty (A2 secures this via SASL or CageFS local isolation).
  • Persistent Connection: ON

Validating the Connection

Click the Update Settings button first. Then, look at the Connection Test status at the top of the Object Cache settings area.

  • Passed: You are successfully storing database queries in RAM.
  • Failed: The PHP extension is not loaded, or the port is blocked.

Phase 3: Programmatic Verification (Principal Engineer Level)

The UI can sometimes report false positives. To verify that Memcached is actually storing data, create a standalone PHP script in your public_html directory named cache-test.php.

This script bypasses WordPress entirely to test the raw PHP-to-Daemon connection.

<?php
/**
 * Memcached Connectivity Test
 * Place this in public_html and access via browser.
 */

// strict types for rigorous testing
declare(strict_types=1);

// 1. Check if extension is loaded
if (!class_exists('Memcached')) {
    die('<h2 style="color:red">Error: Memcached PHP extension is NOT loaded. Check cPanel.</h2>');
}

try {
    // 2. Initialize instance
    $m = new Memcached();
    
    // 3. Add Server (Standard A2 Port)
    $m->addServer('localhost', 11211);

    // 4. Attempt to set a key
    $key = 'a2_turbo_verification_key';
    $value = 'Performance is active - ' . date('Y-m-d H:i:s');
    
    // Set with 60 second TTL
    $result = $m->set($key, $value, 60);

    if ($result) {
        // 5. Attempt to get the key back
        $retrieved = $m->get($key);
        
        echo '<div style="font-family: monospace; padding: 20px; background: #e0ffe0; border: 1px solid green;">';
        echo '<h2>SUCCESS: Memcached is Operational</h2>';
        echo '<p><strong>Stored Value:</strong> ' . htmlspecialchars($retrieved) . '</p>';
        echo '<p><strong>Result Code:</strong> ' . $m->getResultCode() . '</p>';
        echo '<p><strong>Server Stats:</strong><pre>' . print_r($m->getStats(), true) . '</pre></p>';
        echo '</div>';
    } else {
        throw new Exception('Could not set key. Result Code: ' . $m->getResultCode());
    }

} catch (Exception $e) {
    echo '<div style="font-family: monospace; padding: 20px; background: #ffe0e0; border: 1px solid red;">';
    echo '<h2>CONNECTION FAILED</h2>';
    echo '<p>Error: ' . $e->getMessage() . '</p>';
    echo '</div>';
}

Load yourdomain.com/cache-test.php. If you see the server stats array, your infrastructure is sound. Delete this file immediately after testing.

Deep Dive: Handling wp-config.php Configuration

In some complex deployments (e.g., Bedrock or multisite environments), the LSCache plugin UI might not write to the file system correctly. You can force the configuration by defining constants in your wp-config.php file.

Add these lines above /* That's all, stop editing! Happy publishing. */:

// Force LSCache Object Cache Settings
define('WP_LSCACHE_OBJECT_CACHE', true);
define('WP_LSCACHE_OBJECT_CACHE_METHOD', 'memcached');
define('WP_LSCACHE_OBJECT_CACHE_HOST', 'localhost');
define('WP_LSCACHE_OBJECT_CACHE_PORT', 11211);

Note that WP_CACHE is a separate constant usually handled by the advanced-cache.php drop-in. Do not manually toggle WP_CACHE unless you are sure the drop-in exists.

Common Pitfalls and Troubleshooting

1. The PHP Version Mismatch

A common error occurs when a developer enables the extension for PHP 8.1 in cPanel, but the domain is actually running PHP 8.2 via .htaccess handler mapping. Ensure the version selected in "Select PHP Version" matches the version outputted by phpinfo().

2. Object Cache vs. Page Cache

Do not confuse these.

  • Page Cache: Stores the generated HTML of a page (handled by LSCache automatically).
  • Object Cache: Stores the results of SQL queries (requires the Memcached setup above). You need both for a true "Turbo" experience.

3. Database Bloat in wp_options

If you previously used a plugin that utilized disk-based transients (standard WordPress behavior), your wp_options table might be bloated. Once Memcached is enabled, install a transient cleaner or run wp transient delete --all via WP-CLI to flush old database entries and force WordPress to start using RAM.

Conclusion

A2 Hosting provides excellent hardware, but the "Turbo" label relies on specific software configurations that are not fully automated. By explicitly enabling the memcached library and configuring the binary protocol in LiteSpeed Cache, you move the heavy lifting from your MySQL disk I/O to system RAM.

This results in a measurable reduction in backend latency and a higher concurrency limit for your WordPress application.