Let's see how to use Memcache to improve the performance of your Joomla installation.
They are two different software, made by different authors, but mostly compatible with each other.
This tutorial has been tested with Memcached (with a trailing d), but it should work with Memcache too.
sudo apt install php-memcached memcached
phpinfo.php
file in the Joomla root folder<?php phpinfo();
Example: http://localhost/phpinfo.php
memcache
user to www-data
groupsudo usermod -g www-data memcache
WARNING
Yes, the memcached user is named "memcache" (without a d
). I believe this is for compability reasons with 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:
Add these lines to /etc/memcached.conf
:
# Create unix sock
-s /tmp/memcached.sock
# Set permissions to the group
-a 775
For extra security, disable TCP connections. This prevents accessing it from the outside. Comment these 2 settings on /etc/memcached.conf
:
# Default connection port is 11211
#-p 11211
# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.
#-l 127.0.0.1
sudo service memcached restart
At Joomla
> Admin
> System
> Global Configuration
> System Tab
> Cache Settings
:
Memcached
/tmp/memcached.sock
ON
public $secret
You are going to experience session issues if multiple Joomla instances are running on the same machine.
To avoid this, do the following:
configuration.php
public $secret = 'a unique string';
// configuration.php
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.
WARNING
Do this step NOW even if you have just one Joomla instance installed. This will prevent future issues.
For extra speed, enable Memcached for your Sessions:
If you see the following error message, fix it with step 6 ("avoid session issues"):
Warning: session_start(): Unable to clear session lock record in /var/www/mysite/staging/libraries/joomla/session/handler/native.php on line 260
Warning: session_start(): Failed to read session data: memcached (path: /tmp/memcached.sock:11211) in /var/www/mysite/staging/libraries/joomla/session/handler/native.php on line 260
Error: Failed to start application: Failed to start the session
This is a common issue, especially if you have cloned your website and haven't changed the "secret" variable.