Knowledge Base

Browse our knowledge base for free solutions to common problems

Easily Install OPcache & Disable Per Domain In DirectAdmin

Created On: 20 May 2025
Written by: Ben

Introduction

OPcache is a built-in bytecode caching engine for PHP that plays a crucial role in enhancing website performance. By storing precompiled script bytecode in memory, it reduces the need for PHP to load and parse scripts on every request, resulting in faster execution times and lower server load. In hosting environments like DirectAdmin, enabling OPcache globally is a common best practice for improving the performance of PHP-based websites.

However, there are situations—especially in development or debugging environments—where having OPcache enabled for a specific domain can be counterproductive. Developers might want to see code changes take effect immediately, which is not possible when it is aggressively caching scripts. In such cases, it becomes necessary to disable OPcache selectively for just one domain without affecting others on the same server.

This article walks you through the process of installing OPcache in a DirectAdmin environment and shows how to configure it so that it remains active for all domains except the one(s) where you choose to disable it. Using DirectAdmin’s custom configuration tools and PHP administrative flags, you’ll learn how to fine-tune it's behavior on a per-domain basis to suit different hosting or development needs.

Install OPcache On DirectAdmin Server

First navigate to your custom build directory via SSH:

cd /usr/local/directadmin/custombuild

Make a new directory within the custom folder. This will allow us to create custom configuration which we can apply for all installed PHP versions:

mkdir -p custom/opcache

Copy the default opcache.ini to the custom folder that we have just created:

cp -p configure/opcache/opcache.ini custom/opcache/opcache.ini

Edit the file:

nano custom/opcache/opcache.ini

Change it to your liking, this is my file in full:

; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 1000000 are allowed.
;opcache.max_accelerated_files=10000
;opcache.max_accelerated_files=10000

; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation. ("1" means validate once per second, but only
; once per request. "0" means always validate)
;opcache.revalidate_freq=2
;opcache.revalidate_freq=60

; Enables or disables file search in include_path optimization
;opcache.revalidate_path=0
;opcache.revalidate_path=1

; Validate cached file permissions.
;opcache.validate_permission=0
;opcache.validate_permission=1

; Allow file existence override (file_exists, etc.) performance feature.
;opcache.enable_file_override=0
;opcache.enable_file_override=1

; Disable opcache api calls by default, making script path invalid
; which is normally expected to start with /.
; Php defaults to accept all paths.
;opcache.restrict_api=""
;opcache.restrict_api=1




; CUSTOM
; SEE: 
opcache.enable=1
opcache.enable_cli=1
opcache.save_comments=1
opcache.revalidate_freq=1
opcache.validate_timestamps=0
opcache.interned_strings_buffer=128
opcache.max_accelerated_files=10000
opcache.memory_consumption=512

Notice I just comment most of the default settings out and just apply what I need as a big chunk at the bottom of the file.

Now that we have the settings inside of the config file enable OPCache inside of custombuild with the following command:

da build set_php "opcache" yes

Now build OPcache with:

./build opcache

Thats it! The installation of OPcache within DirectAdmin is now complete and you should be able to use it within your applications.

Disable OPcache Per Domain In DirectAdmin

Now that we have OPCache enabled globally it can be useful to sometimes disable it per domain. Some applications such as WHMCS do not like to have it enabled. We can disable OPcache inside of the domains PHP FPM configuration by navigating to the following:

DirectAdmin (Admin) > Server Manager > Custom HTTPD Configurations > DOMAIN > php-fpm.conf 8.2 conf

Once there we can paste the following line inside of the "php-fpm Global |CUSTOM2|" box:

php_admin_flag[opcache.enable] = 0

See the example below:

opcache disabled

Thats it! OPcache should now be disabled for the domain name that you have applied the configuration to. Adding it into the Global CUSTOM2 field also means that these changes will persist even when the user changes the PHP version of the website.

For more information on how PHP FPM configurations can be customised in DirectAdmin please refer to their official documentation on it here.

For other useful guides please check out Knowledge Base.

ICTU LTD is a company registered England and Wales (Company No. 09344913) 15 Queen Square, Leeds, West Yorkshire, England, LS2 8AJ
Copyright © 2025 ICTU LTD, All Rights Reserved.
exit