Joomla and Memcache (with UNIX sockets)

Memcache or Memcached?

This tutorial has been tested with Memcached (with a trailing d), but it should work with Memcache too.

Be aware they are two different software, made by different authors.

0. Install (if you haven’t yet)

1. Install server and PHP module


sudo apt install php-memcached memcached

2. To test it, create a phpinfo.php file in the Joomla root folder:

3. Open the page in your browser:

For example: http://localhost/phpinfo.php

4. Look for a memcached reference:


1. Add memcache to www-data group:


sudo usermod -g www-data memcache

www-data is the default nginx/apache user on most Linux distributions. Change it to your actual user if necessary. You can double check this in your phpinfo:

2. Enable UNIX sockets:

Add these lines to /etc/memcached.conf:

3. Disable TCP (optional)

For extra security, disable TCP connections. Comment these 2 settings on /etc/memcached.conf:

4. Restart service:


sudo service memcached restart

5. Configure Joomla:

At Joomla > Admin > System > Global Configuration > System Tab > Cache Settings:

  • Handler: Memcached
  • Host: /tmp/memcached.sock
  • System Cache: ON

6. Avoid session issues by changing your public $secret:

You are going to experience session issues if multiple Joomla instances are running on the same machine.

To avoid this to happen, do the following:

Open your configuration.php

Change public $secret = 'a unique string';

Needless to say that "a unique string" should be replaced with your own unique string. Joomla's memcached controller uses the $secret value to differentiate between instances so sessions don't get mixed up.

Do this step NOW even if you have just one Joomla instance installed. This is going to avoid future issues.

7. Sessions with Memcached

For extra speed, enable Memcached for your Sessions:


TROUBLESHOOTING:

  1. If you see the following error message, fix it with step 6 ("avoid session issues"):

This is a common issue, especially if you have cloned your website and haven't changed the "secret" variable.

Close Menu