---
title: "Connect WordPress"
description: "Use a cache as WordPress's object cache, with Redis Object Cache on Valkey or W3 Total Cache on Memcached."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.ezghcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect WordPress

A cache shared by all your web servers keeps WordPress's object cache warm through deploys and
across instances. Create the cache in the VPC your WordPress instances are in, then set up one of
these plugins.

## Valkey with Redis Object Cache

[Redis Object Cache](https://wordpress.org/plugins/redis-cache/) works with Valkey over TLS, with a
username and password. It needs the PHP `redis` extension (phpredis), Predis or Relay.

1. Download the EZGH CA bundle to each web server:

   ```sh
   sudo curl -fsSo /etc/ssl/certs/ezgh-caches.pem https://get.ezghcloud.com/caches/ca-bundle.pem
   ```

2. Read the cache's endpoint and the `default` user's Secret:

   ```sh
   ezgh caches get cch_4k2m9x0a7qpe
   ezgh secrets read sec_a1b2c3d4e5f6 --field password --format raw
   ```

   To read the password on an instance without handling it yourself, see
   [Read a secret on an instance](/secrets/instances).

3. Add to `wp-config.php`, above `/* That's all, stop editing! */`:

   ```php
   define( 'WP_REDIS_SCHEME', 'tls' );
   define( 'WP_REDIS_HOST', 'cache-hylq6kelvuwvn2ks4yqhp4jaqu.us-west-1.ezghcompute.com' );
   define( 'WP_REDIS_PORT', 6379 );
   define( 'WP_REDIS_PASSWORD', [ 'default', '<password from the Secret>' ] );
   define( 'WP_REDIS_SSL_CONTEXT', [
       'cafile'           => '/etc/ssl/certs/ezgh-caches.pem',
       'verify_peer'      => true,
       'verify_peer_name' => true,
   ] );
   define( 'WP_REDIS_TIMEOUT', 1 );
   define( 'WP_REDIS_READ_TIMEOUT', 1 );
   ```

   `WP_REDIS_PASSWORD` is the username and the password. With only a password, the `default` user is
   used.

4. In WordPress, open **Settings › Redis** and choose **Enable Object Cache**. The status shows
   **Connected**.

Several sites can share one cache: give each its own `WP_REDIS_PREFIX`, and its own
[user](/caches/users) if you rotate their passwords separately.

## Memcached with W3 Total Cache

The PHP `memcached` extension doesn't support TLS, so WordPress connects to Memcached on port
**11212**, without TLS, inside your VPC. That port takes a username and password over Memcached's
binary protocol (SASL). It's on while the cache's `plaintextPort` is `true`, as it is by default.

[W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/) supports this. It needs the PHP
`memcached` extension built with SASL support, as distribution packages are (`php-memcached` on
Ubuntu and Debian).

1. Read the cache's endpoint and the `default` user's Secret, as above.
2. In WordPress, open **Performance › General Settings**, turn on **Object Cache**, and pick
   **Memcached** as its method.
3. Open **Performance › Object Cache**. Set **Memcached hostname:port** to the endpoint and port
   11212, for example `cache-hylq6kelvuwvn2ks4yqhp4jaqu.us-west-1.ezghcompute.com:11212`. Turn on
   **Use binary protocol**, and enter the username and password.
4. Choose **Test** to check the connection, then **Save all settings**.

Plugins that use the older PHP `memcache` extension, such as the `memcached` object-cache drop-in,
can't send a username and password, so they can't connect.

A Memcached cache starts empty after a failover or maintenance. WordPress fills it again as pages are
served.

Source: https://docs.ezghcloud.com/caches/connect-wordpress/index.mdx
