APC – Installing It On CentOS

yum install php-pear
yum install php-devel
yum install httpd-devel

Edit the file /usr/share/pear/pearcmd.php and add the following at the beginning:
@ini_set(‘memory_limit’, ’16M’);
otherwise you’ll probably get a fatal error whilst building the extension:
pecl install apc

Now configure PHP to use the new extension.
Create the file /etc/php.d/apc.ini and in that file put:
extension=apc.so

Now restart apache
sudo /etc/init.d/httpd greaceful

In the future, if new versions of APC are released, you can easily upgrade them using:
sudo pecl upgrade apc

Now, to configure APC there are two options: either edit php.ini, or add apc.ini to the php.d folder. Either way, I use the following:

extension = apc.so
apc.enabled = 1
apc.shm_size = 48
apc.include_once_override = 1
apc.mmap_file_mask = /tmp/apc.XXXXXX

It’s very important to choose the size of the cache (apc.shm_size) because when it gets full, APC empties it.

Finally I restart apache again (service httpd restart) and verify that php -v returns the same output. If I want to verify that apc is working, I locate apc.php on the server and then copy it to a web-accessible directory. Then I load that script in my browser, and if I can see pretty graphs, then it’s working.

APC works thanks to share memory (RAM).

apc.shm_size aside, it’s also important to set correctly the number of sectors and apc.stat that it’s about whether to check the timestamp of the files (before serving) to re-cache them (see documentation).

IMPORTANT! I had this problem: the cache was flushed completely after getting full. That was because I need to set:
apc.ttl and apc.user_ttl to a non-zero value (for example 7200). In your vim /etc/php.d/apc.ini:
apc.ttl=7200
apc.user_ttl=7200

This entry was posted in LAMP Server Setup, Linux, Web Development. Bookmark the permalink.

Leave a Reply