# How to integrate Redis into Craft CMS version 2

> Connect Craft CMS version 2 to Redis running on a UNIX socket with three targeted configuration changes.

Source: https://www.kualo.com/knowledgebase/other-apps/how-to-integrate-redis-into-craft-cms-version-2
Updated: 2026-06-04

---

This guide walks you through integrating Redis with Craft CMS version 2 so that caching is served from Redis rather than the filesystem. It assumes you have already [set up Redis in cPanel](/knowledgebase/cpanel-how-tos/how-to-set-up-redis-in-cpanel).

:::info
These steps apply to Craft CMS **version 2** only. The file paths and configuration structure differ in Craft 3 and later.
:::

There are three changes to make in order for Craft CMS to work with Redis running on a UNIX socket, which is the case for most single-server setups hosted with Kualo.

## Step 1: Set the cache method to Redis

Open `craft/app/etc/config/defaults/general.php` and find the `cacheMethod` setting. Change its value to `redis`:

```php
'cacheMethod' => 'redis',
```

The valid values for this setting are `apc`, `db`, `eaccelerator`, `file`, `memcache`, `redis`, `wincache`, `xcache`, and `zenddata`. The default is `file`.

## Step 2: Create the Redis cache config file

Create a new file at `craft/config/rediscache.php`. You can use the example below as a starting point - the defaults for this file live in `craft/app/etc/config/defaults/rediscache.php`.

```php
<?php

return array(
    /*
     * Hostname to use for connecting to the Redis server.
     * Replace the path below with your Redis socket address from cPanel.
     */
    'hostname' => 'unix:///home/USER/.kxcache/redis.sock',

    /*
     * Set port to 0 when connecting via a UNIX socket.
     */
    'port' => '0',

    /*
     * Password for the Redis server. Leave empty when using stream_socket_server below.
     */
    'password' => '',

    /*
     * Use a persistent stream socket connection.
     */
    'stream_socket_server' => 'STREAM_CLIENT_PERSISTENT',

    /*
     * The Redis database to use. Starts at 0.
     * Use a unique value for each application sharing the same Redis instance.
     */
    'database' => 0,

    /*
     * Connection timeout. If null, the value from php.ini is used.
     */
    'timeout' => null,
);
```

:::warning
Replace the `hostname` value with your actual Redis socket path, which you can find in cPanel. If you host more than one application under the same account and both use Redis, give each a unique `database` number to keep their caches separate.
:::

## Step 3: Patch Craft to connect via a UNIX socket

By default, Craft CMS builds the Redis connection string as `hostname:port`, which does not work with a UNIX socket. You need to change one line in `craft/app/framework/caching/CRedisCache.php`.

Find the following line (around line 85):

```php
$this->hostname.':'.$this->port,
```

Change it to:

```php
$this->hostname,
```

Save the file, then reload your site and confirm it is working as expected. Craft CMS should now be serving its cache from Redis.

:::tip
For further performance gains, consider integrating LiteSpeed caching into your Craft CMS setup.
:::


---

_Source: Kualo Knowledgebase — https://www.kualo.com/knowledgebase/other-apps/how-to-integrate-redis-into-craft-cms-version-2 · © Kualo Ltd._
