Install or enable phps apcu extension

← ServerPilot Docs

In the examples shown, replace "X.Y" with your app's PHP version (for example, "5.6" or "7.1").

The APCu extension adds object caching functions to PHP.

APCu is the official replacement for the outdated APC extension. APC provided both opcode caching (opcache) and object caching. As PHP versions 5.5 and above include their own opcache, APC was no longer compatible, and its opcache functionality became useless. The developers of APC then created APCu, which offers only the object caching functionality (they removed the outdated opcache).

Installing APCu on PHP 7.0, 7.1, 7.2, 7.3, and 7.4

To install this extension on PHP 7.X, SSH in to your server as root and run these commands:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo pecl7.X-sp install apcu

When asked the following question, press Enter.

Enable internal debugging in APCu [no] :

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

sudo bash -c "echo extension=apcu.so > /etc/php7.X-sp/conf.d/apcu.ini"
sudo service php7.X-fpm-sp restart

APCu for PHP 7+ does not support an option for full backwards compatibility with APC. If you require full backwards compatibility with APC and you're using PHP 7+, you'll also need to install the APCu Backwards Compatibility (apcu-bc) extension.

Installing APCu on PHP 5.4, 5.5, and 5.6

To install this extension on PHP 5.X, SSH in to your server as root and run these commands:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo pecl5.X-sp install apcu-4.0.11

When asked the following questions, press Enter.

Enable full APC compatibility [yes] :
Enable internal debugging in APCu [no] :

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

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

Verifying the Installation

You can verify APCu is installed correctly by running the command:

phpX.Y-sp -i | grep apcu

You should see output like the following:

Additional .ini files parsed => /etc/phpX.Y-sp/conf.d/apcu.ini,
apcu

Uninstalling the APCu Extension

To uninstall this extension, as root run the commands:

sudo rm /etc/phpX.Y-sp/conf.d/apcu.ini
sudo peclX.Y-sp uninstall apcu

Next, restart PHP-FPM with the command:

sudo service phpX.Y-fpm-sp restart

Last updated: October 8, 2018

To use apcu, the apcu extension has to be installed. You can find it here https://pecl.php.net/package/APCu

Note: apcu is not the same as apc!

APCu is the official replacement for the outdated APC extension. APC provided both opcode caching (opcache) and object caching. As PHP versions 5.5 and above include their own opcache, APC was no longer compatible, and its opcache functionality became useless. The developers of APC then created APCu, which offers only the object caching (read "in memory data caching") functionality (they removed the outdated opcache).

Wondering how to use apcu? The following example should give you a basic understanding.

<?php

date_default_timezone_set

('Europe/Amsterdam');$apcuAvailabe = function_exists('apcu_enabled') && apcu_enabled();

if(

$apcuAvailabe)
{
   
//apcu_clear_cache();$test1 = apcu_fetch('test1');
   
$test2 = apcu_fetch('test2');
}
$test1[] = rand(1, 1000);
$test2[] = rand(1, 1000);

if(

$apcuAvailabe)
{
   
apcu_store('test1', $test1);
   
apcu_store('test2', $test2);
}

echo

sprintf('current - value = %s<br/>', implode(' ,', $test1));
echo
sprintf('current - value = %s<br/>', implode(' ,', $test2));$aPCUIterator = new APCUIterator();

echo

sprintf('totalCount = %s<br/>', $aPCUIterator->getTotalCount());
//echo sprintf('totalHits = %s<br/>', $aPCUIterator->getTotalHits()); // Not implemneted/available?
echo sprintf('totalSize = %s<br/>', $aPCUIterator->getTotalSize());

echo

'----------------------------------<br/>';$aPCUIterator->rewind();
echo
sprintf('key = %s<br/>', $aPCUIterator->key());
echoCurrent($aPCUIterator->current());
$aPCUIterator->next();

echo

'----------------------------------<br/>';

echo

sprintf('key = %s<br/>', $aPCUIterator->key());
echoCurrent($aPCUIterator->current());
echo
sprintf('valid = %s<br/>', $aPCUIterator->valid() ? 'true' : 'false');

function

echoCurrent($current)
{

        echo

sprintf('current - type = %s<br/>', $current['type']);
    echo
sprintf('current - key = %s<br/>', $current['key']);
    echo
sprintf('current - value = %s<br/>', implode(' ,', $current['value']));
   
//echo sprintf('current - num_hits = %s<br/>', $current['num_hits']); // Not implemneted/available?
   
echo sprintf('current - mtime = %s<br/>', date("d-m-Y H:i:s", $current['mtime']));
    echo
sprintf('current - creation_time = %s<br/>', date("d-m-Y H:i:s", $current['creation_time']));
    echo
sprintf('current - deletion_time = %s<br/>', date("d-m-Y H:i:s", $current['deletion_time']));
    echo
sprintf('current - access_time = %s<br/>', date("d-m-Y H:i:s", $current['access_time']));
   
//echo sprintf('current - ref_count = %s<br/>', $current['ref_count']); // Not implemneted/available?
   
echo sprintf('current - mem_size = %s<br/>', $current['mem_size']);
   
//echo sprintf('current - ttl = %s<br/>', $current['ttl']); // Not implemneted/available?
}?>

How do I enable my APCu extension?

Installing PHP Packages.
APCu. To install APCu you need to run this command: <source lang='bash'> sudo apt install php-apcu </source> ... .
Install Memcached. With version 4.0.4 and greater of iHRIS you can use memcached to improve performance. ... .
Set ZendOpcache options. ... .
Document Root. ... .
Enable Rewrite Module. ... .
Enable ..

How do I install an APCu file on Windows?

Unzip the archive, copy php_apcu. dll in C:\wamp\bin\php\php5. 5.6\ext ..
PHP version (5.5 in your case).
x64 (64 bits) OR x86 (32 bits windows).
Thread Safe (for Apache compatibility).

What is APCu extension?

The APCu extension adds object caching functions to PHP. APCu is the official replacement for the outdated APC extension. APC provided both opcode caching (opcache) and object caching. As PHP versions 5.5 and above include their own opcache, APC was no longer compatible, and its opcache functionality became useless.

What is APCu in PHP?

APCu is an in-memory key-value store for PHP. Keys are of type string and values can be any PHP variables. APCu only supports userland caching of variables. APCu is APC stripped of opcode caching. The first APCu codebase was versioned 4.0.