Installing Memcache and APC (PHP Alternative Cache) on FreeBSD (9.0)

What is Memcache ?

Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

What is APC ?

APC Cache (Eaccelerator and other similar caches) is fast but it is not distributed so you’re wasting cache and reducing possible hit rate by caching things locally if you have many web servers. MemcacheD is relatively slow but distributed and so you do not waste memory by caching same item in a few places, it is also faster to warmup as you need only one access to bring item into the cache, not access for each of web servers.

The good thing however is you do not have to select one or another, you can use both at the same time. APC will be great for caching small but frequently accessed things which are not taking too much memory. For example if you store list of states in the database you can cache it this way. For NNSEEK we can use it to cache list of languages, top groups and much of semi-static modules shown on group directory pages. Memcached is good for caching things which take large amount of space combined and which you only need to fetch few per page. For example search results may be good candidate (assuming we want to cache them and want to cache them in memory).

 So lets going and get these caching tools setup and working…

Login to your server as ‘root’, next we’ll install APC from the ports collection like so:-

cd /usr/ports/www/pecl-APC
make install clean

Now next we’ll install Memcache in the same way we did with APC (from the Ports tree):-

cd /usr/ports/databases/pecl-memcache
make install clean

If your server didn’t shows any errors, we can go ahead and restart the webserver – just make sure and is already load in your PHP extensions file.

So now we need to add  in the new ‘’ and ‘’ extentsions into PHP, we do this by editing the ‘extenions.ini’ file as shown below:-

vi /usr/local/etc/php/extensions.ini

Now add to the bottom of the file:-

Save the file and then exit from vi! – Almost done!

At this stage you’ll need to restart your web server, if using Apache you can run:-

apachectl restart

You can now confirm if APC and Memcache is fully working by creating a PHP file and putting:-

<? phpinfo(); ?>

If all worked good you should now see entries for APC and Memcache on that page (when viewed in your browser) 🙂

Hope you found this useful!

One reply on “Installing Memcache and APC (PHP Alternative Cache) on FreeBSD (9.0)”