Install APCu (Alternative PHP Cache) on CentOS 7

Last modified on February 6, 2020 1 min read

Today we will install APCu (Alternative PHP Cache) on CentOS 7. APCu provided both opcode caching (opcache) and object caching APCu is the replacement for the outdated APC extension. It’s very easy to install. Just follow these steps:

Step 1 : Login to Server

At first, we need to login to our server via SSH. Open your terminal and run this command:

ssh [email protected] -p PORT

Step 2 : Install APCu

Before installing APCu, if your server doesn’t have Remi Repository, install that first using this command:

sudo yum install

Now run this command to install APCu:

sudo yum install php-pecl-apcu

Step 3 : Dependency Packages for APCu

By entering this command, you can install dependency packages for APCu:

sudo yum install php-pear php-devel httpd-devel pcre-devel gcc make

Step 4 : Restart Web Server

Finally restart your web server to enable APCu:

# apache
sudo systemctl restart httpd php-fpm
# nginx
sudo systemctl restart nginx php-fpm

Now check your phpinfo(); script to see APCu is installed or not:

Step 5 : APCu Admin Page

This is an optional step. I’m sharing a PHP file. You need to keep this file to your domain’s public html folder to see APCu admin page. Download this file from GitHub:

Now open the file from browser (

The default username and password is: admin, admin. You can change this from the apcu.php file:

#0 or 1. 0 for disable user and pass


Step 6 : Config APCu

We can easily configure APCu. Open /etc/php.ini file and add value like this:

# Memory Segments
## PHP file cache 1 hour ##
## User cache 2 hour ##
## Garbage collection 1 hour ##

We need to restart the webserver again. This link will help you APCu Runtime Configuration.

Step 7 : Store and Fetch Data

Create a file named cache.php and paste this code:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

$cache_name = "test_c_1";
$expire_time = 10;

if (apcu_exists($cache_name) && !isset($_GET['reload-cache'])) {
	echo 'Load from Cache:<br>';
  $data = apcu_fetch($cache_name);
else {
	echo 'Cache Miss!<br>';
	$data = Date("d M, Y - h:i:s");
	apcu_store($cache_name, $data, $expire_time);

echo $data;

Now visit the cache.php to see the output.

The article is over. Thank you. 🙂

Monthly Newsletter

One email a month, packed with the latest tutorials, delivered straight to your inbox.
We'll never send any spam or promotional emails.

Hey, I'm Md Obydullah. I build open-source projects and write article on Laravel, Linux server, modern JavaScript and more on web development.


8 Replies to “Install APCu (Alternative PHP Cache) on CentOS 7”

  1. Hello,
    There is a specific configuration to work CLI, I run a test saving a variable in the terminal, but the second time I get the created variable returns nothing, as if I had not created …
    What would it be like to use APCU CLI php?

    1. Hello, I think your server doesn’t have Remi Repository. First install that using this command: sudo yum install

      Let me know if it works or not. I’ve updated the article too. Thanks for your feedback.

  2. phpinfo shows apcu installed and enabled. acpu.php works, but cache.php does nothing. It is just a blank page, no output or anything. I have triple checked for typos.

    1. Hi Evin,

      I’m sorry for late reply. To allow httpd integrated PHP module to do network access in an enforcing SELinux environment, you have to run this command on your server setsebool -P httpd_can_network_connect on.


Leave a Reply