Operating System Ubuntu

XCache Is Discontinued: Use OPcache and APCu on Ubuntu 26.04 Instead

XCache was last released in 2014 and only supports PHP 5. Here is its status and how to use OPcache and APCu on Ubuntu 26.04 LTS and 24.04 LTS instead.

XCache cannot be installed on any supported Ubuntu release. The project stopped at version 3.2.0 in 2014, works only with PHP 5, and its package (php5-xcache) disappeared from Ubuntu together with PHP 5. This article explains the status and shows what replaces it on Ubuntu 26.04 LTS and 24.04 LTS: OPcache for compiled-script caching and APCu for caching your own data.

What XCache was and where it stands

XCache was an opcode cache for PHP 5 developed under the lighttpd project. It kept compiled PHP scripts in shared memory so they did not have to be parsed on every request, offered a key-value API (xcache_get(), xcache_set()) for application data, and shipped a small web control panel.

  • The last release, 3.2.0, dates from September 2014 and supports PHP up to 5.6. There has been no release for PHP 7 or 8.
  • Distributions dropped it with PHP 5. FreeBSD, for example, removed its XCache port on 30 December 2018 with the note that it works only with end-of-life PHP 5.6.
  • Applications followed: TYPO3 removed its XCache cache backend in version 8.2 because PHP 7 does not support XCache.

Ubuntu 15.04 itself has been end-of-life since early 2016. Do not try to build XCache from source against a current PHP; it does not compile.

The replacement for opcode caching: OPcache

OPcache is PHP's own opcode cache and does the job XCache's cacher did. How you get it depends on the PHP version:

  • Ubuntu 26.04 LTS (PHP 8.5): as of PHP 8.5, OPcache is always built into the PHP binary and always loaded. There is no separate package to install and no php8.5-opcache package in the archive.
  • Ubuntu 24.04 LTS (PHP 8.3): OPcache is a separate extension package, php8.3-opcache, which is installed along with PHP by default.

Install PHP if you have not done so. For Apache with mod_php:

sudo apt update
sudo apt install -y apache2 php libapache2-mod-php

For Nginx or Apache with PHP-FPM, install php-fpm instead of libapache2-mod-php.

Verify that OPcache is active

php -v
php -i | grep -E '^opcache\.(enable|memory_consumption) '

The first command should include a line "with Zend OPcache". Note that the command-line PHP has its own configuration, and OPcache is normally disabled for it (opcache.enable_cli) while being enabled for the web server. To see the values the web server uses, call opcache_get_status() from a script served by it, or look at the output of phpinfo().

Tune OPcache

The defaults work for small sites. To change them, create a file in the configuration directory of the PHP variant your web server uses. On Ubuntu 26.04 with PHP-FPM that is /etc/php/8.5/fpm/conf.d/; with mod_php it is /etc/php/8.5/apache2/conf.d/. On 24.04, replace 8.5 with 8.3.

sudo nano /etc/php/8.5/fpm/conf.d/99-opcache-tuning.ini
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60

These are the values the PHP manual recommends as a starting point. opcache.revalidate_freq=60 means PHP checks a script for changes at most once a minute, so an edited file can take up to 60 seconds to show up. Apply the change:

sudo systemctl restart php8.5-fpm

With mod_php, restart Apache instead: sudo systemctl restart apache2.

The replacement for the data cache: APCu

OPcache caches only compiled code. If an application used XCache's variable cache, the equivalent is APCu, an in-memory key-value store for a single server. It is packaged in Ubuntu's universe component:

sudo apt install -y php-apcu
sudo systemctl restart php8.5-fpm
php -m | grep apcu

In your own code, xcache_set(), xcache_get(), xcache_isset() and xcache_unset() map to apcu_store(), apcu_fetch(), apcu_exists() and apcu_delete(). In an application or framework, switch its cache driver setting from XCache to APCu (or to Redis or Memcached if several servers must share the cache). The old apcu-bc compatibility layer is not supported on PHP 8.

See the PHP manual for the OPcache and APCu configuration directives.

Frequently asked questions

Is there a replacement for the XCache control panel?

Not a bundled one. PHP exposes the same information through opcache_get_status() and apcu_cache_info(), and phpinfo() shows a summary. Third-party dashboards built on these functions exist; if you install one, protect it with authentication, because it reveals file paths and can reset the cache.

I still run a PHP 5 application that uses XCache. What should I do?

Migrate it. PHP 5 has received no security fixes since the end of 2018, and no supported Ubuntu release packages it. Moving to a supported PHP version gives you OPcache automatically, and the XCache variable-cache calls can be replaced with APCu as shown above.

Do I need both OPcache and APCu?

OPcache benefits every PHP site and needs no code changes. APCu is only useful when the application is written or configured to store data in it, so install it when your application's documentation asks for it.

Share story:

Continue reading other guides on How VPS.