Skip to content

Redis cpanel

WordPress

  • It runs via socket and needs to be configured in the application config to work with the socket.

define( 'WP_REDIS_SCHEME', 'unix' );
define( 'WP_REDIS_PATH', '/home/$cpuser/ea-podman.d/ea-redis62.cpuser.01/redis.sock' );
define( 'WP_REDIS_DATABASE', 0 );
- Example
################## Redis Socket Setup ##################
#/home/vmin/ea-podman.d/ea-redis62.vmin.02/redis.sock

define( 'WP_REDIS_SCHEME', 'unix' );
define( 'WP_REDIS_PATH', '/home/$cpuser/ea-podman.d/ea-redis62.cpuser.01/redis.sock' );
define( 'WP_REDIS_DATABASE', 0 );
  • Script
    /usr/local/cpanel/scripts/ea-podman install ea-redis62
    

Drupal

  1. Install the Redis module via Composer:

composer require drupal/redis
2. Enable it
drush en redis
  1. Update settings.php
    $settings['redis.connection']['interface'] = 'unix';
    $settings['redis.connection']['path'] = '/home/$cpuser/ea-podman.d/ea-redis62.cpuser.01/redis.sock';
    $settings['cache']['default'] = 'cache.backend.redis';
    $settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';
    

Magento

  • Update env.php file
    'cache' => [
        'frontend' => [
            'default' => [
                'backend' => 'Cm_Cache_Backend_Redis',
                'backend_options' => [
                    'server' => '/home/$cpuser/ea-podman.d/ea-redis62.cpuser.01/redis.sock',
                    'database' => '0',
                    'port' => '0',
                    'persistent' => '',
                    'force_standalone' => 1
                ],
            ],
        ],
    ],
    

Joomla

  • configuration.php file
    public $session_handler = 'redis';
    public $redis_server = '/home/$cpuser/ea-podman.d/ea-redis62.cpuser.01/redis.sock';
    

Laravel

  • Update .env file

    REDIS_HOST=/home/$cpuser/ea-podman.d/ea-redis62.cpuser.01/redis.sock
    REDIS_SCHEME=unix
    
  • config/database.php

    'unix_socket' => env('REDIS_HOST', '/home/$cpuser/ea-podman.d/ea-redis62.cpuser.01/redis.sock'),
    

config redis-cli

OFFICIAL DOCUMENTATION

  • Set Memory

    podman exec -it -u root container_id  redis-cli CONFIG SET MAXMEMORY 3GB
    OK
    
  • Container Id can be obtain from podman ps -a command

  • Get Memory value
    podman exec -it -u root d4661ad912ee  redis-cli CONFIG GET MAXMEMORY
    1) "maxmemory"
    2) "3221225472"
    

The value is in Bytes

python -c 'memory = (3221225472 // 1024 ** 2 );print(memory)'
3072
  • Get server info

    podman exec -it -u root d4661ad912ee  redis-cli INFO SERVER
    # Server
    redis_version:6.2.17
    redis_git_sha1:00000000
    redis_git_dirty:0
    redis_build_id:1fd7a5d71f5b6cc4
    redis_mode:standalone
    os:Linux 5.14.0-570.12.1.el9_6.x86_64 x86_64
    arch_bits:64
    monotonic_clock:POSIX clock_gettime
    multiplexing_api:epoll
    atomicvar_api:c11-builtin
    gcc_version:12.2.0
    process_id:1
    process_supervised:no
    run_id:8bb1a2180e2b630ac650b98fdcbc158aaf0e99a7
    tcp_port:6379
    server_time_usec:1748683245175747
    uptime_in_seconds:5662
    uptime_in_days:0
    hz:10
    configured_hz:10
    lru_clock:3852781
    executable:/data/redis-server
    config_file:/usr/local/etc/redis/redis.conf
    io_threads_active:0
    
  • Redis config file is mapped to the /home/$user/ea-podman.d/redis.conf file. Values from that file are been synched to the container and in reverse.

  • Redis with Cloudlinux

     Redis server configuration by NICT
     */
    define( 'WP_REDIS_HOST', '127.0.1.202' );
    define( 'WP_REDIS_PORT', 33235 );
    define( 'WP_REDIS_DATABASE', 0 );
    define( 'WP_REDIS_TIMEOUT', 1 );
    define( 'WP_REDIS_READ_TIMEOUT', 1 );
    
  • PHP APP.

    // Redis init (optional cache layer)
    $redis = null;
    
    // Redis init (optional cache layer)
    global $redis;
    $redis = null;
    
    if (extension_loaded('redis') && isset($cfg['redis_host'])) {
        try {
            $redis = new Redis();
            $redis->pconnect(
                $cfg['redis_host'],
                $cfg['redis_port'],
                $cfg['redis_timeout']
            );
            $redis->select($cfg['redis_db']);
        } catch (Throwable $e) {
            $redis = null;
        }
    }
    
/* Redis */
$cfg['redishost']     = '127.0.1.202';
$cfg['redisport']     = 33235;
$cfg['redisdb']       = 0;
$cfg['redistimeout']  = 1.0;