Note: Installing and using Memcached requires access to the command line and the ability to install software on your server. If you are using a Shared Hosting Package, then you may not have access to this capability. If you are in doubt, please contact your hosting provider.
If you are running vBulletin in a Virtual Machine or on a Dedicated Server, you can improve performance with Memcached. This allows you to move some of the caching systems from vBulletin's database and into memory. On the surface, configuring vBulletin to use Memcached may seem complicated. However installation is quick and easy, with a little server knowledge.
Install Memcached on the Server
Memcached is designed to work on Linux systems. In many cases can be installed with your package manager.
Linux
# CentOS 6
[root@memcached01 ~]# yum install memcached
[root@memcached01 ~]# chkconfig memcached on
[root@memcached01 ~]# service memcached start
# CentOS 7
[root@memcached01 ~]# yum install memcached
[root@memcached01 ~]# systemctl enable memcached
[root@memcached01 ~]# systemctl start memcached
# Ubuntu 16.04 and 18.04
[root@memcached01 ~]# apt-get update
[root@memcached01 ~]# apt-get install memcached
Other Distros
For other linux distributions, you might have to install from the source code. See the Memcached Documentation on Github to accomplish this..
Windows
While Memcached is designed as a Linux/Unix executable it is open source. Due to this, there are Windows Binaries available. You can find these by performing a search on your favorite search engine. The instructions vary depending on the version of Windows and how you have things configured. Refer to the documentation for the specific port you decide to use.
Windows Subsystem for Linux (WSL)
If you are using Windows Server 2016 or Windows 10 as your base OS, you can install Memcached within the Windows Bash environment using the instructions for Debian/Ubuntu above. However, this is not recommended for a production server.
Running Memcached
systemctl start memcached
Starting Memcached on WSL
WSL does not have systemctl as the system is controlled by the Windows Kernal. To start Memcached use this command:
sudo /etc/init.d/memcached
Note: I am using WSL on Windows 10 1809 and Ubuntu 18.04. If you're using an older version of the OS, then compatibility may not be complete. The commands in your version of Linux may be different.
Install the Memcached Libraries in PHP
Debin/Ubuntu
sudo apt-get update
sudo apt-get install -y php7.1-memcached
sudo service apache2 restart
If your version of PHP is different, you should update the above commands to reflect this.
CentOS
sudo yum install php php-pecl-memcache
## CentOS/RHEL 6.10 ##
sudo /etc/init.d/httpd restart
## OR ##
sudo service httpd restart
Configuring vBulletin
Enabling memcached
Once you have Memcached running on the server, you can configure vBulletin to use it. Open your /core/includes/config.php
file and look for this code:
/*
$config['Datastore']['class'] = 'vB_Datastore_Memcached';
$i = 0;
// First Server
$i++;
$config['Misc']['memcacheserver'][$i] = '127.0.0.1';
$config['Misc']['memcacheport'][$i] = 11211;
$config['Misc']['memcachepersistent'][$i] = true;
$config['Misc']['memcacheweight'][$i] = 1;
$config['Misc']['memcachetimeout'][$i] = 1;
$config['Misc']['memcacheretry_interval'][$i] = 15;
*/
This will enable memcached with the default installation. It needs to be made active by removing the /* */
comment markers. Change the code to this:
$config['Datastore']['class'] = 'vB_Datastore_Memcached';
$i = 0;
// First Server
$i++;
$config['Misc']['memcacheserver'][$i] = '127.0.0.1';
$config['Misc']['memcacheport'][$i] = 11211;
$config['Misc']['memcachepersistent'][$i] = true;
$config['Misc']['memcacheweight'][$i] = 1;
$config['Misc']['memcachetimeout'][$i] = 1;
$config['Misc']['memcacheretry_interval'][$i] = 15;
Note: If you have changed the port or have memcached is running on a different server, you will need to update the values here.
Memcached Prefixes
It is adviseable to use a prefix in order to keep your vBulletin data separate from other applications. You can specify this in your /core/includes/config.php
file. Look for this code:
$config['Cache']['memcacheprefix'] = '';
Set the prefix to something unique for your site like this:
$config['Cache']['memcacheprefix'] = 'randomchars_mysite';
Moving the System Cache
vBulletin has several different layers of caching for performance purposes. We're going to move one of them to your new Memcached server. The cache we're going to move is the Regular cache.
In your /core/includes/config.php
find:
$config['Cache']['class'][0] = 'vB_Cache_Db'; //regular cache
Change it to:
$config['Cache']['class'][0] = 'vB_Cache_Memcached'; //regular cache
Closing
The system should be using Memcached as soon as the /core/includes/config.php
file is updated on the server. There are no settings within the AdminCP to make this happen. Hopefully, you will be able to see a performance benefit and less strain on your database server with these changes.
I understand but to be honest I could not install or run Memcached since I have upgraded to PHP 7.x I tried to search many tutorials about this and tried more but not succeeded.