PHP Development

How to Enable OPcache for PHP

By the Domain India teamPublished 5 min read
Knowledge base article
Contents (6 sections)

OPcache keeps compiled PHP code in memory so PHP does not have to read and compile your scripts on every request. On Domain India shared hosting you normally do not need to enable it: it is a server setting, and it is already on for websites on our cPanel servers. This page shows how to check it for your own site, and how to turn it on if you run your own VPS.

For the full OPcache guide

Settings you can and cannot change, stale-code problems and VPS tuning are covered in PHP OPcache configuration.

Key takeaways

On shared hosting there is nothing to enable: OPcache is on for websites on our cPanel servers, and on our DirectAdmin servers for every PHP version except PHP 8.3 (measured 20 September 2026). On our Webuzo server it is on for PHP 8.0 and 8.1 (measured 30 September 2026). Shared hosting customers cannot edit the server's php.ini or restart the web server, and don't need to. On a VPS, you enable it in your PHP version's OPcache configuration file and reload PHP-FPM.

1. Is OPcache already on for my site?

Server typeOPcache for websitesWhat to do
cPanelLoaded and enabledNothing
DirectAdminEnabled on every PHP version except PHP 8.3Nothing, unless your site runs PHP 8.3
WebuzoNot measuredAsk support

On the command line (SSH and cron jobs) OPcache is off on our cPanel servers. That is normal, because a script run from the command line runs once and exits, and it does not affect your website.

DirectAdmin on PHP 8.3

PHP 8.3 on our DirectAdmin servers had OPcache switched off when we measured it, and it can't be switched on from inside your account. If your site runs PHP 8.3 on DirectAdmin and you want OPcache, open a ticket and we will tell you the options for your account.

2. Check your own site

Settings can differ between PHP versions and change after server updates, so check the value your site actually uses. Create a file called oc-check.php in your public_html folder:

php
<?php
header('Content-Type: text/plain');
echo 'PHP version: ', PHP_VERSION, "\n";
echo 'OPcache loaded: ', extension_loaded('Zend OPcache') ? 'yes' : 'no', "\n";
echo 'opcache.enable: ', ini_get('opcache.enable') ? 'on' : 'off', "\n";

Open https://yourdomain.com/oc-check.php, note the result, then delete the file. If it says opcache.enable: on, your site uses OPcache and there is nothing to do. If it says off or loaded: no, open a support ticket with the output.

Don't use a phpinfo() page for this: phpinfo() is disabled on our cPanel servers, so the page comes up blank or with a warning. ini_get() is not disabled. Don't check over SSH either, because php -i reports the command-line PHP, where OPcache is off.

3. Why you don't edit php.ini on shared hosting

Older guides tell you to edit the server's php.ini, raise opcache.memory_consumption and restart Apache. None of that applies to a shared hosting account:

  • The server's PHP configuration and the web server are managed by us for everyone on that server. You can't restart Apache or PHP, and you don't need to.
  • OPcache's memory, string buffer and file-count settings are server-wide. PHP ignores them in a .user.ini, a per-site php.ini or the MultiPHP INI Editor, so pasting a tuning snippet there changes nothing.
  • A php_value or php_flag line in .htaccess gives a 500 error on our servers, because PHP does not run as an Apache module.

A normal website needs no OPcache tuning. If you think yours does, open a ticket and tell us why.

4. Enabling OPcache on a VPS

On a VPS you run PHP yourself, so OPcache is yours to configure. In short:

  1. Make sure the extension is installed.
    Most current PHP packages include OPcache; on some distributions it is a separate package for your PHP version.
  2. Edit your PHP version's OPcache configuration file.
    Its location depends on your operating system and PHP packages. Set opcache.enable=1 and the values you want.
  3. Reload PHP-FPM.
    OPcache belongs to the PHP process, so reload PHP-FPM (not only the web server) for the change to apply.
  4. Check it from a web page,
    with ini_get('opcache.enable') as in section 2, and later with opcache_get_status() for the hit rate.

A good starting configuration, and advice on max_accelerated_files, validate_timestamps and clearing the cache, is in section 7 of the OPcache guide. Leave out opcache.fast_shutdown, which still appears in older guides: it was removed in PHP 7.2.

5. OPcache is not a page cache

OPcache saves compiled code, but PHP and your database queries still run on every request. For a WordPress site on shared hosting, the bigger gain usually comes from a page-caching plugin such as WP Super Cache or W3 Total Cache (our shared hosting runs Apache) and a current PHP version. See my website is slow and how to change your PHP version.

Support is on 24/7 live chat, and tickets get a first response within 15 minutes; how long a fix takes depends on the issue. We do not offer phone support.

Frequently asked questions

Do I need to enable OPcache on Domain India shared hosting?

No. OPcache is enabled for websites on our cPanel servers, and on our DirectAdmin servers for every PHP version except PHP 8.3 (measured 20 September 2026). On our Webuzo server it is enabled for PHP 8.0 and 8.1 (measured 30 September 2026).

How do I check if OPcache is on for my website?

Create a temporary PHP file that prints ini_get('opcache.enable'), open it in your browser, then delete it. This works even though phpinfo() is disabled on our cPanel servers.

Can I change OPcache settings in php.ini on shared hosting?

No. OPcache memory and file-count settings are server-wide, and PHP ignores them in a .user.ini or per-site php.ini. Shared hosting customers also cannot restart Apache or PHP. A normal website doesn't need these settings changed.

Why does OPcache show as off when I check over SSH?

Command-line PHP has OPcache off on our cPanel servers, which is normal because each command-line script runs once and exits. Check from a web page instead.

How do I enable OPcache on a VPS?

Install the OPcache extension for your PHP version if it isn't already included, set opcache.enable=1 in your PHP version's OPcache configuration file, reload PHP-FPM, and check the result from a web page with ini_get('opcache.enable').

Ready to check your site? Run the test file from section 2, read the full OPcache guide, or open a ticket if OPcache is off for your PHP version.

OPcache off, or not sure what you're seeing?

Send us your domain, the PHP version your site uses and the output of the check script, and we will tell you what your server has enabled.

Open a support ticket

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app
How to Enable OPcache for PHP | Domain India