Memcached And VPS Hosting
What is Memcached?
Memcached is a distributed memory caching system just like the name suggests. This general purpose caching system was originally developed by Danga Interactive for LiveJournal (a blog hosting site). It is now used by many in order to speed up their dynamic database driven websites by caching objects and data into memory. This reduces the amount of times the database needs to be queried and saves on resources.
When to use Memcached?
Memcached should ideally be used on resource intensive websites. A lot of people have asked the question about having Memcached installed on shared hosting. If your website is starting to consume resources that go beyond the scope of shared hosting then Memcached isn’t going to save your site. It’s likely it’s going to need to be upgraded from shared to VPS hosting. Standard file caching methods should be used on shared, and if it’s still not enough then you likely need to upgrade. Also, shared hosting accounts will typically not allow Memcached as it lacks authentication, meaning other users on the same shared hosting could potentially retrieve your Memcached data if they have the correct keys.
This is because Memcached lacks security features and authentication. Therefore it should only be utilized on servers with a properly configured firewall. VPS and Dedicated hosts allow you to configure your firewall which is another reason they are better suited, as opposed to shared.
If you do have a VPS and want to use Memcached, then you’re likely going to require a VPS with high enough memory limitation as Memcached can use a lot of memory on a large site, otherwise you might be best served by with an alternative caching method.
Installing Memcached on a VPS Server
File and program versions may have become outdated and/or there are just better ones you should use. Best to find the latest and not use the ones in this guide. The methods required and may differ depending on your server setup and the flavor/version of Linux being used. If in doubt it might be best to ask your server administrator for assistance or to install Memcached for you.
Installing Memcached
Install Libevent
wget http://www.monkey.org/~provos/libevent-1.4.8-stable.tar.gz
tar xfz libevent-1.4.8-stable.tar.gz
cd libevent-1.4.8-stable
./configure
make
sudo make install
sudo ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib
Install Memcached
wget http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
tar xfz memcached-1.2.6.tar.gz
cd memcached-1.2.6
./configure
make
sudo make install
memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211
Install Memcached PHP Extension
In your accounts home directory edit your ‘.profile’ file and add:
export PATH=$PATH:/usr/local/bin
Install PEAR by doing:
wget http://pear.php.net/go-pear -O go-pear.php
php go-pear.php
ls -l ~/.pearrc
edit your ‘.profile‘ and add (don’t forget to change yourname):
export PATH=/home/yourname/pear/bin:$PATH
Install Memcache
pecl install memcache
Add ‘extension=memcache.so’ to your php.ini file, you can find it using the command below:
php -i | grep ‘php.ini’
An Alternative Method to Installing Memcached
mkdir -p /root/source
cd /root/source
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -ivh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
yum -y install libevent*
yum -y install memcached*
gem source -a http://gems.github.com
wget http://blog.evanweaver.com/files/libmemcached-0.25.14.tar.gz
tar -xzvf libmemcached-0.25.14.tar.gz
cd libmemcached-0.25.14
./configure && make && make install
cd /root/source
wget http://blog.evanweaver.com/files/memcached-0.13.gem
gem install memcached-0.13.gem
gem install memcache-client—version=1.6.3






