How to Enable Persistent Object Caching in WordPress Using APCu on CWP with PHP-FPM 8.3

0 7 hours ago

Enabling persistent object caching in WordPress is one of the easiest ways to improve backend performance, reduce database load, and speed up page generation. If you’re using Control Web Panel (CWP) with ALT PHP-FPM 8.3, this guide will show you how to install and configure APCu, a lightweight and fast object cache engine supported by WordPress.

Let’s walk through how to manually compile and enable APCu for PHP-FPM 8.3 and use it effectively with your WordPress site.


🧠 Why Use APCu?

  • It stores frequently-used data directly in memory
  • No need for an external service like Redis or Memcached
  • Great for single-site WordPress instances
  • Reduces MySQL queries significantly

✅ Step 1: Confirm You’re Using ALT PHP-FPM 8.3

Check that your PHP-FPM build is installed in:

/opt/alt/php-fpm83/

If not yet installed, go to: CWP → PHP-FPM Selector → Rebuild PHP 8.3
Enable necessary modules like mbstring, imagick, ioncube, etc.


✅ Step 2: Download & Build APCu Manually

CWP’s ALT PHP builds don’t include PECL support by default, so you’ll manually compile APCu.

SSH into your server and run:

cd /usr/local/src
wget https://pecl.php.net/get/apcu
tar -xzf apcu
cd apcu-5.1.24 # or the latest version from the extraction

Build for PHP-FPM 8.3:

/opt/alt/php-fpm83/usr/bin/phpize
./configure --with-php-config=/opt/alt/php-fpm83/usr/bin/php-config
make
make install

✅ If successful, you’ll see:

swiftCopyEditInstalling shared extensions: /opt/alt/php-fpm83/usr/lib/php/extensions/...

✅ Step 3: Enable APCu in php.ini

nano /opt/alt/php-fpm83/usr/php/php.ini

Add this at the bottom:

extension=apcu.so
apc.enabled=1
apc.enable_cli=1
apc.shm_size=128M

Then save and exit.


✅ Step 4: Restart PHP-FPM 8.3

systemctl restart php-fpm83

✅ Step 5: Confirm APCu is Active

Run:

/opt/alt/php-fpm83/usr/bin/php -m | grep apcu

You should see:

nginxCopyEditapcu

You can also create a phpinfo.php file in your site’s public_html and visit it in a browser to visually confirm APCu is listed.


✅ Step 6: Enable Object Cache in WordPress

Option 1: Use the APCu Manager Plugin

  1. Go to WordPress Dashboard → Plugins → Add New
  2. Search: APCu Manager
  3. Install and activate the plugin

✅ WordPress will now automatically use APCu for object caching.


Option 2: Manual Drop-In

Alternatively, create a file called:

wp-content/object-cache.php

With the following content:

<?php
function wp_cache_add($key, $data, $group = '', $expire = 0) {
return apcu_add("wp_${group}_$key", $data, $expire);
}
function wp_cache_set($key, $data, $group = '', $expire = 0) {
return apcu_store("wp_${group}_$key", $data, $expire);
}
function wp_cache_get($key, $group = '', $force = false, &$found = null) {
$success = false;
$value = apcu_fetch("wp_${group}_$key", $success);
$found = $success;
return $value;
}
function wp_cache_delete($key, $group = '') {
return apcu_delete("wp_${group}_$key");
}
function wp_cache_flush() {
return apcu_clear_cache();
}
function wp_cache_init() {}
function wp_cache_close() {}
function wp_cache_replace($key, $data, $group = '', $expire = 0) {
return apcu_store("wp_${group}_$key", $data, $expire);
}
function wp_cache_incr($key, $n = 1, $group = '') {
return apcu_inc("wp_${group}_$key", $n);
}
function wp_cache_decr($key, $n = 1, $group = '') {
return apcu_dec("wp_${group}_$key", $n);
}

Then reload your WordPress site.


🧪 Step 7: Verify in WordPress Site Health

Go to:

Tools → Site Health → Status

✅ You should no longer see the message:

“You should use a persistent object cache”


🚀 Bonus Tip: Use Redis for Larger Sites

While APCu is great for single-site performance, if you’re hosting WooCommerce or high-traffic sites, consider using Redis (which supports multiple worker processes and persistent storage).


💬 Need Help?

If you’d prefer an expert to configure this for you:

📨 Contact Servers9 Support — their team can fully optimize your CWP + WordPress stack with APCu, Redis, or any caching solution.