Skip to content
Magento 2: useful settings and fixes
E-commerce · Updated on · 9 min read

Magento 2: useful settings and fixes

Here are a few Magento 2 settings and fixes I often need: turning off the admin reCAPTCHA, extending the admin session lifetime, managing indexes, choosing themes and fixing the cookieMessagesObservable error.

How to Remove the Admin reCAPTCHA from Magento 2

reCAPTCHA can be annoying, especially in a test environment, so it can be useful to know how to remove it. Since Magento 2 enables it automatically, here are the 3 procedures we can follow:

From Admin:

Go to the menu Stores => (Settings) Configuration

Magento 2 admin Stores menu with the Configuration item

In the Advanced => Admin section, open the CAPTCHA accordion and, by unticking the “Use system value” checkbox, we can set the dropdown value to “No“

Admin CAPTCHA setting in Magento 2 configuration

From a Query:

update core_config_data set value = 0 where path = 'admin/captcha/enable'

From the Terminal:

bin/magento config:set admin/captcha/enable 0

Magento 2 Admin Session Cookie Lifetime

The cookie lifetime can be changed in 3 different ways:

From the Admin panel:

In the Stores => (Settings) Configuration menu

Magento 2 admin Stores menu with the Configuration item

In the Advanced => Admin section, open the Admin Session Lifetime (seconds) accordion and enter the value you want to set. The screenshot shows the maximum value suggested in the field’s comment

Admin Session Lifetime field in Magento 2 configuration

From a Query:

update core_config_data set value='31536000' where path = 'admin/security/session_lifetime'

From the Terminal:

bin/magento config:set admin/security/session_lifetime 0

Magento 2 Indexes

What are they?

Indexes are a fundamental component of Magento 2 and of any software with very large, complex databases. Without indexes, Magento could never deliver the performance it offers.

Where are indexes managed?

In the admin panel, in the System menu, under Tools you will find Index Management

Magento 2 Index Management in the System menu

How should they be configured?

The optimal configuration for indexes is scheduled mode, so that Magento’s cron takes care of refreshing them. If we set them to update on save, for example, we would slow down the work we do in the admin panel, because the wait for each request would get longer.

Magento 2 indexers grid with the update mode

How do I change the indexer mode?

As with many Magento tables, mass actions are available. So if we want to change the indexer mode, we just select one or more indexes using the checkbox on the left, then use the “Actions” dropdown above the grid on the left and choose the change to make.

Selecting indexers and the Actions menu to change mode

Commands to manage indexes from the CLI:

To set scheduled mode.

bin/magento indexer:set-mode schedule

To run a reindex:

bin/magento indexer:reindex

To reset the indexes:

bin/magento indexer:reset

To reindex a single index:

bin/magento indexer:reindex nome_indice

Magento 2 Themes

I often work on stores already built on Magento 2 that, because of low budgets at the start, ended up having to install ready-made themes bought for a few euros on the best-known marketplaces (which I will deliberately not name).

Everyone is free to do what they think is best, of course. But I would like to help someone choose the best option by explaining some of the problems I have run into with ready-made themes.

When upgrading the Magento version, and possibly the technology stack, the theme may not have the update that fixes any issues.
Several times I found that the theme update turned out to be a completely different theme from the previous version, so all the custom changes made in the first phase had to be redone from scratch, and sometimes they weren’t even feasible.
As for performance, these themes implement many features that our store may not need at all, but by having them installed we create performance problems.

Sometimes it might be worth considering implementing a few fewer features in the first phase, in order to set aside resources for building a custom theme.

By default, Magento 2 ships with the Luma theme, which can be used as-is, or extended and customized as needed.
Alternatively, we can find very performant themes that can be customized by choosing which components to use.

The ones I have worked with lately and been very happy with are the following:

ReferenceError: cookieMessagesObservable is not defined

cookieMessagesObservable is not defined error in the browser console

The other day I had to upgrade a Magento store from version 2.3.x to the latest version, 2.4.7, and I ran into this error in the console.
Debugging the code, I found that the theme had overridden this file: Magento_Theme/web/js/view/messages.js, which of course didn’t include cookieMessagesObservable.

I fixed it simply by deleting the file from the theme, since it contained no customizations.

You might also like