Connecting to memcached on shared hosting
Instructions on how to set up memcached access in popular CMS on shared hosting.
On shared hosting, Memcached is available via a socket, with both PHP extensions memcache and memcached supported. By default, each user gets 32 MB of memory. If you need more, you can request an increase through the ticket system.
Depending on which PHP extension you’re using, the socket path is specified differently:
For php-memcache:
Socket path: unix:///user_home_directory/.memcached/memcached.sock
Port: 0
For php-memcached:
Socket path: user_home_directory/.memcached/memcached.sock
Port: 0
You can find the correct home directory in cPanel on the General Information page.
Using Memcached in Joomla 5
Since Joomla comes with Memcached support out of the box, no extra plugins are needed.
Log into your Joomla admin panel and go to System → Global Configuration → System. In the caching and session settings, configure the following:
- Cache Handler —
Memcached
- Memcache(d) Server Host —
user_home_directory/.memcached/memcached.sock
- Memcache(d) Server Port —
11211
Click Save to apply the changes.
Using Memcached in WordPress
WordPress doesn’t support Memcached natively, but you can use plugins. One of the most popular is W3 Total Cache.
Go to the plugin settings → General Settings, and set Page Cache Method to Memcached.
Then, for each cache type, you’ll need to provide connection details. Go to Page Cache → Advanced and enter:
user_home_directory/.memcached/memcached.sock:0
Using Memcached in OpenCart
OpenCart has built-in Memcached support. To enable it:
OpenCart 3.0
Add the following lines to the end of both config.php
and admin/config.php
:
define('CACHE_HOSTNAME', '/home/YOUR_ACCOUNT/.system/memcache/socket');
define('CACHE_PORT', '0');
define('CACHE_PREFIX', 'oc_');
OpenCart 2.2–2.3 Add to both config files:
define('CACHE_HOSTNAME', 'unix:///home/YOUR_ACCOUNT/.system/memcache/socket');
define('CACHE_PORT', '0');
define('CACHE_PREFIX', 'oc_');
In system/config/default.php
, change:
$_['cache_type'] = 'file';
to:
$_['cache_type'] = 'mem';
Using Memcached in Bitrix
Bitrix supports Memcached through the php-memcache extension, but only on PHP 5.3–5.6.
To configure it, add the following lines to bitrix/php_interface/dbconn.php:
define("BX_CACHE_TYPE", "memcache");
define("BX_CACHE_SID", $_SERVER["DOCUMENT_ROOT"]."#01");
define("BX_MEMCACHE_HOST", "unix:///user_home_directory/.memcached/memcached.sock");
define("BX_MEMCACHE_PORT", "0");
Also, add this to bitrix/.settings_extra.php:
<?php
return array(
'cache' => array(
'value' => array(
'type' => 'memcache',
'memcache' => array(
'host' => 'unix:///user_home_directory/.memcached/memcached.sock',
'port' => '0',
),
'sid' => $_SERVER["DOCUMENT_ROOT"]."#01"
),
),
);
Note
If bitrix/.settings_extra.php doesn’t exist, you’ll need to create it manually.
Using Memcached in DLE
DLE also supports Memcached natively. To enable it:
Go to your admin panel → System Settings → Optimization. Set Cache Type to Memcache and in Memcache Server Connection Data enter:
user_home_directory/.memcached/memcached.sock
Using Memcached in Drupal
Drupal 7
Drupal doesn’t have native Memcached support, so you’ll need to install the Memcache module.
Once installed, enable it in the “Modules” section and add the following to /sites/default/settings.php (replace your_login
with your hosting account name):
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
$conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';
$conf['memcache_stampede_protection'] = TRUE;
$conf['cache_default_class'] = 'MemCacheDrupal';
// The 'cache_form' bin must be assigned to non-volatile storage.
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
// Don’t bootstrap the DB when serving cached pages.
$conf['page_cache_without_database'] = TRUE;
$conf['page_cache_invoke_hooks'] = FALSE;
$conf['memcache_servers'] = array('unix:///home/your_login/.memcached/memcached.sock' => 'default');
Drupal 8+
// Memcache configuration
$settings['memcache']['servers'] = ['unix:///home/your_login/.memcached/memcached.sock' => 'default'];
$settings['memcache']['bins'] = ['default' => 'default'];
$settings['memcache']['key_prefix'] = '';
$settings['cache']['default'] = 'cache.backend.memcache';
Help
If you run into any issues or need help, just open a ticket in our support system, and we’ll be happy to assist.