cPanel

Install Memcache on cPanel server

Install Memcache
Install Memcache

Install Memcache on cPanel server

Memcache is a high-performance, distributed memory caching system. It provides fast access to cached data. Here I am explaining how to install Memcache on cPanel server.

Please note that you need to install Memcached daemon for the proper functioning of Memcache. You can install the daemon by using the yum package manager.

 
yum install memcached

Then start the daemon.

 
/etc/init.d/memcached start

Enable the Memcached daemon on chkconfig. It will make sure the Memcached daemon start automatically after the server reboot.

 
chkconfig memcached on

 

Once the daemon is installed, you can proceed with the installation of Memcache PHP extension using pecl.

We are using different methods to install Memcache PHP extension in EasyApache3 and EasyApache4

Installation of Memcache PHP extension using EasyApache3

 
pecl install memcache

Also, you can verify the installation by using the following command.

 
php -m | grep memcache

Installation of Memcache PHP extension using EasyApache4

We are using multiple PHP version on EasyApache4, so we need to install the Memcache on each PHP version individually. Run the following commands to install the Memcache module on different PHP versions.

PHP 5.4

 
/opt/cpanel/ea-php54/root/usr/bin/pecl install memcache

Verify using the following command:

 
/opt/cpanel/ea-php54/root/usr/bin/php -m | grep memcache

PHP 5.5

 
/opt/cpanel/ea-php55/root/usr/bin/pecl install memcache

Verify using the following command:

 
/opt/cpanel/ea-php55/root/usr/bin/php -m | grep memcache

PHP 5.6

 
/opt/cpanel/ea-php56/root/usr/bin/pecl install memcache

Verify using the following command:

 
/opt/cpanel/ea-php56/root/usr/bin/php -m | grep memcache

PHP 7.0

 
cd /usr/local/src/
wget https://github.com/websupport-sk/pecl-memcache/archive/NON_BLOCKING_IO_php7.zip
unzip NON_BLOCKING_IO_php7.zip
mv pecl-memcache-NON_BLOCKING_IO_php7 pecl-memcache-NON_BLOCKING_IO_php70
cd pecl-memcache-NON_BLOCKING_IO_php70
/opt/cpanel/ea-php70/root/usr/bin/phpize 
./configure --enable-memcache --with-php-config=/opt/cpanel/ea-php70/root/usr/bin/php-config
make
cp modules/memcache.so /opt/cpanel/ea-php70/root/usr/lib64/php/modules/
echo 'extension=memcache.so' > /opt/cpanel/ea-php70/root/etc/php.d/memcached.ini

Verify:

 
/opt/cpanel/ea-php70/root/usr/bin/php -m | grep memcache

PHP 7.1

 
cd /usr/local/src/
wget https://github.com/websupport-sk/pecl-memcache/archive/NON_BLOCKING_IO_php7.zip
unzip NON_BLOCKING_IO_php7.zip
mv pecl-memcache-NON_BLOCKING_IO_php7 pecl-memcache-NON_BLOCKING_IO_php71
cd pecl-memcache-NON_BLOCKING_IO_php71
/opt/cpanel/ea-php71/root/usr/bin/phpize && ./configure --enable-memcache --with-php-config=/opt/cpanel/ea-php71/root/usr/bin/php-config
make
cp modules/memcache.so /opt/cpanel/ea-php71/root/usr/lib64/php/modules/
echo 'extension=memcache.so' > /opt/cpanel/ea-php71/root/etc/php.d/memcached.ini

Verify:

 
/opt/cpanel/ea-php71/root/usr/bin/php -m | grep memcache

PHP 7.2

 
cd /usr/local/src/
wget https://github.com/websupport-sk/pecl-memcache/archive/NON_BLOCKING_IO_php7.zip
unzip NON_BLOCKING_IO_php7.zip
mv pecl-memcache-NON_BLOCKING_IO_php7 pecl-memcache-NON_BLOCKING_IO_php72
cd pecl-memcache-NON_BLOCKING_IO_php72
/opt/cpanel/ea-php72/root/usr/bin/phpize && ./configure --enable-memcache --with-php-config=/opt/cpanel/ea-php72/root/usr/bin/php-config
make
cp modules/memcache.so /opt/cpanel/ea-php72/root/usr/lib64/php/modules/
echo 'extension=memcache.so' > /opt/cpanel/ea-php72/root/etc/php.d/memcached.ini

