PHP memcached Fatal error: Class ‘Memcache’ not found

I had this problem on an older Debian system we are supporting. After installing memcached and php5-memcached packages, the PHP interpreter didn’t find the required functions (take a look at this comment for a simple test script).

Turns out, Debian has different configuration for different environments (cli, apache2, php-fpm, etc) and apparently the guy providing the php5-memcached package wasn’t aware of that, so I fixed this error by creating a link to the memcache php-ini config for each environment:

# cd /etc/php5/apache2/conf.d
# ln -s ../../conf.d/memcached.ini ./
# cd /etc/php5/cli/conf.d
# ln -s ../../conf.d/memcached.ini ./
# # ls -l /etc/php5/*/conf.d/
total 32K
lrwxrwxrwx 1 root root   26 Jul 18 14:48 memcached.ini -> ../../conf.d/memcached.ini
total 32K
lrwxrwxrwx 1 root root   26 Jul 18 14:46 memcached.ini -> ../../conf.d/memcached.ini
# php -i | grep -i memcache
memcached support => enabled
libmemcached version => 0.40
Registered save handlers => files user memcached 


I wanted to share this link because I found it to be one of the most informative posts I’ve read in a while; it’s about using parted to properly align partitions for best performance: