5

I already installed and tested Redis working properly on my server. But when I added Redis required settings cache in my app/etc/env.php then my Magento 2 displays blank page. I also tried to clean cache by running this command php bin/magento cache:clean and I got errors below

PHP Parse error: syntax error, unexpected ''automatic_cleaning_factor'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in app/etc/env.php on line 101

Below is my env.php config:

'cache' =>
  array (
    'frontend' =>
    array (
      'default' =>
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' =>
        array (
          'server' => '127.0.0.1',
          'port' => '6379',
          'persistent' => '',
          'database' => '0',
          'password' => '',
          'force_standalone' => '0',
          'connect_retries' => '1',
          'read_timeout' => '10',
          'automatic_cleaning_factor' => '0',
          'compress_data' => '1',
          'compress_tags' => '1',
          'compress_threshold' => '20480',
          'compression_lib' => 'gzip',
          'use_lua' => '0',
        ),
      ),
      'page_cache' =>
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' =>
        array (
          'server' => '127.0.0.1',
          'port' => '6379',
          'persistent' => '',
          'database' => '1',
          'password' => '',
          'force_standalone' => '0',
          'connect_retries' => '1',
          'lifetimelimit' => '57600',
          'compress_data' => '0',
          'compress_tgs'  => '1',
          'compress_threshold' => '20480',
          'compression_lib' => 'gzip'
          'automatic_cleaning_factor' => '0',
        ),
      ),
    ),
  ),

I don't know reason why? Did I miss configuration setting in Magento or I had to disable memcached in Magento 2.

EDIT

PHP Fatal error: Uncaught exception 'CredisException' with message 'Connection to Redis failed after 2 failures.Last Error : (13) Permission denied' in /var/www/magento2/vendor/colinmollenhour/credis/Client.php:448\nStack trace:\n#0 /var/www/magento2/vendor/colinmollenhour/credis/Client.php(444): Credis_Client->connect()\n#1 /var/www/magento2/vendor/colinmollenhour/credis/Client.php(774): Credis_Client->connect()\n#2 /var/www/magento2/vendor/colinmollenhour/credis/Client.php(604): Credis_Client->__call('select', Array)\n#3 /var/www/magento2/vendor/colinmollenhour/cache-backend-redis/Cm/Cache/Backend/Redis.php(144): Credis_Client->select(1)\n#4 /var/www/magento2/vendor/magento/zendframework1/library/Zend/Cache.php(153): Cm_Cache_Backend_Redis->__construct(Array)\n#5 /var/www/magento2/vendor/magento/zendframework1/library/Zend/Cache.php(94): Zend_Cache::_makeBackend('Cm_Cache_Backen...', Array, true, true)\n#6 /var/www/magento2/vendor/magento/framework/App/Cache/Frontend/Factory.php(156): Zend_Cache::factory('Ma in /var/www/magento2/vendor/colinmollenhour/credis/Client.php on line 448

5

You have a typo at the end of your config, you're missing a comma ',' after

'compression_lib' => 'gzip'
6
  • Thanks so much for your reply. I already added comma ',' but it still raises errors – nvtthang Dec 26 '16 at 17:43
  • the same error? – Julien Lachal Dec 26 '16 at 18:24
  • Well, It raised to me another error message PHP Fatal error: Uncaught exception 'CredisException' with message 'Connection to Redis failed after 2 failures.Last Error : (13) Permission denied' in /var/www/magento2/vendor/colinmollenhour/credis/Client.php:448\nStack trace:\n#0 /var/www/magento2/vendor/colinmollenhour/credis/Client.php(444): Credis_Client->connect()\n#1 /var/www/magento2/vendor/colinmollenhour/credis/Client.php(774): Credis_Client->connect()\n#2 – nvtthang Dec 27 '16 at 17:20
  • Make sure your permissions are set correctly across all files. – Julien Lachal Dec 28 '16 at 7:55
  • Same problem in CentOS 7, Magento 2.1.8. Not the comma cause, doesn't find the file permissions problem. – Key Shang Nov 21 '17 at 9:53
1

In CentOs 7, you need to enable the SELinux boolean:

sudo setsebool httpd_can_network_connect on

1
  • This solved it for me – Kunsal Ajay Apr 19 at 13:08
0

I had same issue, turned out the port used by redis (6379 in my case) was being used by other application. So, I changed port in the config and it worked like charm.

0

I had a similar issue. I was getting following error.

   "PHP message: PHP Fatal error:  Uncaught CredisException: Connection to Redis redis:6379 failed after 2 failures.Last Error : (0) php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /var/www/html/project/vendor/colinmollenhour/credis/Client.php:475
Stack trace:
#0 /var/www/html/project/vendor/colinmollenhour/credis/Client.php(471): Credis_Client->connect()
#1 /var/www/html/project/vendor/colinmollenhour/credis/Client.php(784): Credis_Client->connect()

I had not provided the password and the server name was wrong for me.

'cache' => [
    'frontend' => [
        'default' => [
            'id_prefix' => 'a03_',
            'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
            'backend_options' => [
                'server' => 'redis', /* I had redis installed locally so I had to enter 127.0.0.1 */
                'database' => '0',
                'port' => '6379',
                'password' => '', /* Here I had not entered password */
                'compress_data' => '1',
                'compression_lib' => '',
                'preload_keys' => [
                    'a03__EAV_ENTITY_TYPES',
                    'a03__GLOBAL_PLUGIN_LIST',
                    'a03__DB_IS_UP_TO_DATE',
                    'a03__SYSTEM_DEFAULT',
                ],
            ]
        ],
-1

First, check the Redis host in your env file you can use your env.php based on my env file that I use in my Magento 2 Docker container to avoid future issues:

<?php
return array (
  'backend' => 
  array (
    'frontName' => 'admin',
  ),
  'crypt' => 
  array (
    'key' => '5e56dc6d8f24f711bb4f289cca1beda9',
  ),
  'session' => 
  array (
    'save' => 'redis',
    'redis' => 
    array (
      'host' => 'redis-session',
      'port' => '6379',
      'password' => '',
      'timeout' => '2.5',
      'persistent_identifier' => '',
      'database' => '2',
      'compression_threshold' => '2048',
      'compression_library' => 'gzip',
      'log_level' => '1',
      'max_concurrency' => '6',
      'break_after_frontend' => '5',
      'break_after_adminhtml' => '30',
      'first_lifetime' => '600',
      'bot_first_lifetime' => '60',
      'bot_lifetime' => '7200',
      'disable_locking' => '0',
      'min_lifetime' => '60',
      'max_lifetime' => '2592000',
    ),
  ),
  'db' => 
  array (
    'table_prefix' => '',
    'connection' => 
    array (
      'default' => 
      array (
        'host' => 'db',
        'dbname' => 'magento',
        'username' => 'magento',
        'password' => 'magento',
        'active' => '1',
      ),
    ),
  ),
  'resource' => 
  array (
    'default_setup' => 
    array (
      'connection' => 'default',
    ),
  ),
  'x-frame-options' => 'SAMEORIGIN',
  'MAGE_MODE' => 'production',
  'cache_types' => 
  array (
    'config' => 1,
    'layout' => 1,
    'block_html' => 1,
    'collections' => 1,
    'reflection' => 1,
    'db_ddl' => 1,
    'eav' => 1,
    'customer_notification' => 1,
    'full_page' => 1,
    'config_integration' => 1,
    'config_integration_api' => 1,
    'translate' => 1,
    'config_webservice' => 1,
    'compiled_config' => 1,
    'amasty_shopby' => 1,
    'target_rule' => 1,
  ),
  'install' => 
  array (
    'date' => 'Thu, 05 Jan 2017 22:49:50 +0000',
  ),
  'cache' => 
  array (
    'frontend' => 
    array (
      'default' => 
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' => 
        array (
          'server' => 'redis',
          'port' => '6379',
          'persistent' => '',
          'database' => '0',
          'password' => '',
          'force_standalone' => '0',
          'connect_retries' => '1',
          'read_timeout' => '10',
          'automatic_cleaning_factor' => '0',
          'compress_data' => '1',
          'compress_tags' => '1',
          'compress_threshold' => '20480',
          'compression_lib' => 'gzip',
          'use_lua' => '0',
        ),
      ),
      'page_cache' => 
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' => 
        array (
          'server' => 'redis',
          'port' => '6379',
          'persistent' => '',
          'database' => '1',
          'password' => '',
          'force_standalone' => '0',
          'connect_retries' => '1',
          'lifetimelimit' => '57600',
          'compress_data' => '0',
        ),
      ),
    ),
  ),
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.