Redis & Magento 2

Hi Craig, hi guys,

Once I took elasticsearch off my plate and still struggling with Porto there I thought I’ll try to play and learn something new.

Craig have you got any experience with installing & configuring Redis and Magento 2.

I found some documentation on how to install it on DigOcean and other dos instructing how to configure it and secure but as we know sometimes it is not easy just to follow dos (i.e. Porto dosc :slight_smile: hahah)

Regards,
Pawel

Testing environment:
M2.3.1, Ubuntu 16.04, DigitalOcenan, many snapshots including Magento Vanilla install

Hi guys,

ZONK! :frowning: I’ve just ried to install Redis on DigOcena Ubunntu 16.04 following this instruction:

and get this warring message after running this command: make test

Please ref to the screenshot and give me a tip if you can. I’m not a programmer so please be as descriptive as you can.
redis%20-%20worrning%20during%20install

Thank you.

Pawel

I’ve done it a couple of times using the article that you linked. Each time with success. So I have never seen this error before - Or know what it means.

I Googled “make test+error defrag” and found this suggestion. If it doesn’t help, you might want to start over:

Just notice that your jemalloc version is 4.0.3, but in branch unstable we have already upgraded jemalloc to 5.0.1, please try make distclean and make to force update jemalloc and run make test. Ref

I’ve got this tutorial penciled in on my plans. So, there will be a video on this one day.

Hi Craig,

Thank you for looking at it.

I fixed it now.

I found this online run these commands and it worked.

Okay fixed it, but rebuilding and testing again shouldn’t be the fix for this :thinking: Ref

  1. make clean
  2. make
  3. make test

Pawel

1 Like

FYI, a common issue that people run into after setting up Magento for Redis Sessions is running into this error

Error: Warning: session_start(): Failed to read session data: user (path: /var/lib/php/sessions) in /var/www/html/vendor/magento/framework/Session/SessionManager.php on line 206

This happens when a user opens more than 6 sessions in quick succession. For example, clicking multiple links Frontend/Backend. The default configuration is max sessions per user is “6”. Which is very low and should be tweaked higher based on what your server can handle.

“12” seems to eliminate the issue without causing too much stress on the server. For more details on the problem and the fix, checkout this post: Error: Failed to read session data: user (path: /var/lib/php/sessions) from April.

It’s not something you’d come across normally until your site traffic starts to build up. So, just bare this in mind when the time comes.

Good luck.

:dizzy_face:
This stuff is not easy.

I think I’ll leave it until you make a tutorial about it.

I’ll play with it but from what I can see it is not easy.

Don’t worry. Redis just appears harder than it is :slight_smile: Luckily, it’s one of those things that once you’ve done it once - You’ll never need to do again.

Hi,

I didn’t give up just yet.

Installed it and config. it.
Check the service for errors by running:

  • sudo systemctl status redis

and got this pls ref to the screenshot

Could you give me a tip on what these warnings are related to and how to fix them?

Pawel

1 Like

It’s a message that’s logged every time you start Redis. They indicate that you should optimise your Redis Configuration for better performance. That’s beyond the scope of my expertise and what we cover here. You’ll need to head over to https://serverfault.com/ or something like that to get advice from someone who works in DevOps.

Fine-tuning your web server for optimal performance is someones ongoing job and not a one-size-fits-all set-and-forget task. You could literally hire someone part time if you really wanted to go down that rabbit hole. The same could be said for optimising Apache, PHP and a whole host of other services that run on a web server.

Hi Craig,

OK thank you.

From what I can see Redis is working. All tests passed successfully except this warning message which I’m going to revisit later.

Now I need to start using it with Magento which is a different story.
I hope that this doc will be https://devdocs.magento.com/guides/v2.3/config-guide/redis/config-redis.html

If you or someone have any tips, recommendations or good resources to refer to please contribute.

Pawel

The Magento setup is super-easy. It just comes down to 3 commands that you can copy from their documentation:

Configure Redis default caching

bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0

Configure Redis page caching

bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=127.0.0.1 --page-cache-redis-db=1

Configure Magento to use Redis for session storage

bin/magento setup:config:set --session-save=redis --session-save-redis-host=127.0.0.1 --session-save-redis-log-level=3 --session-save-redis-db=2

And that’s it. They’re just default settings and can be tweaked for performance during or after the setup.

