From OpenWetWare
Jump to navigationJump to search

Installing MemCache

Download all src packages needed for the install.

We'll start with libevent because it is a dependency of memcached.

  • Extract Files: # tar xvfz libevent-1.2.tar.gz

Install libevent

  • # cd libevent-1.2
  • # ./configure && make
  • # make install

Take note of where libevent is installed.

  • In my installation is ended up --> /usr/local/lib/

libevent installation complete.

Next we'll install memcached.

  • Extract files: # tar xvfz memcached-1.2.0.tar.gz
  • # cd memcached-1.2.0
  • # ./configure --with-libevent=/usr/local/lib/

How effective is this approach?

  • Let me say even though I did this option, it didn't seem to work on my server. *I had to do some linking to make it work, which I'll outline just in case yours doesn't work like mine.
    • # make
    • # make install

Memcached installation complete.

Now we'll install memcache

    • Extract Files: # tar xvfz memcache-2.1.0.tar.gz
    • # cd memcache-2.1.0 (make sure it's memcache and NOT memcached)
    • # phpize
    • # ./configure && make
    • # make install
  • Take note of the php extensions directory that memcache is installed in.
  • Mine is: /usr/local/lib/php/extensions/no-debug-non-zts-20020429

That's it. Your done installing.

Now we need to test it and see if it works.

  • # /usr/local/bin/memcached -u nobody -d -m 64 -l -p 11211
  • This is the config I like, so feel free to use different options.
    • -u nobody: The user that the daemon will run as
    • -d: ??? Maybe run as daemon?
    • -m 64: memory 64mb
    • -l (note that's a lowercase L) Listen IP address
    • -p 11211: listen port (default)

Ok, so hopefully this worked.

If it did not...

  • and you get an error when trying to start memcached that says that it basically can't find then you'll need to do the following to fix it. Exact Error I got was:
    • Quote:
    • memcached: error while loading shared libraries:
    • open shared object file: No such file or directory

Run the following command to see where memcached is looking for it's libs

  • # LD_DEBUG=libs memcached -v
  • Now you should have taken note of the libevent in section 4 and you will need to compare that location with the different locations that it lists.
  • The one I chose to use was "trying file=/usr/lib/"

Now we can assume that the file doesn't exist in that location

  • We are getting an error that says it doesn't. So we'll create a link from the actual file in the location I've chosen that it's looking in.
  • ln -s /usr/local/lib/ /usr/lib/

Done, now we need to test again.

  • # /usr/local/bin/memcached -u nobody -d -m 64 -l -p 11211

This time is should have worked.

  • And if you run the ps -xx command of your choice you should see it listed.

Startup script issues

  • Now, I spent a considerable amount of time trying to get the startup script that kerpluk posted links to, but did not have any luck. The failed portion of it relates to the start-memcached script. And I don't know enough about scripting to know how to work around the problem. So I just cheated and added the startup commands to rc.local.

==Edit /etc/rc.local with your editor or choice.

  • Add the following lines (or your version of it) to the bottom of the file.
  • ## Start Memcached
    • /usr/local/bin/memcached -u nobody -d -m 64 -l -p 11211

Now it will automatically start when you reboot your server.

Ok, now we need to add memcache to PHP as an extension.

  • Open your phpinfo file from ACP in vB and find the location of php.ini.
  • Once you have the location, edit the file and add/verify the following:
  • find "extension_dir =" and make sure it's set to your php extensions directory.
  • Mine has: extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20020429"
  • Which is correct based off the information we took note of in the last step of section 8. If it's not, then you have two options, you can either make it so it has the directory that you obtained during the install of memcache or add it to the extension line that we'll add to php.ini.
  • IF you chose to add the extension directory to extension_dir or if it was already correct (mine was from previously installing APC), then add the following somewhere in the section that has all the extensions.
    • ;
    • ; memcache Section
    • ;
    • extension =
    • memcache.allow_failover = 0
  • OR if extension_dir doesn't point to the correct location you can add it this way:
    • memcache Section
    • extension = "/usr/local/lib/php/extensions/no-debug-non-zts-20020429/"
    • memcache.allow_failover = 0
  • Either one will work just fine.
  • Save the file, and restart apache
    1. service httpd restart

Further Information

See OpenWetWare:Software/Performance/MemCache/MediaWiki