Installing Memcached for vBulletin

Collapse
X
Collapse
  •  

  • Installing Memcached for vBulletin

    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.

    Last edited by Wayne Luke; Thu 1 Aug '19, 8:37am.

    • Wayne Luke
      #3
      Wayne Luke commented
      Editing a comment
      We do not support vBulletin 4.2.5 with PHP 7.2. However, I see no reason why Memcached wouldn't work. It is an external application. Maybe you're missing the proper Memcached class in PHP. You'll need to consult the PHP documentation to install that.

    • webmastersun
      #4
      webmastersun commented
      Editing a comment
      Thanks @Wayne!
      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.

    • Wayne Luke
      #5
      Wayne Luke commented
      Editing a comment
      I don't have any problem running memcached with php 7.1, php 7.2 or php 7.3 on my local Ubuntu 18.04 server (under WSL). You need to have both components installed. The executable and the PHP Library. You need to make sure that Memcached is running on the server.
    Posting comments is disabled.

About the Author

Collapse

Wayne Luke A curious juxtaposition of nature, technology and sustainability. Find out more about Wayne Luke

Article Tags

Collapse

administration (1) beginner (3) calendar (1) cloud (1) Custom (1) database (2) Google (1) how-to (2) howto (1) how to (1) https (1) Intermediate (4) MYSQL (2) performance (2) recovery tools (1) security (2) seo (1) server information (1) sftp (1) ssl (1) style (1) tls (1) tutorial (4) vb5howto (5) vbcloud (1)

Latest Articles

Collapse

  • vBulletin LDAP Setup
    by Wayne Luke

    Note: vBulletin Support cannot provide support for setting up and maintaining an LDAP server. This product is for advanced users already running LDAP servers. Once you have LDAP installed and configured, users can just log into your vBulletin installation. You do not need to sync users before you go live. Users will be automatically synced on their first login. Requirements Purchase and download the LDAP package. Unzip the download package. Upload the package to your core/packages...

    Wed 6 Jul '22, 10:29am
  • vBulletin Database Tools
    by Wayne Luke
    The vBulletin Database Tools are a series of command line scripts that allow you to quickly make modifications to your database in order to provide performance fixes and update them to UTF8 standards. IMPORTANT- These files must be run via the command line, either if you have local access to the server or ssh access. If you are on shared hosting your access may be limited. You may ask your host for ssh access. If they say it is not available ask if they will run the commands for you. These scri...
    Mon 21 Oct '19, 9:29am
  • vBulletin 5 Database Best Practices
    by Wayne Luke
    The database is the heart and soul of your vBulletin site. All content and user information is stored in the database. Protect the database and you protect your site. This document will go over the creation and usage of a MySQL database for the use of vBulletin 5 Connect. If you have shared hosting and are provided a web-based control panel like cPanel, you will need to access your hosting provider's documentation on how to carry out these operations. This document assumes a general familiarity with the command line operations of your Operating System. All commands listed assume that you are accessing your server via SSH. ...
    Wed 31 Oct '18, 7:18am
  • Installing Memcached for vBulletin
    by Wayne Luke
    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 s...
    Sat 27 Oct '18, 12:00pm
  • Using Tools.php
    by Wayne Luke
    Within your vBulletin Download Package, we provide a file called tools.php, this file isn't uploaded to the server by default as it is considered to be a significant security risk. However, there are times when you need to change specific settings and aren't able to access your AdminCP directly. Uploading to the Server It is recommended that tools.php is installed in the /core/install directory. To do this, follow the steps below: Connect to your server with your favorite SFTP or SCP client. In y...
    Sat 27 Oct '18, 11:45am
  • Converting your forum to https
    by Mark.B
    CONVERTING YOUR FORUM TO HTTPS
    Applies to self-hosted versions of:
    vBulletin 3; vBulletin 4; vBulletin 5;
    Cloud sites have https enabled by default and you do not need to do anything.

    This FAQ explains how to convert your vBulletin forum to use secure https (SSL) rather than http, and why you might need to.
    Note: This guide contains links to external sites. vBulletin Solutions is not responsible for the content of external links and cannot be held responsible...
    Fri 9 Dec '16, 2:59am
Working...