This is an old revision of the document!
How to use memcached in UNIX socket?
Memcached can also run in UNIX socket which provides better performance than TCP connection.
Note
Please use root privilege to the following instructions.
If memcached failed to start , it is usually due to permission and user problem , please check the socket path is writable to designated user.
for Centos7.X
1. Stop memcached
systemctl stop memcached
2. Copy file service file
cp /usr/lib/systemd/system/memcached.service /etc/systemd/system/memcached.service
3. Add following content to /etc/systemd/system/memcached.service ,after [Service], please change username to the same user that runs PHP
User=username Group=username
4. Edit /etc/sysconfig/memcached , please change path to your desired location. change from
OPTIONS=""
to
OPTIONS="-s /path/to/memcached.sock -a 0770"
and change username to the same user name in step 3. change from
USER="memcached"
to
USER="username"
5. Now start memcached again
systemctl start memcached
6. Check if it started successfully ,
systemctl status memcached
7. Check if everything goes well.
nc -U /path/to/memcached.sock
and then type
stats
for Centos6.X
1. Stop memcached
service memcached stop
2. Edit /etc/sysconfig/memcached change
OPTIONS=""
to
OPTIONS="-s /path/to/memcached.sock -a 0770"
change
USER=""
to
USER="username"
, the same user that runs PHP
3. Start memcached
service memcached start
4. Check if everything goes well.
nc -U /path/to/memcached.sock
and then type
stats
for Ubuntu 17.10, Ubuntu 16.04, Debian 8 and Debian 9
1. Stop memcached
systemctl stop memcached
2. Edit
/etc/memcached.conf
comment out host and port , add socket path and permission.
-s /path/to/memcached.sock -a 0770
and change
-u memcache
to
-u username
the same user that runs PHP
3. Start memcached again
systemctl start memcached
4. Check if everything goes well.
nc -U /path/to/memcached.sock
and then type
stats
for Ubuntu 14.04 and Debian 7
1. Stop memcached
service memcached stop
2. Edit
/etc/memcached.conf
comment out host and port , add socket path and permission.
-s /path/to/memcached.sock -a 0770
and change
-u memcache
to
-u username
the same user that runs PHP
3. Start memcached again
service memcached start
4. Check if everything goes well.
nc -U /path/to/memcached.sock
and then type
stats