Linux

How to enable redis.sock on redis server

You want to enable the Unix socket (redis.sock) for your Redis server. By default Redis only listens on TCP (127.0.0.1:6379), so you have to configure the socket manually.

Here’s the step-by-step guide (works on CentOS/RHEL with yum install redis, but very similar for Ubuntu/Debian too):

1. Edit the Redis config

Open the Redis config file (location may vary):

sudo nano /etc/redis.conf

or sometimes:

sudo nano /etc/redis/redis.conf

Find and uncomment / add these lines:

# Enable Unix socket
unixsocket /var/run/redis/redis.sock
unixsocketperm 770
  • unixsocket → path of the socket file. Commonly /var/run/redis/redis.sock.

  • unixsocketperm → permissions for the socket (770 means: owner + group can access).

2. Make sure the directory exists

sudo mkdir -p /var/run/redis
sudo chown redis:redis /var/run/redis

3. Add your web/PHP user to the redis group

sudo usermod -aG redis nginx
# or if using Apache with PHP-FPM
sudo usermod -aG redis apache
# or a DirectAdmin user
sudo usermod -aG redis user1

Replace with the actual user running PHP-FPM.

4. Restart Redis

sudo systemctl restart redis

5. Verify socket

ls -l /var/run/redis/redis.sock

Expected output (permissions may vary):

srwxrwx--- 1 redis redis 0 Sep 12 10:00 /var/run/redis/redis.sock

6. Test connection

redis-cli -s /var/run/redis/redis.sock ping

Should return:

PONG

Now Redis is listening on both TCP (127.0.0.1:6379) and the Unix socket (/var/run/redis/redis.sock).

Thanks for visit my website