Alternative PHP Cache (APC) caches PHP opcodes for speeding up websites that depend on PHP code. Since PHP is an interpreted language, it has to be processed before executing the code. APC caches the intermediate code to reduce the amount of time to execute PHP code.
To install APC on Ubuntu Karmic Koala using PECL make sure you already have PECL installed.
apt-get install php-pear php5-dev
Then install APC.
apt-get install libpcre3-dev
pecl install apc
Edit /etc/php5/apache2/php.ini. In the Dynamic extensions section add
extension=apc.so
apc.shm_size=64M
The default memory size is 32M which is not sufficient for a complex website with a lot of PHP code. If the size of the cache is too small fragmentation will result which can slow down the website instead of speeding it up. Then reload Apache.
/etc/init.d/apache2 reload
There is a monitoring script /usr/share/php/apc.php which can be moved under the webserver root to monitor APC and warn about fragmentation problems. Methods like .htaccess should be used to restrict access to this script.
Add new comment