Custom Search

Tutorial Installing memcached for Windows on Apache / PHP and Xenforo

Discussion in 'Website Development' started by TazDevilLooney, Mar 22, 2012.

  1. TazDevilLooney Admin

    Message Count:
    Likes Received:
    Trophy Points:
    Operating System:
    Windows 7 Ultimate X64 SP1
    After spending so much time trying to locate the information on the net i thought i'd share all the details on how to successfully run memcached on windows. As the information on the net changes from day to day i will be making available all the files in zip format at the end of this tutorial as they just work.


    First you need the software the latest ones can be found here or download the file at the bottom of this tutorial.

    Memcached :
    PHP Memcached interface :


    Create a directory in the root of your hard drive as follows C:\memcached\ and place the file from the zip in it.
    Open up a command prompt and navigate to the location of the files by typing in CD \memcached
    To install as a service type in memcached -d install
    To start the service type in memcached -d start

    Other usefull information regarding memcached.
    To stop the service type in memcached -d stop
    To uninstall the service type in memcached -d uninstall
    To set memory limit (Default is 64MB) type in while memcache is running memcached -m 2048 this makes 2GB of cache avaiable.

    While running memcache as a service your be unable to add the -m 2048 on the service start up.

    Control Panel -> Administrative tools -> Services


    To add the extra memory allocation your need to edit the registry to add the information.

    Run -> Regedit
    Add -m 2048 (The value i'm using is 2GB but pick what you wish to allocate) on the end of the imagepath.


    If you now go back to the service section you should now see .


    If your not seeing this result a computer restart is required. You now have memcached running.

    PHP Memcached interface

    Unzip and place memcache.php on your server were your site files are located.

    Other usefull information regarding PHP Memcached interface.
    To access the interface your be asked for username and password details these are as follows.
    Username : memcache
    Password : password

    If you edit the file in notepad you can change the password details on lines 21 -> 22.

    define('ADMIN_USERNAME','memcache');    // Admin Username
    define('ADMIN_PASSWORD','password');      // Admin Password

    If you don't wish to have a password comment out lines 35 -> 45 by placing // at the front of each line.

    //if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
    //            Header("WWW-Authenticate: Basic realm=\"Memcache Login\"");
    //            Header("HTTP/1.0 401 Unauthorized");
    //            echo <<<EOB
    //                <html><body>
    //                <h1>Rejected!</h1>
    //                <big>Wrong Username or Password!</big>
    //                </body></html>
    //            exit;

    You also need to change the information on lines 28 -> 29 to reflect your system.

    $MEMCACHE_SERVERS[] = 'mymemcache-server1:11211'// add more as an array
    $MEMCACHE_SERVERS[] = 'mymemcache-server2:11211'// add more as an array

    An working example is as such.

    $MEMCACHE_SERVERS[] = 'localhost:11211'// add more as an array
    // $MEMCACHE_SERVERS[] = 'mymemcache-server2:11211'; // add more as an array

    You should be able to view the interface at the address you placed the file you should now see this.
    However is won't work till the rest of the information is followed.


    PHP files

    Check you php/ext/ folder for the file php_memcache.dll
    If this file exists then all well and good if not add your php version from the zip file below which contains.

    1. php_memcache-php-
    2. php_memcache-php-

    Now that php-memcahce.dll has eather been located or added to your system find your php.ini file and add this code to the bottom.


    Restart the server and memcache will be running check this by viewing your phpinfo().


    Getting your sites to use the cache.

    Some sites will require extra plugins to be installed for the memcache to start working. If your running a dynamic site like wordpress or others check if you require any additional plugins to activate this feature.

    To activate the memcache feature in Xenforo add this code to your /library/config.php

    $config['cache']['enabled'] = true;
    $config['cache']['frontend'] = 'Core';
    $config['cache']['frontendOptions']['cache_id_prefix'] = 'xf_';
    $config['cache']['cacheSessions'] = true;
    $config['cache']['backend'] = 'Memcached';
    $config['cache']['backendOptions'] = array(
    'compression' => false,
    'servers' => array(
    // your memcached server IP /address
    'host' => 'localhost',
    // memcached port
    'port' => 11211,

    While your site is in use check back to your You should see the hit's start to rise (refresh data).


    You now have a fully working version of memcache. :happy:

    Files in the Zip

    1. memcache.php - (PHP Memcached interface)
    2. memcached-win32-1.4.4-14 - (Core windows program)
    3. php_memcache-php- - (php_memcache.dll)
    4. php_memcache-php- - (php_memcache.dll)
    5. php_ini.txt - (Text Document)
    6. xenforo_config_php.txt - (Text Document)

    Enjoy :happy:

    Attached Files:

  2. vger Pre-Moderation

    Message Count:
    Likes Received:
    Trophy Points:
    You da man Taz..............:happy:

Share This Page

(Users: 0, Guests: 0)