After reading, investigating and tried lot of ways to install PHP-Pecl Memcache module in PHP 7.x I realized that there are many known issues with pecl’s provided memcache module in PHP 7+. But I found a way to install PHP-Memcache on PHP 7.x, keep reading.
Luckly, the guys at Websupport.tk uploaded to Github an alternative version of PHP-Memcache that compiles and works fine in PHP 7.x versions. You can review all the changes at their Github proyect: https://github.com/websupport-sk/pecl-memcache
Step by step: install PHP-Memcache on PHP 7
Download and extract the file
cd /usr/local/src; wget https://github.com/websupport-sk/pecl-memcache/archive/NON_BLOCKING_IO_php7.zip; unzip NON_BLOCKING_IO_php7.zip; cd pecl-memcache-NON_BLOCKING_IO_php7;
Configure, compile and install
/opt/cpanel/ea-php71/root/usr/bin/phpize && ./configure --enable-memcache --with-php-config=/opt/cpanel/ea-php71/root/usr/bin/php-config && make;
Copy and enable the modile inside cPanel PHP 7.1 php.ini files
cp -av modules/memcache.so /opt/cpanel/ea-php71/root/usr/lib64/php/modules/; echo ';enable memcache pecl module php7' > /opt/cpanel/ea-php71/root/etc/php.d/40-memcached.ini; echo 'extension=memcache.so' >> /opt/cpanel/ea-php71/root/etc/php.d/40-memcached.ini;
Restart Apache to apply changes:
/scripts/restartsrv_httpd
After doing so, you will notice that the module is properly being reported by PHP 7.1:
[[email protected]:~]php -v ea-php-cli Copyright 2016 cPanel, Inc. PHP 7.1.0 (cli) (built: Jan 4 2017 15:09:11) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.1.0, Copyright (c) 1999-2016, by Zend Technologies
Now run the following command to see if PHP-Memcache is loaded in your PHP server:
php -i | grep memcache -i
This should be the expected output:
[[email protected]:~]php -i | grep memcache -i /opt/cpanel/ea-php71/root/etc/php.d/40-memcached.ini, memcache memcache support => enabled memcache.allow_failover => 1 => 1 memcache.chunk_size => 32768 => 32768 memcache.compress_threshold => 20000 => 20000 memcache.default_port => 11211 => 11211 memcache.hash_function => crc32 => crc32 memcache.hash_strategy => consistent => consistent memcache.lock_timeout => 15 => 15 memcache.max_failover_attempts => 20 => 20 memcache.protocol => ascii => ascii memcache.redundancy => 1 => 1 memcache.session_redundancy => 2 => 2 Registered save handlers => files user memcache
That’s it. Now you should have PHP-Memcache working fine with PHP 7.x versions on cPanel / EA4 based servers. If you know other ways to install PHP-Memcache on PHP 7.x, please let us know so we can add your method to this tutorial.
Hello,
after following this guide, php is showing the memcache extension but when I try to login I get : PHP WARNING: session_start(): Failed to read session data: memcache
Any help?
Hey Nicola,
Make sure you have memcached system daemon installed and running ok.
Hey Esteban,
yes the deamon is started and listening on port 11211.
root 26650 0.0 0.0 364424 4424 ? Ssl Apr04 3:28 /usr/local/memcached/bin/memcached -d -p 11211 -u root -m 1024 -c 2048 -P /var/run/memcached.pid
I’ve another instance of php5.6.6 and that is pointing to memcached for sessions, and it is working.
I tried installing php7.0.13 and now, I don’t get the error anymore on the apache logs, but the login still does not work.
Make sure your session save path is writable, also read this, just in case:
http://stackoverflow.com/questions/12112319/failed-to-write-session-data-php-and-memcached
Hi Esteban, yes the path is writable as the php5 is writing to it.
I tried installing memcached extension and it worked using ‘127.0.0.1:11211’ but I would like to continue using memcache for failover etc. Any other suggestion?
This is my php.ini now :
session.save_handler = memcache
session.save_path = ‘tcp://127.0.0.1:11211’
memcache.lock_timeout = 60
extension=memcache.so
Right now I can’t think about any other solution, you need to investigate more I’m afraid.
Sorry I can’t help you this time. Good luck.