Installing PHP 7.0 APCu Extension

Last Updated on by in PHP
In order to include object caching functionality in PHP 7.0, The APCu extension is used.Earlier APC extension was used, but it has been replaced by APCu nowadays.

The previous version used to be known by the APC in PHP 5.5, it used to provide opcode and object caching functionality. However, as the time pass by developer created APCu which is more flexible and robust.

How to Install APCu on PHP 7.0, 7.1, 7.2 ?

In order to install APCu extension in PHP 7.0, 7.1, 7.2 +, you must log inside your server as a root user using SSH access. Hit below commands in your terminal.

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
# Replace X with your php version number
sudo pecl7.X-sp install apcu

It will ask the given below question, hit enter.

# Hit Enter in response to this question
Enable internal debugging in APCu [no] :

As soon as you entered the above command, it will start processing once it is finished with the process. Then create a file to keep the configuration for the extension, finally run the below command as a root user to restart the PHP.

# Replace php7.X-sp => X with your PHP version
sudo bash -c "echo > /etc/php7.X-sp/conf.d/apcu.ini"
# Replace php7.X-sp => X with your PHP version
sudo service php7.X-fpm-sp restart

APCu creates some problems if you are using PHP 7+ versions. To provide full backward compatibility with APCu with PHP 7+, we should install APCu Backwards Compatibility extension.

How to Verify PHP APCu Installation?

Use the below command to make sure whether the APCu PHP extension is installed precisely.

phpX.Y-sp -i | grep apcu

Following will be the output of above cmd:

# Replace php7.X-sp => X with your PHP version
Additional .ini files parsed => /etc/phpX.Y-sp/conf.d/apcu.ini,


How to Uninstall the PHP APCu Extension?

Type the below command in terminal, to uninstall the PHP APCu extension.

# Replace php7.X-sp => X with your PHP version

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

Finally, don’t forget to restart the PHP-FPM:

sudo service phpX.Y-fpm-sp restart

Digamber - Author

Hi, I'm Digamber Singh, a New Delhi-based full-stack developer, tech author, and open-source contributor with 10+ years' experience in HTML, CSS, JavaScript, PHP, and WordPress.