Solved Redis in FreeBSD jail

masteroman

Member

Reaction score: 8
Messages: 30

I've been using jails and managing them with ezjail, as such I'm not using vimage jails but plain ol' jails. In one of the jails I have installed Nginx, PHP-FPM, Redis, and Wordpress located on one of the user accounts within jail.

When configuring Redis to listen on 127.0.0.1 it binds to all interfaces since 127.0.0.1 isn't dedicated to that particular jail. When it is configured that way you're able to access it over the internet (I don't want that) and you're able to normally use https://wordpress.org/plugins/redis-cache/ plugin in wordpress to use redis as object cache backend.

If I configure Redis to use any other IP (127.0.0.131 is the one I have assigned on lo0 interface within the jail) this plugin fails to connect, no matter if I specify correct host to connect and settings reflect that.

I've also tried setting up this particular plugin to use:

Code:
define( 'WP_REDIS_SCHEME', 'unix' );
define( 'WP_REDIS_PATH', '/var/run/redis/redis.sock' );
In other words to connect via unix socket, but that doesn't work as well. It is trying to establish connection via PECL redis extension.

I've tried to change permissions on unix socket to 777 briefly for testing purposes but setting them up that way also didn't resolve the issue and wordpress is still unable to connect to the redis instance.

Redis sockstat output:

root@www:~ # sockstat -l |grep redis
redis redis-serv 4473 4 tcp4 127.0.0.131:6379 *:*
redis redis-serv 4473 5 stream /var/run/redis/redis.sock


PHP-FPM pool sockstat:

root@www:~ # sockstat -l | grep php
USER php-fpm 5773 0 stream /var/run/www.DOMAIN
USER php-fpm 3412 0 stream /var/run/www.DOMAIN


User ID:

root@www:~ # id USER
uid=1001(USER) gid=1001(USER) groups=1001(USER),535(redis)


Redis Socket:

root@www:~ # ls -ld /var/run/redis/
drwxr-xr-x 2 redis redis 4 Feb 26 21:21 /var/run/redis/
root@www:~ # ls -ld /var/run/redis/redis.sock
srwxrwx--- 1 redis redis 0 Feb 26 21:21 /var/run/redis/redis.sock


So according to that there should be no permission issues when connecting to the Redis socket. Also worth mentioning that I'm using redis as PHP session handler without any issues in the same PHP-FPM pool:

Code:
php_value[session.save_handler] = redis
php_value[session.save_path]    = "unix:///var/run/redis/redis.sock"
This may sound like XY problem but what I'm really asking here if anybody is using similar setup on FreeBSD, within Jail, and does anybody have some suggestions on what to check next in order to allow connection from Wordpress plugin to Redis instance?
 
OP
OP
masteroman

masteroman

Member

Reaction score: 8
Messages: 30

Ok, I think I figured this out, it is an issue with plugin itself not properly setting up connection.
 

fred974

Daemon

Reaction score: 36
Messages: 1,584

masteroman
would you mind sahring your config files?
I am trying to cache wordpress as well but all i found is not working so far.
Do you have 1 redis per domain jail or multiple?
 
OP
OP
masteroman

masteroman

Member

Reaction score: 8
Messages: 30

masteroman
would you mind sahring your config files?
I am trying to cache wordpress as well but all i found is not working so far.
Do you have 1 redis per domain jail or multiple?
Basically it was simple issue and oversight on my end. Issue was with not placing connection settings high enough in wp-config.php file when defining connection setting.

I have both redis and wordpress in the same jail.
 
Top