How to use Redis in a UNIX Socket
Please use root privilege to execute the following instructions. If Redis fails to start, please verify SELinux is disabled , and all mentioned directories and files have correct permissions to the designated user.
for Centos 7.X
- Stop Redis.
systemctl stop redis
- Copy the service file.
cp /usr/lib/systemd/system/redis.service /etc/systemd/system/redis.service
- Edit
/etc/systemd/system/redis.service
.User=username Group=username
Change
username
to same user that runs PHP. - Edit
/etc/redis.conf
and change the following:unixsocket /path/to/redis.sock unixsocketperm 770 logfile /path/to/redis.log dir /path/to/redis
Change port to
0
if TCP socket is no longer needed. - Change owner of redis.conf to same username in step 3.
chown username:group /etc/redis.conf
If
/path/to/redis
directory does not exist, please manually create it, and make sure above mentionedsocket path
,log path
anddir path
and are writable by the designated user. - Start Redis.
systemctl start redis
- Verify it started successfully.
systemctl status redis
- Check whether everything is working well.
nc -U /path/to/redis.sock info