Tag: memcache

  • How to Install memcached on CentOS Plesk  Server

    How to Install memcached on CentOS Plesk Server

    Install memcached daemon with command

    yum install Memcached
    

    Enable memcached to start on boot

    systemctl enable memcached
    

    Start memcached

    systemctl start memcached
    

    You can verify if memcached is running with the command “netstat -lntp”

    [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

    [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

    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

    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

    /opt/plesk/php/7.4/bin/pecl install memcached
    

    If you get error related to phpize missing, you need to install PHP devel package.

    yum install plesk-php74-devel
    

    After install finished, you need to edit php.ini

    vi /opt/plesk/php/7.4/etc/php.ini
    

    At end of the file, add

    extension=memcached.so
    

    Restart php-fpm

    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

    /opt/plesk/php/7.4/bin/pecl install memcache-4.0.5.2
    

    After installing, edit php.ini file

    vi /opt/plesk/php/7.4/etc/php.ini
    

    At end of the file, add

    extension=memcache.so
    

    Restart php-fpm

    systemctl restart plesk-php74-fpm.service