← ServerPilot Docs

How to Install the PHP APC Extension

APC is an opcode cache that allows PHP to save and reuse the intermediate code generated from PHP source code as a speed optimization.

This tutorial is only relevant for PHP 5.4. PHP 5.5, PHP 5.6, and PHP 7 have opcode caching built into PHP and it is enabled by default.

To enable APC's separate object caching functionality in PHP 5.5+, do not install APC. Instead, install the APCu extension.

To install this extension, SSH into your server as root and run the following commands:

sudo apt-get install gcc make autoconf libc-dev pkg-config
sudo pecl5.4-sp install apc

Press Enter when asked configuration questions unless you know you want to change any of the defaults.

Once installed, create a configuration file for the extension and restart PHP by running the following commands as root:

sudo bash -c "echo extension=apc.so > /etc/php5.4-sp/conf.d/apc.ini"
sudo service php5.4-fpm-sp restart

Debugging Compilation Errors

The following error means you tried to build APC for PHP 5.5 or PHP 5.6. PHP 5.5 and 5.6 include opcode caching by default. APC does not work with PHP 5.5+.

/tmp/pear/temp/APC/apc_compile.c:2417:9: error: 'zend_trait_precedence' has
no member named 'function'
make: *** [apc_compile.lo] Error 1
ERROR: `make' failed

Uninstalling the PHP APC Extension

To uninstall this extension, as root run the commands:

sudo rm /etc/phpX.Y-sp/conf.d/acp.ini
sudo pecl5.4-sp uninstall apc

Next, restart PHP-FPM with the command:

sudo service phpX.Y-fpm-sp restart
Last updated: February 26, 2018

Launch your first site in 5 minutes