Install the PHP extension APC on Debian
APC is the acronym for Alternative PHP Cache. This module enhance the performances of your PHP applications by caching the "compiled" PHP op-code.
This howto is tested on:
- Debian 5.0 Lenny
- Debian 6.0 Squeeze
- Debian 7.0 Wheezy
Prerequisites
This howto need a working PHP setup such as, for example, the one in described by Install PHP-FPM on Debian.
Installation
Install from the Debian package if it is available:
if [ -n "$(command apt-cache pkgnames php5-apc)" \
-a -n "$(command dpkg --status "php5-common" | command grep "dotdeb")" ]; then
# Check for dot-deb packages.
command apt-get -y install php5-apc
elif [ -n "$(command apt-cache pkgnames php-apc)" ]; then
command apt-get -y install php-apc
fi
If the Debian package is not available, install PEAR and build the extension:
if [ -z "$(command apt-cache pkgnames php-apc)" -a -z "$(command apt-cache pkgnames php5-apc)" ]; then
command apt-get -y install php5-dev make php-pear apache2-prefork-dev libpcre3-dev
command pecl install apc --with-apxs='/usr/bin/apxs2'
echo 'extension=apc.so' > '/etc/php5/conf.d/apc.ini'
fi
Reload the configuration :
test -x /etc/init.d/php5-fpm && /etc/init.d/php5-fpm restart
test -x /etc/init.d/apache2 && /etc/init.d/apache2 force-reload
test -x /etc/init.d/lighttpd && /etc/init.d/lighttpd force-reload
test -x /etc/init.d/nginx && /etc/init.d/nginx force-reload
Installation from sources
Before installing from sources the last version of APC extension, make sure to uninstall the php-apc package:
command apt-get remove php-apc php5-apc
Install the software needed to build APC:
command apt-get install php5-dev make php-pear apache2-prefork-dev libpcre3-dev
Build and install APC:
command pecl install apc --with-apxs='/usr/bin/apxs2'
Enable APC PHP extension:
echo 'extension=apc.so' > '/etc/php5/conf.d/apc.ini'
Reload the configuration :
test -x /etc/init.d/php5-fpm && /etc/init.d/php5-fpm restart
test -x /etc/init.d/apache2 && /etc/init.d/apache2 force-reload
test -x /etc/init.d/lighttpd && /etc/init.d/lighttpd force-reload
test -x /etc/init.d/nginx && /etc/init.d/nginx force-reload
To be alerted of APC extension upgrades, read Setup a email alert for PEAR upgrades.
Configuration
The APC default configuration is sufficient. Make sure the APC extension is enabled, and turn on the upload progress status option:
echo '; APC Configuration
apc.enabled = 1
; Memory allocated to APC. Use Munin or APC Info to see if more is needed.
apc.shm_size="96M"
; rfc1867 allow file upload progression display.
apc.rfc1867 = on' \
> '/etc/php5/conf.d/apc-config.ini'
Reload the configuration :
test -x /etc/init.d/php5-fpm && /etc/init.d/php5-fpm restart
test -x /etc/init.d/apache2 && /etc/init.d/apache2 force-reload
test -x /etc/init.d/lighttpd && /etc/init.d/lighttpd force-reload
test -x /etc/init.d/nginx && /etc/init.d/nginx force-reload
Thanks
- Thanks to Alternative PHP Cache (en) developers.
