In my
previous post I covered the installation of nginx, PHP-FPM and MySQL on Ubuntu. In this post I will cover the installation of APC and Memcached onto the server. As before I kept to the use of of packages located on the official Ubuntu repository in order to keep upgrading and maintainance headaches to a minimum. Also before these are the step I took on an Ubuntu 12.04 LTS (Precise Pangolin) installation. However you should be able to follow the same steps with any older or newer release of Ubuntu.
Note that this post is meant as a follow up to my previous post on the installation of nginx, PHP-FPM and MySQL on Ubuntu which can be found
here. However these steps should work fine for installing APC and Memcached in an Apache environment as well. Just be sure to replace the /etc/init.d/php-fpm restart commands with /etc/init.d/apache2 restart.
This post covers the installation of both APC and Memcached although you may not necessarily need both being that APC is generally capable of doing what Memcached does in smaller environments but depending on your websites software and infrastructure you may need Memcached in place of APC or in conjunction with APC.
First off I will cover the installation of APC which is as simple as running the following command.
sudo apt-get install php-apc
|
After the package has been installed you will need to restart the php-fpm process.
sudo /etc/init.d/php5-fpm restart
|
Once the php-fpm process has been restarted we can varify our APC setup by running the following command. You may need to install the PHP command line interface.
Install the PHP command line interface:
sudo apt-get install php5-cli
|
Command to check if APC has been installed correctly:
php -r "phpinfo();" | grep apc
|
you should receive output resembling the follow.
Additional .ini files parsed => /etc/php5/cli/conf.d/apc.ini,
apc
apc.cache_by_default => On => On
apc.canonicalize => On => On
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
apc.file_md5 => Off => Off
apc.file_update_protection => 2 => 2
<... clipped to save room ...>
|
That is that you now have APC installed on your server.
Next we move on to the installation of Memcached. As with APC the installation process is very simple and straight forward. First we will install the Memcached package.
sudo apt-get install memcached
|
After the Memcached package has been installed we will need to start the Memcached process.
sudo /etc/init.d/memcached start
|
After starting Memcached we will need to install the Memcache or Memcached PHP module. A simple
Google Search will help you learn the difrences between the two and help you decide on which best suits your needs.
Install php5-memcache:
sudo apt-get install php5-memcache
|
Or install php5-memcached
sudo apt-get install php5-memcached
|
Now restart your PHP-FPM process.
sudo /etc/init.d/php5-fpm restart
|
You now have both APC and Memcached installed and ready to be utilized to increase the performance of your server when dishing out your content. In my next post I will cover the setup and configuration of WordPress running on nginx along with the plug in W3 Total Cache which will allow WordPress to fully utilize APC and/or Memcached to really liven up your blogs performance.
memcached:
PHP extension for interfacing with memcached via libmemcached library This extension uses libmemcached library to provide API for communicating with memcached servers.
Newer Project.
Newer Features.
Faster.
memcache:
Memcached is a caching daemon designed especially for dynamic web applications to decrease database load by storing objects in memory. This extension allows you to work with memcached through handy OO and procedural interfaces.
Mature Project.
Binary not dependant on the libmemcached library.
Support for more legacy code.
I will add the optional php5-memcached line into the post as well so people will know they have the choice.
btw, which is your recommendation? memcache or memcached?
However I have read memcached being newer has a performance advantage over memcache. Honestly I have never done any benchmarks so I can not prove this one way or the other.
I would suggest looking at these posts for a little more information between the two it seems to me at this time it’s basically up in the air if either has a true advantage over the other at this time unless the application being hosted takes advantage of the newer features contained in memcached.
http://serverfault.com/questions/63383/memcache-vs-memcached
http://stackoverflow.com/questions/1442411/using-memcache-vs-memcached-with-php