How to Install memcached on CentOS Plesk Server
Install memcached daemon with command
1 |
yum install Memcached |
Enable memcached to start on boot
1 |
systemctl enable memcached |
Start memcached
1 |
systemctl start memcached |
You can verify if memcached is running with the command “netstat -lntp”
1 2 3 4 |
[root@server ~]# netstat -lntp |grep memcache tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 129472/memcached tcp6 0 0 :::11211 :::* LISTEN 129472/memcached [root@server ~]# |
By default Memcached listen on all interfaces (0.0.0.0:11211). You need to make it bind to 127.0.0.1 only, so no one will be able to access your Memcached installation from the public. For securing Memcached installation, refer How to secure Memcached on CentOS 7. After Memcached is secured, you will see it listen on 127.0.0.1 only like the following
1 2 3 |
[root@server etc]# netstat -lntp | grep mem tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 81636/memcached [root@server etc]# |
Install memcached PHP Module
Install the requirements
1 |
yum install -y libmemcached-devel zlib-devel |
Replace default system PHP with PHP version on which you need memcache PHP module installed. In this case, I will be installing the PHP module for PHP version 7.4
1 2 3 4 5 |
cd /usr/bin mv php php.old mv phpize phpize.old ln -s /opt/plesk/php/7.4/bin/php ln -s /opt/plesk/php/7.4/bin/phpize |
Now run the command
1 |
/opt/plesk/php/7.4/bin/pecl install memcached |
If you get error related to phpize missing, you need to install PHP devel package.
1 |
yum install plesk-php74-devel |
After install finished, you need to edit php.ini
1 |
vi /opt/plesk/php/7.4/etc/php.ini |
At end of the file, add
1 |
extension=memcached.so |
Restart php-fpm
1 |
systemctl restart plesk-php74-fpm.service |
Install memcache module
the latest version of memcache won’t work with PHP 7.4, so we need to use an older version.
To install version 4.0.5.2 of memcache, run
1 |
/opt/plesk/php/7.4/bin/pecl install memcache-4.0.5.2 |
After installing, edit php.ini file
1 |
vi /opt/plesk/php/7.4/etc/php.ini |
At end of the file, add
1 |
extension=memcache.so |
Restart php-fpm
1 |
systemctl restart plesk-php74-fpm.service |