Exception when installing on a project that uses redis via socket
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3471826. --> Reported by: [anybody](https://www.drupal.org/user/291091) Related to !15 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Crowdsec question / feature request regarding socket connections: <a href="https://github.com/crowdsecurity/crowdsec/issues/3981">https://github.com/crowdsecurity/crowdsec/issues/3981</a></p> <p>Installing this in a project that already uses redis causes the following exception right after<br> <code>drush en crowdsec</code>:</p> <pre>The website encountered an unexpected error. Try again later.<br>CrowdSec\RemediationEngine\CacheStorage\CacheStorageException: Error when creating Redis cache adapter:Redis connection failed: No such file or directory in CrowdSec\RemediationEngine\CacheStorage\Redis-&gt;__construct() (line 35 of /vendor/crowdsec/remediation-engine/src/CacheStorage/Redis.php).<br><br>CrowdSec\RemediationEngine\CacheStorage\Redis-&gt;__construct() (Line: 183)<br>Drupal\crowdsec\Client-&gt;cache() (Line: 133)<br>Drupal\crowdsec\Client-&gt;remediation() (Line: 160)<br>Drupal\crowdsec\Client-&gt;verifyIp() (Line: 87)<br>Drupal\crowdsec\Middleware-&gt;handle() (Line: 48)<br>Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle() (Line: 51)<br>Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle() (Line: 36)<br>Drupal\Core\StackMiddleware\AjaxPageState-&gt;handle() (Line: 49)<br>Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware-&gt;handle() (Line: 51)<br>Drupal\Core\StackMiddleware\StackedHttpKernel-&gt;handle() (Line: 741)<br>Drupal\Core\DrupalKernel-&gt;handle() (Line: 19)</pre><h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p><em>As we found out below, the reason is that we're connecting through a socket!</em></p> <p>See above and here's my settings.redis.php:</p> <pre>&lt;?php<br><br>use Drupal\Core\Installer\InstallerKernel;<br><br>// Either copy the content of this file into an existing settings.php file or<br>// create as e.g. settings.redis.php and include it, then customize. See<br>// README.md and client specific README files for more information.<br><br>// Adjust extension check or remove, prevents configuring Redis before<br>// Drupal is installed or on an environment where the used client is not<br>// available.<br>if (!InstallerKernel::installationAttempted() &amp;&amp; extension_loaded('redis')) {<br><br>&nbsp; // Customize host and port.<br>&nbsp; // $settings['redis.connection']['host'] = '127.0.0.1';<br>&nbsp; // $settings['redis.connection']['port'] = 6379;<br><br>&nbsp; // Old Hetzner redis via cron:<br>&nbsp; // $settings['redis.connection']['host']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = '127.0.0.1';&nbsp; // Your Redis instance hostname.<br>&nbsp; // $settings['redis.connection']['port']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = '6379';&nbsp; // Redis port<br><br>&nbsp; // New Hetzner redis via UI:<br>&nbsp; $settings['redis.connection']['host']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = '/run/redis_me/redis.sock';&nbsp; // Your Redis instance hostname.<br>&nbsp; $settings['redis.connection']['port']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0;&nbsp; // Redis port<br><br><br>&nbsp; // Customize used interface.<br>&nbsp; // $settings['redis.connection']['interface'] = 'PhpRedis';<br><br>&nbsp; // Set Redis as the default backend for any cache bin not otherwise specified.<br>&nbsp; $settings['cache']['default'] = 'cache.backend.redis';<br><br>&nbsp; // Per-bin configuration examples, bypass the default ChainedFastBackend.<br>&nbsp; // *Only* use this when using Relay (see README.Relay.md) or when APCu is not<br>&nbsp; // available.<br>&nbsp; // $settings['cache']['bins']['config'] = 'cache.backend.redis';<br>&nbsp; // $settings['cache']['bins']['discovery'] = 'cache.backend.redis';<br>&nbsp; // $settings['cache']['bins']['bootstrap'] = 'cache.backend.redis';<br><br>&nbsp; // Use compression for cache entries longer than the specified limit.<br>&nbsp; $settings['redis_compress_length'] = 100;<br><br>&nbsp; // Customize the prefix, a reliable but long fallback is used if not defined.<br>&nbsp; // $settings['cache_prefix'] = 'prefix';<br>&nbsp; $settings['cache_prefix'] = 'redisme_';<br><br>&nbsp; // Apply changes to the container configuration to better leverage Redis.<br>&nbsp; // This includes using Redis for the lock and flood control systems, as well<br>&nbsp; // as the cache tag checksum. Alternatively, copy the contents of that file<br>&nbsp; // to your project-specific services.yml file, modify as appropriate, and<br>&nbsp; // remove this line.<br>&nbsp; // $settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';<br>&nbsp; $settings['container_yamls'][] = 'sites/default/redis.services.yml';<br><br>&nbsp; // Allow the services to work before the Redis module itself is enabled.<br>&nbsp; $settings['container_yamls'][] = 'modules/contrib/redis/redis.services.yml';<br><br>&nbsp; // Manually add the classloader path, this is required for the container cache<br>&nbsp; // bin definition below and allows to use it without the redis module being<br>&nbsp; // enabled.<br>&nbsp; $class_loader-&gt;addPsr4('Drupal\\redis\\', 'modules/contrib/redis/src');<br><br>&nbsp; // Use redis for container cache.<br>&nbsp; // The container cache is used to load the container definition itself, and<br>&nbsp; // thus any configuration stored in the container itself is not available<br>&nbsp; // yet. These lines force the container cache to use Redis rather than the<br>&nbsp; // default SQL cache.<br>&nbsp; $settings['bootstrap_container_definition'] = [<br>&nbsp;&nbsp;&nbsp; 'parameters' =&gt; [],<br>&nbsp;&nbsp;&nbsp; 'services' =&gt; [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'redis.factory' =&gt; [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'class' =&gt; 'Drupal\redis\ClientFactory',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'cache.backend.redis' =&gt; [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'class' =&gt; 'Drupal\redis\Cache\CacheBackendFactory',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'arguments' =&gt; ['@redis.factory', '@cache_tags_provider.container', '@serialization.phpserialize'],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'cache.container' =&gt; [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'class' =&gt; '\Drupal\redis\Cache\PhpRedis',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'factory' =&gt; ['@cache.backend.redis', 'get'],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'arguments' =&gt; ['container'],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'cache_tags_provider.container' =&gt; [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'class' =&gt; 'Drupal\redis\Cache\RedisCacheTagsChecksum',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'arguments' =&gt; ['@redis.factory'],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'serialization.phpserialize' =&gt; [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'class' =&gt; 'Drupal\Component\Serialization\PhpSerialize',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ],<br>&nbsp;&nbsp;&nbsp; ],<br>&nbsp; ];<br>}</pre><h3 id="summary-proposed-resolution">Proposed resolution</h3> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <h3 id="summary-ui-changes">User interface changes</h3> <h3 id="summary-api-changes">API changes</h3> <h3 id="summary-data-model-changes">Data model changes</h3>
issue