Announcement

Collapse
No announcement yet.

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
    [[email protected] ~]# yum install memcached
    [[email protected] ~]# chkconfig memcached on
    [[email protected] ~]# service memcached start
    
    # CentOS 7
    [[email protected] ~]# yum install memcached
    [[email protected] ~]# systemctl enable memcached
    [[email protected] ~]# systemctl start memcached
    
    # Ubuntu 16.04 and 18.04
    [[email protected] ~]# apt-get update
    [[email protected] ~]# 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 1st 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) advanced (5) android (2) api (29) array (17) beginner (17) blog (4) calendar (2) cms (2) forum (3) forum rules (1) forums (4) Intermediate (7) iphone (3) list (1) mapi (30) member list (1) methods (10) mobile (34) security (2) skimlinks (1) style (2) threads (4) vb5howto (5) vBulletin (5)

Latest Articles

Collapse

  • vBulletin 5 Database Best Practices
    by Wayne Luke
    This is part of a best practices series to manage your vBulletin installation. 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 31st Oct '18, 7:18am
  • vBulletin Password Handling
    by Wayne Luke
    Note: vBulletin Cloud sites cannot use custom password schemes at this time. The core security of your site is the User Password and how it is stored. In the beginning, vBulletin used a simple MD5 hash to represent the password. However as Floating Point Processors (i.e. GPU and ASICs) have become more powerful, this method proved to be risky and reduced security. If we significantly changed the password scheme, then users wouldn't be able to login and would need to change their passwords fir...
    Sat 27th Oct '18, 12:34pm
  • Creating the Sitemap XML for your vBulletin
    by Wayne Luke
    The XML Sitemap specification allows search engines to index your site more efficiently. vBulletin 5 Connect can create the Sitemap automatically so you can submit it to your favorite search engines. Using the default path If you are using vBulletin Cloud, you must use this option. The default value for this is core/store_sitemap. Make sure the directory is CHMOD 0777 on your server. In the AdminCP, go to Settings -> Options -> XML Sitemap and set Enable Automatic Sitemap Generation to Yes. ...
    Sat 27th Oct '18, 12:18pm
  • 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 27th 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 you...
    Sat 27th Oct '18, 11:45am
  • Third-Party Logins: Twitter
    by Wayne Luke
    You will need to use an existing twitter account in order to use this functionality.

    Create an app using your twitter account

    In your browser go to https://apps.twitter.com/app/new

    Check App Settings

    Go to the application settings (e.g. https://apps.twitter.com/app/12345/settings where 12345 references the app created in step 2. You can access the settings by going to the list of
    your apps (https://apps.twitter.com), clicking on the app link, then clicking...
    Tue 10th Apr '18, 9:00am
Working...
X