PHP Fatal error: Class Memcache not found in
Introduction
The error “PHP Fatal error: Class ‘Memcache’ not found” usually occurs when the Memcache PHP module is missing or not properly compiled in PHP. This issue commonly affects PHP applications that depend on the Memcache extension for caching functionality.
In some cases, enabling Memcache through EasyApache may show the module as enabled, but the extension may not actually compile correctly in PHP. In such situations, compiling the Memcache module manually from source is the recommended solution.
Prerequisites
- Root or SSH access to the server
- PHP development tools installed
- Internet connection on the server
- Basic knowledge of Linux commands
Implementation
Error Message
PHP Fatal error: Class ‘Memcache’ not found in
This error generally occurs when the Memcache PHP module is missing.
Step 1 – Download Memcache Source
mkdir repo
cd repo
wget http://pecl.php.net/get/memcache-3.0.6.tgz
tar -xvfz memcache-3.0.6.tgz
Step 2 – Compile and Install Memcache
cd memcache-3.0.6
phpize
You should see output similar to the following:
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Now continue with the compilation process:
./configure
make
make install
Step 3 – Enable Memcache in PHP
Add the Memcache extension entry to the php.ini file:
echo “extension=memcache.so” >> /usr/local/lib/php.ini
Restart Apache service:
service httpd restart
Verify the Installation
Check the Loaded php.ini File
php -i | grep php.ini
Example output:
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini
Verify Memcache Module
php -m | grep memcache
Expected output:
memcache
Example Installation Output
mkdir repo
cd repo
wget http://pecl.php.net/get/memcache-3.0.6.tgz
tar -zxvf memcache-3.0.6.tgz
cd memcache-3.0.6
phpize
./configure
make
make install
echo “extension=memcache.so” >> /usr/local/lib/php.ini
service httpd restart
php -m | grep memcache
Conclusion
By compiling the Memcache module manually from source and enabling it in php.ini, you can successfully resolve the “PHP Fatal error: Class ‘Memcache’ not found” issue on PHP applications running on Linux hosting servers.