But definitely read through the documentation first before blindly copying and pasting commands. Plus it shows you how to test if it’s working.

Hi,

Thank you. I rund the command but something somewhere is not correct.
I cheched the entry in
app/etc/env.php

They are alomost identical
The only difference is ‘id prefix’ => ‘40d_’ (whatever it means)

Please ref.

It is my first try. I’ll do it a few times to familiarise myself with the process hopefully spot something which I could omit.

If you have any comments please let me know.
I can see a password record there. Is it possible to secure Redis with pass?

Pawel

That’s normal and the documentation may be out of date. It was added in 2.3.1 according to the release notes.

Magento now sets the id_prefix option on prefix cache keys for the cache frontend during installation. If this option is not set, Magento uses the first 12 bits of the md5 hash of the absolute path to the Magento app/etc directory. But if this value is not exactly the same on all web servers, cache invalidation will not work. Fix submitted by Fabian Schmengler in pull request 18641 . GitHub-15828

Yes, you can apply a password to Redis but I don’t know how.

Thank you very much for your help.

I’ll be digging in the topiic more this evening.

Can you please give me a list of suggestied soft. which is good to have on Magento and server like:

Redis
elasticsearch, kibana
Vanish - From what I read in one of your posts you are not using V

It gives me something to do :slight_smile:

Pawel

Hi,

I got stuck.
I installed redis configured magento and I can see that the site is working much faster.
Now i would like to protect Redis following flowing steps 3,4,5 from this article https://www.digitalocean.com/community/tutorials/how-to-secure-your-redis-installation-on-ubuntu-14-04

However, for some reasons I can’t edit redis.conf file using my superuser account with this command
sudo nano /etc/redis/redis.conf

Putty opens it but it looks like there is nothing there.
I tried to edit the file in notepad ++ and upload it back to this location, however, I get message access denied. Hmmmmmm :thinking:.

Can you please give me a tip?

Pawel

Do those instructions for Ubuntu 14.04 work with 16.04? I don’t know the answer but just thought I’d ask?

I just checked my Sandbox server and the file exists my side and I can edit it with sudo nano /etc/redis/redis.conf just fine.

What do you mean when you say? Why can’t you? What error do you get?

Hi Craig,

Sorry for my English and my messages. They can be quite chaotic.

I reinstalled the Redis once more and I was able to add my password to
redis.conf file uncommenting the following entry and replacing foobared with my pass (Source).

# requirepass foobared

All was good until I run these commands using magento server user:

bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=127.0.0.1 --page-cache-redis-db=1
bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0
bin/magento setup:config:set --session-save=redis --session-save-redis-host=127.0.0.1 --session-save-redis-log-level=3 --session-save-redis-db=2

I was asked I think to enter my pass but It didn’t work when I used auth my_redis_password.
I’m happy to send some screenshot to support it. The message.

For now, I disabled the password commenting it back with # but I’m planning to revisit it.

In the meantime can you pls inform me whether using not passworded Redis my site is exposed to an attack or the password secure the server only from someone who already hacked and has access to the server and can change its setting.

i.e. I or someone can access the server using magento server user and then try to change Redis setting?

You see the site works fast but I don’t want to make it unsecure.

Pawel

If you check the Magento Documentation, you have to add the cache-backend-redis-password variable to the commands, which it does not appear you have done. For example:

bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=127.0.0.1 --page-cache-redis-db=1 --cache-backend-redis-password=foobared

Anyway, if someone gains access to your server then Redis is the least of your problems. Don’t forget, that your Password is stored in the redis.conf file anyway.

It’s my understanding that setting up a Redis password is something that you only need if you run Redis on a seperate server (which large companies do). As a matter of fact, most large sites have their Web Application, Redis, MySQL, ElasticSearch, etc on their own servers. But those types of companies obviously don’t come here.


Again, I’ve not done any of this stuff so you’ll want to do your own research on best practices.

Hi,

Thank you very much for your time and sharing knowldadge with me.

I’m sorry for tormenting you all the time.

Pawel

1 Like

We are super micro busines but I like learning how things can be done :slight_smile:
You never know when you need it.

The next quite enoying thing I spotted on M2.3.1 is slow loading image.
I’ll do some reaserch on it and maybe open a new topic.

Have a good weekend!

Pawel