Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an Ubuntu machine with nginx and memcache running, and I'm trying to use PHP with Memcached. I'm getting Fatal error: Class 'Memcached' not found.

The ini file is loaded from /etc/php5/fpm/php.ini, and all other additional .ini files are parsed, except memcached.ini (even after restarting nginx) as seen in phpinfo()'s output.

output for phpinfo()

I tried apt-get install php5-memcache and it completed without errors. However, pecl install memcached fails with the below error:

In file included from /tmp/pear/temp/memcached/php_memcached.h:22:0,
                 from /tmp/pear/temp/memcached/php_memcached.c:47:
/tmp/pear/temp/memcached/php_libmemcached_compat.h:5:40: fatal error: libmemcached-1.0/memcached.h: No such file or directory
compilation terminated.
make: *** [php_memcached.lo] Error 1
ERROR: `make' failed

The server has libmemcache in /usr/include/libmemcached, but even pecl install with --with-libmemcache=/usr/include/libmemcached fails.

The output for php -i | grep -i memcache is as below:

/etc/php5/cli/conf.d/memcached.ini,
memcached
memcached support => enabled
libmemcached version => 0.44
Registered save handlers => files user memcached 
PWD => /usr/include/libmemcached
_SERVER["PWD"] => /usr/include/libmemcached

I'm not sure what else to check. Much appreciated if someone could help me out with something to fix this.

Thanks!

[UPDATE] Memcached is working from cli.

share|improve this question

2 Answers 2

What is the output of

php -i |grep memcache

I've used memcache for storing php sessions as well as Magento Cache & Sessions.

There are two things not to be confused with:

  1. Memcached -> Note the 'd' which is a daemon listens on port no: 11211. It can be used to store php sessions instead of file system etc..

  2. Memcache -> a module usually not compiled with php. it's used when you want to store your php sessions in memcached.

so if php -i |grep memcache shows you have memcache installed. Then you need to install memcached (daemon) to be able to use/send sessions to it.

share|improve this answer
    
I have installed Memcached, and not Memcache - adding the output for php -i | grep -i memcache to my question. But again, the ini loaded here is from php5/cli/ and for nginx is from php5/fpm/. I am not sure if it really matters, because the conf.d is the same. –  shyam Jan 7 at 10:34
up vote 0 down vote accepted

I solved the issue. The only thing I had to do was restart php5-fpm
sudo service php5-fpm restart.

Found this in - https://insready.com/en/blog/building-nginx-microcaching-mariadbmysql-php-fpm-debian-6-apc-memcache-drupal-7-server

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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