XF 2.1 Redis configuration problem

Anatoliy

Well-known member
I'm trying to enable guest page caching. My hosting provider installed Redis on my VPS. However when I put in src/config.php file the following code I get "http error 500" in the browser.

$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = ['host' => '127.0.0.1', 'password' => 'my_password'];

if I put this code, I get in my browser something like "Unexpected error. Please come back later"

$config['cache']['enabled'] = true;
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = ['host' => '127.0.0.1', 'password' => 'my_password'];

Please advice what I'm doing wrong and how it should be done correctly.
Thanks in advance.
 
still on New Year vacation? )

Please advice how to figure out if my hosting provider misconfigured Redis or I put a wrong code in config.php?

I disabled add-ons (tapatalk and XenForo Redirects for vBulletin) but it didn't change anything.
 
Server error log
  • LogicException: Cannot load Redis cache provider without Redis
  • src/XF/CacheFactory.php:201
Stack trace
#0 src/XF/CacheFactory.php(79): XF\CacheFactory->createRedisCache(Array)
#1 src/XF/CacheFactory.php(34): XF\CacheFactory->instantiate('Redis', Array)
#2 src/XF/App.php(639): XF\CacheFactory->create('Redis', Array)
#3 src/XF/Container.php(228): XF\App->XF\{closure}('page', Array, Object(XF\Container))
#4 src/XF/App.php(2346): XF\Container->create('cache', 'page')
#5 src/XF/Pub/App.php(54): XF\App->cache('page', false)
#6 src/XF/Container.php(28): XF\Pub\App->XF\Pub\{closure}(Object(XF\Container))
#7 src/XF/Pub/App.php(674): XF\Container->offsetGet('pageCache')
#8 src/XF/Pub/App.php(102): XF\Pub\App->pageCache()
#9 src/XF/App.php(2180): XF\Pub\App->start(true)
#10 src/XF.php(391): XF\App->run()
#11 index.php(20): XF::runApp('XF\\Pub\\App')
#12 {main}
Request state
array(4) {
["url"] => string(30) "/members/stinger-believer.955/"
["referrer"] => bool(false)
["_GET"] => array(0) {
}
["_POST"] => array(0) {
}
}
 
You will need two things:
  • Redis
  • phpredis
If you are missing one of these it won't work. Check with phpinfo whether phpredis is installed.

http error 500
This should put an error in the webserver's error log. Can you check this, it might reveal what is going wrong.
Are you sure Redis is installed with password and listening on localhost? You can check this by login in on your local server and do a telnet to localhost port 6379. This way you can check if Redis is listening.

Sometimes it is installed using unix sockets, in that case you need to redirect 'host'to a path like /var/run/redis.sock'
 
Last edited:
You will need two things:
  • Redis
  • phpredis
If you are missing one of these it won't work.


This should put an error in the webserver's error log. Can you check this, it might reveal what is going wrong.
Are you sure Redis is installed with password and listening on localhost? You can check this by login in on your local server and do a telnet to localhost port 6379. This way you can check if Redis is listening.

Sometimes it is installed using sockets, in that case you need to redirect 'host'to a path like /var/run/redis.sock'

thank you, Mr. Jinx! I'm going to contact my hosting provider with this info.
 
@Mr. Jinx you were right, phpredis was missing. now they installed it, I put in my config.php
$config['cache']['enabled'] = true;
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = ['host' => '127.0.0.1', 'password' => 'my_password'];

and my forum works fine (no error message). But how can I check that guests get cached page and not regular php pages as before?
 
When a page is served from the cache, a X-XF-Cache-Status: HIT header will be present in the response.

this is what documentation mentions. i checked on my own forum and couldn't locate this header.

yeah, it doesn't look right.

So what's the scoop with xenforo tech support? Two weeks already gone since I asked for help. It's not like I'm trying to modify something, I'm trying to use build in option of the software I paid for. Tech support doesn't reply on the forum? Should I open a ticket?

What's going on?
 
Huh! I probably blind. )
It's here!

HTTP/1.1 200 OK =>
Server => nginx/1.14.2
Date => Thu, 16 Jan 2020 08:55:55 GMT
Content-Type => text/html; charset=utf-8
Content-Length => 65185
Connection => close
Vary => Accept-Encoding
X-Frame-Options => SAMEORIGIN
X-Content-Type-Options => nosniff
Expires => Thu, 16 Jan 2020 08:57:18 GMT
Cache-Control => private, no-cache, max-age=0
X-XF-Cache-Status => HIT
Set-Cookie => xf_csrf=........; path=/; secure
Last-Modified => Thu, 16 Jan 2020 08:52:18 GMT
X-Cache => HIT from Backend
Strict-Transport-Security => max-age=31536000

Thank you, OperaManiac!!!
 
do remember that third party sites would show the headers for guests and not logged in members.

so right now I have in my config.php this record:

$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = ['host' => '127.0.0.1', 'password' => 'password'];

It's not clear for me if this is how it should be for caching css, page, registry, sessions?
Or I should put this in config?

$config['cache']['enabled'] = true;
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = ['host' => '127.0.0.1', 'password' => 'my_password'];

And what about css caching? I can still see links to css.php file in html code, so css is not caching?
That's very confusing to those who doesn't know anything about it, like me. )
 
your html code does not change due to caching. check headers of css files to see if they are served from cache or not.

logically speaking... browsers would automatically cache static elements like images and css on first load. so they would be served from local cache after first page load?
 
your html code does not change due to caching. check headers of css files to see if they are served from cache or not.

checked. don't see X-XF-Cache-Status => HIT (

logically speaking... browsers would automatically cache static elements like images and css on first load. so they would be served from local cache after first page load?

well that would be for sure if it would be <link rel="stylesheet" href="/blahblahblah.css" />
but we have <link rel="stylesheet" href="/css.php?blahblahblah" />
I'm not sure that browsers do cache php files.
 
i am personally not sure what all redis is supposed to cache. personally i am quite happy with the loading speed of pages on my own website with redis enabled. you might also want to look at cloudflare to improve caching of static elements!
 
So what's the scoop with xenforo tech support? Two weeks already gone since I asked for help. It's not like I'm trying to modify something, I'm trying to use build in option of the software I paid for. Tech support doesn't reply on the forum?

The forums are for community support, staff sometimes replies in the forums but not always.
 
i am personally not sure what all redis is supposed to cache.
personally i am quite happy with the loading speed of pages on my own website with redis enabled. you might also want to look at cloudflare to improve caching of static elements!

I tried cloudflare but my google adsense earnings went down so I had to disable cloudflare.
 
Back
Top Bottom