If Bitrix (Bitrix24) shows the error "Memcache extension is not loaded", it means the Memcache PHP extension is missing or not enabled. This guide will help you install and configure Memcache correctly to improve your Bitrix site's performance through caching.
First, verify whether the Memcache extension is already present on your system.
php -m | grep memcache
Expected Results:
memcache or memcached in the output, the extension is installed but may not be enabled for your web server's PHP configuration.Also check if the Memcached service is running:
systemctl status memcached
And verify your PHP version to install the correct package:
php -v
Memcache requires two components: the Memcached service/daemon and the PHP extension.
sudo apt update
sudo apt install memcached libmemcached-tools -y
sudo yum install memcached -y
After installation, start and enable the service:
sudo systemctl start memcached
sudo systemctl enable memcached
sudo apt install php7.4-memcache php7.4-memcached -y
sudo apt install php8.0-memcache php8.0-memcached -y
sudo apt install php8.1-memcache php8.1-memcached -y
# Enable Remi repository first if needed
sudo yum install php-pecl-memcache php-pecl-memcached -y
# Check both extensions
php -m | grep -E "memcache|memcached"
# You should see both memcache and memcached listed
If the extension is installed but not being loaded by your web server's PHP, you need to enable it in the appropriate php.ini file.
# For command-line PHP (initial check)
php --ini | grep "Loaded Configuration File"
# For web server PHP (may be different)
sudo find /etc -name "php.ini" | grep -E "(apache2|fpm|httpd)"
# For Apache on Ubuntu/Debian
sudo nano /etc/php/7.4/apache2/php.ini
# For PHP-FPM (Nginx) on Ubuntu/Debian
sudo nano /etc/php/7.4/fpm/php.ini
# For CentOS/RHEL
sudo nano /etc/php.ini
Search for or add these lines in the extensions section:
extension=memcache.so
extension=memcached.so
Save the file (Ctrl+O, Enter, Ctrl+X).
# For Apache
sudo systemctl restart apache2
# For Nginx with PHP-FPM
sudo systemctl restart php7.4-fpm
sudo systemctl restart nginx
# For CentOS Apache
sudo systemctl restart httpd
# Always restart Memcached service too
sudo systemctl restart memcached
php -m | grep -E "memcache|memcached"
After installing and enabling the extension, configure Bitrix to use Memcache for caching.
sudo nano /home/user/public_html/bitrix/php_interface/dbconn.php
Replace /home/user/public_html/ with your actual Bitrix installation path.
Find the section where cache settings are defined (usually near the end) and add or modify:
// Memcache configuration for Bitrix
define("BX_CACHE_TYPE", "memcache");
define("BX_MEMCACHE_HOST", "127.0.0.1");
define("BX_MEMCACHE_PORT", "11211");
define("BX_CACHE_SID", $_SERVER["DOCUMENT_ROOT"]."|site");
// Optional: Use Memcached instead (recommended)
// define("BX_CACHE_TYPE", "memcached");
// For multiple Memcache servers (clustered setup)
// define("BX_MEMCACHE_HOST", "mem1.site.com;mem2.site.com");
BX_CACHE_TYPE: Use "memcache" for the older extension or "memcached" for the newer oneBX_MEMCACHE_HOST: 127.0.0.1 for local server, or external IP/hostname for remoteBX_MEMCACHE_PORT: Default is 11211127.0.0.1:11211# Create a test file (in a secure location, not web root for production)
echo "<?php phpinfo(); ?>" | sudo tee /home/user/public_html/test_memcache.php
Visit http://yourdomain.com/test_memcache.php and search for "memcache" or "memcached". You should see configuration sections for both extensions.
sudo rm /home/user/public_html/test_memcache.php
# Test Memcached service connectivity
echo "stats" | nc 127.0.0.1 11211
# Test PHP Memcache functionality
php -r "\$mem = new Memcache; \$mem->connect('127.0.0.1', 11211); echo \$mem->getVersion();"
| Issue | Solution |
|---|---|
| Memcache not installed | sudo apt install php7.4-memcache php7.4-memcached |
| Memcache extension not loaded | Add extension=memcache.so and extension=memcached.so in php.ini |
| Bitrix not using Memcache | Configure dbconn.php with BX_CACHE_TYPE, BX_MEMCACHE_HOST, BX_MEMCACHE_PORT |
| Memcache service not running | sudo systemctl restart memcached |
| PHP version mismatch | Install correct version package: php7.4-memcache for PHP 7.4, etc. |
| Web server not recognizing changes | Restart Apache/Nginx and PHP-FPM services |
| Connection refused errors | Check firewall: sudo ufw allow 11211/tcp or firewall-cmd --add-port=11211/tcp |
With Memcache properly installed and configured, Bitrix will use memory-based caching to significantly improve page load times and reduce database load!