Wednesday, September 17, 2008

Installing APC cache for PHP on Ubuntu 8.0.4

Apc offers a dramatic improvement in server speed. Apc is the standard php opcode cache. It parses your code once and stores in in memory, bypassing the filesystem. On a production server, you'll set the apc stat variable to false and it won't even check to see if the php script has been modified. On a development or staging server, you'll run Apc to make sure you haven't written anything that isn't compatible with opcode caches or Apc specifically. You'll set the apc stat variable to true and Apc will check to see if you've made modifications and use them if you have.

Install Apc,

I'm running php with fast cgi because everything about this stack is fast. Get the php development library.

apt-get install php5-dev
apt-get install php-pear
pecl install apc

Since we're not using apache, set Use apxs to set compile flags (if using APC with Apache)? to no.

Done.

Next I modify the php.ini to use the apc extension.


extension=apc.so
;; settings for apc. shm_size in megabytes, apc.stat set to zero in production
;; scenario where the php is restarted when the code is updated.
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 33
apc.max_file_size = 10M
apc.stat=0
apc.ttl="7200"
apc.user_ttl="7200"


No comments: