On my CentOS 7, Memcached is running and working on SSH but not working in the PHP file. I've followed this article: https://www.mynotepaper.com/install-memcached-on-centos-7. This method was working fine on my previous server.

I've tested Memcached using telnet. It works fine.

$ telnet 11211
Connected to
Escape character is '^]'.
set test 0 100 5
get test
VALUE test 0 5

After storing data using telnet, I've tested on SSH via PHP command. It works too:

php -r '$c = new Memcached(); $c->addServer("", 11211); var_dump( $c->getAllKeys() );'
array(1) {
  string(4) "test"

But in PHP file, it doesn't work. The PHP code:

$c = new Memcached();
$c->addServer("", 11211);
var_dump( $c->getAllKeys() );

It always shows bool(false). Here's my PHP info's screenshot.

Could you please tell me what's my mistake?

  • How do you run the PHP script. Does it run from an Apache webserver with PHP module integrated? What does getenforce return? – Gerrit Feb 6 '20 at 16:56
  • Hi @user188737, I've tested on Apache & Nginx webserver with PHP module integrated. In my machine, SELinux is enabled. Do you think I'm facing the issue for SELinux? If so, could you please tell me the way to run Memcached in PHP file without disabling SELinux? – Md Obydullah Feb 7 '20 at 8:53

To allow a httpd integrated PHP module to do network access (even if it is to loopback network) in an enforcing SELinux environment, you have to do on your server (as root or with sudo):

setsebool -P httpd_can_network_connect on

Listing of booleans and info on Centos Wiki: https://wiki.centos.org/TipsAndTricks/SelinuxBooleans

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.