Verify:

 
/opt/cpanel/ea-php72/root/usr/bin/php -m | grep memcache

Restart Apache:

 
service httpd restart

That’s it!

Also Read: How to Install varnish on cPanel

If you like this post and wish to receive more articles from us, please like our FB page: Grepitout

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.

For more details on our services, please drop us an E-mail at info@grepitout.com

5 Comments

Click here to post a comment

  • Solution for easyapache 4 and php7.0 worked well, memcache is enabled, but not for php7.1. I am following steps described here, there are no errors but /opt/cpanel/ea-php71/root/usr/bin/php -m | grep memcache just does not show memcache

    • Did you restart Apache before executing the command “/opt/cpanel/ea-php71/root/usr/bin/php -m | grep memcache”?

      I tried to recreate this issue on my test server and the Memcache module installed successfully on PHP 7.1.

      ====
      [root@server ~]# /opt/cpanel/ea-php71/root/usr/bin/php -m | grep memcache
      memcache
      [root@server ~]#
      ====

  • Hello.

    Do you have instructions for PHP 7.3?

    I tried this:

    cd /usr/local/src/
    wget https://github.com/websupport-sk/pecl-memcache/archive/NON_BLOCKING_IO_php7.zip
    unzip NON_BLOCKING_IO_php7.zip
    mv pecl-memcache-NON_BLOCKING_IO_php7 pecl-memcache-NON_BLOCKING_IO_php73
    cd pecl-memcache-NON_BLOCKING_IO_php73
    /opt/cpanel/ea-php73/root/usr/bin/phpize && ./configure –enable-memcache –with-php-config=/opt/cpanel/ea-php73/root/usr/bin/php-config
    make
    cp modules/memcache.so /opt/cpanel/ea-php73/root/usr/lib64/php/modules/
    echo ‘extension=memcache.so’ > /opt/cpanel/ea-php73/root/etc/php.d/memcached.ini

    /opt/cpanel/ea-php73/root/usr/bin/php -m | grep memcache

    I got this error on “make”:

    /bin/sh /usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/libtool –mode=compile cc -I/opt/cpanel/ea-php73/root/usr/include/php -I. -I/usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73 -DPHP_ATOM_INC -I/usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/include -I/usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/main -I/usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73 -I/opt/cpanel/ea-php73/root/usr/include/php -I/opt/cpanel/ea-php73/root/usr/include/php/main -I/opt/cpanel/ea-php73/root/usr/include/php/TSRM -I/opt/cpanel/ea-php73/root/usr/include/php/Zend -I/opt/cpanel/ea-php73/root/usr/include/php/ext -I/opt/cpanel/ea-php73/root/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/php7/memcache.c -o php7/memcache.lo
    libtool: compile: cc -I/opt/cpanel/ea-php73/root/usr/include/php -I. -I/usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73 -DPHP_ATOM_INC -I/usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/include -I/usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/main -I/usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73 -I/opt/cpanel/ea-php73/root/usr/include/php -I/opt/cpanel/ea-php73/root/usr/include/php/main -I/opt/cpanel/ea-php73/root/usr/include/php/TSRM -I/opt/cpanel/ea-php73/root/usr/include/php/Zend -I/opt/cpanel/ea-php73/root/usr/include/php/ext -I/opt/cpanel/ea-php73/root/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/php7/memcache.c -fPIC -DPIC -o php7/.libs/memcache.o
    /usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/php7/memcache.c: In function ‘php_mmc_store’:
    /usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/php7/memcache.c:643:4: error: too many arguments to function ‘mmc_prepare_key_e ‘
    if (mmc_prepare_key_ex(ZSTR_VAL(key), ZSTR_LEN(key), request->key, &(request->key_len), MEMCACHE_G(key_prefix)) != MMC_OK) {
    ^
    In file included from /usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/php7/php_memcache.h:34:0,
    from /usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/php7/memcache.c:30:
    /usr/local/src/pecl-memcache-NON_BLOCKING_IO_php73/php7/memcache_pool.h:399:5: note: declared here
    int mmc_prepare_key_ex(const char *, unsigned int, char *, unsigned int *);

Topics