How to: Install Memcached on Centos 7 with Cpanel & PHP 7.3
I was trying to install memcached for PHP 7.3 on a Cpanel server and kept running into various errors so I wanted to document how I did it in case it’s helpful for someone else as well as to document it for myself as no doubt I will need to do this on other servers.
First, I tried using the PHP PECL module installer, searching for “memcache” and clicking “install” – It’s supposed to be just that simple, right?
Nope. First error:
ERROR: `/root/tmp/pear/memcached/configure --with-php-config=/opt/cpanel/ea-php73/root/usr/bin/php-config
So off to the internets I go to try and find a solution. I found a couple install guides like this one for php 7.2 and figured I would try them with some minor changes to the path for 7.3 of course.
Everything looked fine until attempting to verify:
/opt/cpanel/ea-php73/root/usr/bin/php -m | grep memcache
Tried to install it again via module installer. This time:
fatal error: ext/standard/php_smart_str.h: No such file or directory
So then I tried to manually install it.
# wget https://pecl.php.net/get/memcached
# tar -xvf memcached
# cd memcached-3.1.4/
# /opt/cpanel/ea-php73/root/usr/bin/phpize && ./configure --enable-memcache --with-php-config=/opt/cpanel/ea-php73/root/usr/bin/php-config
At this point I got this warning:
configure: WARNING: unrecognized options: –enable-memcache
But I couldn’t find anything specific enough to figure out what it was about so I decided to just continue:
Don’t forget to run ‘make test’.
# make test
# cp memcached.so /opt/cpanel/ea-php73/root/usr/lib64/php/modules/
# /opt/cpanel/ea-php73/root/usr/bin/php -m | grep memcache
Response with “memcached” means success. However I still didn’t see it in WHM, PHP PECL modules. I ran the WHM Module PHP PECL install again, and this time it was using memcached 3.1.4 since it was locally on the server and completed installed correctly. Now it should be available to manage within WHM, or at least recognized there.
Don’t forget to restart Apache and PHP-FPM if applicable.