First, decide if you need memcached. APC is both an "accelerator" (an opcode cache, which is fairly transparent), and a caching solution (provides an in-memory data store that code needs to write/read from). memcache only does the latter.
The only reason you'd typically need memcached is if you're going to be running multiple servers that need to read/write from the same cache. As long as you're only running a single web server host, APC will do the trick.
Installing APC is pretty easy.
[root@host]# pecl install apc #or sometimes pecl install apc-beta
[root@host]# service php5-fpm start
You'll probably notice an immediate performance boost, just with APC's default settings.
You can then tweak as needed. See the docs for various settings.
The most common setup I've seen is a single segment, sized in a way that makes sense for your system:
In php.ini:
extension=apc.so
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 50M
APC comes with a handy apc.php script that will give you lots of useful data (like how many hits/misses you're getting), along with pretty graphs.
You would have to set up two separate pools of php "workers" in your php-fpm.conf
, each using a different php_defines as well as a different port. One would have APC enabled, one would not. How to enable or disable APC would depend on if you built it into the PHP executable or not. If it is built in, you'd add apc.enabled=0
in one php_defines to disable it in that worker pool. Otherwise, you'd remove the extension=apc.so
from your default .ini file and move it into one of the php_defines to enable it in that worker pool.
In nginix, you should be able to set which worker pool gets used on a per-location
basis by putting the correct port in fastcgi_pass
. You could test if its working or not by creating a small script calling phpinfo() in each location and checking the output for APC.
Best Answer
Exactly our setup. Well, APC is dead as others have commented. On ubuntu, officially killed since Ubuntu 14.
You're left with mainly two mainstream options:
Memcached: fantastic and fast as a simple key/value store. Works on windows too.
Redis: same as above but considerably slower if you just need a simple key/value store. Redis has far more options though, with rich data, pub/sub, etc. Said to work on windows, but we haven't tested.
From our experience, Memcached is great, easy to implement and because it works on windows, it allows our developers to keep a complete windows development stack locally on their workstations/laptop without servers or virtual machines.