Cannot install Drupal with Redis

Created on 5 May 2017, about 8 years ago
Updated 16 June 2025, 21 days ago

Problem/Motivation

We were investigating enabling Redis caching for Drupal 8 out of the box on Platform.sh. However, when I tried to install Drupal with the Redis module already configured the first load of the actual site offers a fatal error with the generic "The website encountered an unexpected error. Please try again later."

Rerunning the installer with debug output set to verbose offers this error output:

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: No check has been registered for access_check.permission in Drupal\Core\Access\CheckProvider->loadCheck() (line 97 of core/lib/Drupal/Core/Access/CheckProvider.php).
Drupal\Core\Access\AccessManager->performCheck('access_check.permission', Object) (Line: 135)
Drupal\Core\Access\AccessManager->check(Object, Object, Object, 1) (Line: 112)
Drupal\Core\Access\AccessManager->checkRequest(Object, Object, 1) (Line: 107)
Drupal\Core\Routing\AccessAwareRouter->checkAccess(Object) (Line: 92)
Drupal\Core\Routing\AccessAwareRouter->matchRequest(Object) (Line: 154)
Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object, 'kernel.request', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.request', Object) (Line: 125)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Oddly, the first time (without verbose debugging) a page reload worked and gave me an installed site. With verbose debugging enabled a reload just gives me the same error message. If I run "drush cr" manually then the site comes up and appears to function correctly thereafter.

The install process itself seemed to have no error either way. It's just after redirecting to the actual site that the error appears.

Since a force cache rebuild fixes it, my suspicion is that it's caused by a cache not being "Ready" in time to be populated and the particular access check it fails is simply the first of a certain cache lookup rather than itself the buggy component.

Proposed resolution

Β―\_(ツ)_/Β―

πŸ› Bug report
Status

Active

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Crell

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡¦Canada tondeuse

    The following solution works for me on Drupal 10.4. Thanks for all for the ideas and tips, this is team works, as usual.

    In this format, I may use redis only for local usage, and the performance benefits it provides. The files, variables and module may be absent on hosted site instance without failure.

    My dependency to drupal/redis is declared as a DEV dependency in my composer file, in this case.

    In my Dockerfile, for all cases

    FROM php:8.3-apache
    
    ARG REDIS_PORT
    ARG REDIS_HOST
    ARG REDIS_PASSWORD
    ARG ENABLE_REDIS_CACHE
    ARG LOCAL_DEV
    
    # Install Redis PHP extension
    RUN pecl install redis \
        && docker-php-ext-enable redis
    

    In my Dockerfile, when running in local dev mode :

    An enterprise service inject these files into our hosted containers, this is a solution for local dev that also works for hosted site instances.

    # Config for local dev
    RUN \
    if [ "$LOCAL_DEV" = "TRUE" ]; \
    
    [...]
    
    if [ "$ENABLE_REDIS_CACHE" = "TRUE" ]; \
          then mkdir -p /var/run/secrets/vdmtl/redis; \
          echo "Redis configuration"; \
          echo "$REDIS_PASSWORD" > /var/run/secrets/vdmtl/redis/password; \
          echo "$REDIS_HOST" > /var/run/secrets/vdmtl/redis/host; \
          echo "$REDIS_PORT" > /var/run/secrets/vdmtl/redis/port; \
     fi; \
    [...]
    
    fi
    

    In my docker-compose file :

    web:
        container_name: web-${APP_NAME}
        links:
          - database:localhost
        build:
          context: .
          dockerfile: Dockerfile
          args:
            - LOCAL_DEV=${LOCAL_DEV}
            - REDIS_PORT=${REDIS_PORT}
            - REDIS_HOST=${REDIS_HOST}
            - REDIS_PASSWORD=${REDIS_PASSWORD}
            - ENABLE_REDIS_CACHE=${ENABLE_REDIS_CACHE}
        environment:
          ENV: ${ENV}
          LOCAL_DEV: ${LOCAL_DEV}
          ENABLE_REDIS_CACHE: ${ENABLE_REDIS_CACHE}
          
    
      redis:
        container_name: redis-${APP_NAME}
        image: redis:${REDIS_VERSION}
        restart: always
        ports:
          - ${REDIS_PORT}:6379
        command: --port ${REDIS_PORT}
        expose:
          - ${REDIS_PORT}
        volumes:
          - redis-cache:/data:delegated
    

    In my local .env file :

    LOCAL_DEV=TRUE
    
    # Redis
    REDIS_PORT=6382
    REDIS_VERSION=6.2.7
    REDIS_HOST='redis'
    REDIS_PASSWORD=
    ENABLE_REDIS_CACHE=TRUE
    

    In web/sites/default/settings.php

    /**
     * Redis config -- import as needed, check if extension is installed first
     */
    
    $redis = getenv('ENABLE_REDIS_CACHE') === 'TRUE' ? true : false;
    $redis_extension_installed = file_exists($app_root . '/modules/contrib/redis/redis.info.yml');
    if (file_exists($app_root . '/' . $site_path . '/settings.redis.php') && $redis  && $redis_extension_installed) {
      include($app_root . '/' . $site_path . '/settings.redis.php');
    }
    

    In web/sites/default/settings.redis.php

    <?php
    /**
     * Redis settings file
     * @see https://git.drupalcode.org/project/redis/-/blob/8.x-1.x/settings.redis.example.php?ref_type=heads
     *
     * Leverages the php redis ressources installed from dockerfile
     * Will set the redis config before drupal bootstrap, even if the Redis module
     * is not yet installed
     */
    
    
    use Drupal\Core\Installer\InstallerKernel;
    if (!InstallerKernel::installationAttempted() && extension_loaded('redis')) {
    
      // Set Redis as the default backend for any cache bin not otherwise specified.
      $settings['state_cache'] = TRUE;
      $redis_host = trim(file_get_contents('/var/run/secrets/vdmtl/redis/host'), "\r\n");
      $redis_password = trim(file_get_contents('/var/run/secrets/vdmtl/redis/password'), "\r\n");
      $redis_port = trim(file_get_contents('/var/run/secrets/vdmtl/redis/port'), "\r\n");
      $redis_password = $redis_password === '' ? NULL : $redis_password;
    
      // Apply changes to the container configuration to better leverage Redis.
      // This includes using Redis for the lock and flood control systems, as well
      // as the cache tag checksum. Alternatively, copy the contents of that file
      // to your project-specific services.yml file, modify as appropriate, and
      // remove this line.
      $settings['cache']['default'] = 'cache.backend.redis';
      $settings['redis_compress_length'] = 100;
      $settings['container_yamls'][] = 'modules/contrib/redis/redis.services.yml';
      $class_loader->addPsr4('Drupal\\redis\\', 'modules/contrib/redis/src');
      $settings['bootstrap_container_definition'] = [
        'parameters' => [],
        'services' => [
          'redis.factory' => [
            'class' => 'Drupal\redis\ClientFactory',
          ],
          'cache.backend.redis' => [
            'class' => 'Drupal\redis\Cache\CacheBackendFactory',
            'arguments' => ['@redis.factory', '@cache_tags_provider.container', '@serialization.phpserialize'],
          ],
          'cache.container' => [
            'class' => '\Drupal\redis\Cache\PhpRedis',
            'factory' => ['@cache.backend.redis', 'get'],
            'arguments' => ['container'],
          ],
          'cache_tags_provider.container' => [
            'class' => 'Drupal\redis\Cache\RedisCacheTagsChecksum',
            'arguments' => ['@redis.factory'],
          ],
          'serialization.phpserialize' => [
            'class' => 'Drupal\Component\Serialization\PhpSerialize',
          ],
        ],
      ];
    
      try {
        $redis = new Redis();
        $redis->connect($redis_host, $redis_port);
        if ($redis->IsConnected()) {
          $redis->auth($redis_password);
          $response = $redis->ping();
          if ($response) {
            # Redis cache configuration
            $settings['cache_prefix'] = 'dm_';
            $settings['redis.connection']['host'] = $redis_host;
            $settings['redis.connection']['password'] = $redis_password;
            $settings['redis.connection']['port'] = $redis_port;
            $settings['redis.connection']['instance'] = 'cache';
            $settings['redis.connection']['interface'] = 'PhpRedis';
            $settings['cache']['default'] = 'cache.backend.redis';
            $settings['container_yamls'][] = $app_root . '/modules/contrib/redis/example.services.yml';
            $settings['redis_compress_length'] = 100;
            $settings['redis_compress_level'] = 3;
            $conf['redis_perm_ttl'] = 2592000;
            $conf['redis_flush_mode'] = 1;
          }
        }
      } catch (Exception $e) {
      }
    }
    
    
Production build 0.71.5 2024