Cloud House Technologies Logo
CloudHouse Technologies
HomeServicesProjectsBlogAbout UsCareersContact UsLogin
    Cloud House Technologies Logo
    CloudHouse Technologies
    HomeServicesProjectsBlogAbout UsCareersContact UsLogin

    How to Enable and Configure PHP OPcache in DirectAdmin for Faster Website Loading

    Priya

    Content Writer & Researcher

    Last Updated: 1 July 2026
    🖥️

    Is Your DirectAdmin Server Running Slow Despite Good Hardware?

    CloudHouse's server engineers can tune PHP OPcache, configure PHP-FPM pools, and optimise your full DirectAdmin stack — reducing CPU load by 30–50% and improving site load times measurably. Get a free server performance audit.

    🔧 Book Free DiagnosisCall NowWhatsApp
    🖥️12,400+PCs Fixed
    ⭐4.9★Google Rating
    ⚡<15 minAvg. Response
    🛡️ISO 27001Certified

    PHP OPcache is one of the highest-impact, lowest-effort performance improvements you can make on a DirectAdmin server. By caching compiled PHP bytecode in shared memory, OPcache eliminates the need to parse and compile PHP scripts on every request — reducing CPU usage by 30–50% on busy servers and cutting page load times dramatically. This guide walks you through installing OPcache via DirectAdmin's CustomBuild, tuning it correctly for production workloads, and configuring it for servers running multiple PHP versions.

    What PHP OPcache Does and Why It Matters

    Every time a PHP script runs without OPcache, the PHP engine must:

    • Read the source file from disk
    • Tokenise and parse the PHP code
    • Compile it to opcodes (bytecode)
    • Execute those opcodes

    With OPcache enabled, steps 1–3 happen only once per file (or until the file changes). The compiled opcodes are stored in shared memory and reused on subsequent requests. For a typical WordPress site with 400–800 PHP files loaded per request, this removes thousands of disk reads and compile operations per second.

    The result: lower CPU, faster TTFB (Time to First Byte), and the ability to handle significantly more concurrent visitors on the same hardware.

    Step 1: Check If OPcache Is Already Installed

    Before installing, check whether OPcache is already present on your DirectAdmin server:

    php -m | grep -i opcache

    If the output shows Zend OPcache, OPcache is installed (though it may be disabled or misconfigured). Check its status:

    php -i | grep -i opcache.enable

    If nothing is returned or you see opcache.enable=0, proceed with installation.

    💡 None of these worked? Skip the guesswork.

    Get Expert Help →

    Step 2: Install OPcache via DirectAdmin CustomBuild

    DirectAdmin uses CustomBuild 2.0 to manage PHP extensions including OPcache. All installation is done as root via SSH.

    1Navigate to the CustomBuild directory
    cd /usr/local/directadmin/custombuild
    2Enable OPcache in the CustomBuild options
    ./build set opcache yes
    3Build and install OPcache
    ./build opcache

    CustomBuild compiles OPcache for each PHP version installed on the server. This may take 5–15 minutes depending on how many PHP versions are configured. You will see output for each version as it compiles.

    4Verify installation
    php -m | grep -i opcache

    You should now see Zend OPcache in the output.

    Step 3: Configure OPcache for Production Performance

    The default OPcache settings that ship with PHP are conservative and not tuned for a busy web server. You need to edit the php.ini file for each PHP version.

    Find all OPcache-enabled php.ini files:

    find /usr/local/php* -name php.ini 2>/dev/null
    # Also check:
    find /etc/php* -name php.ini 2>/dev/null

    For each php.ini file, find the [opcache] section (or add it at the bottom) and apply these settings:

    [opcache]
    opcache.enable=1
    opcache.enable_cli=0
    opcache.memory_consumption=256
    opcache.interned_strings_buffer=32
    opcache.max_accelerated_files=20000
    opcache.revalidate_freq=60
    opcache.validate_timestamps=1
    opcache.save_comments=1
    opcache.fast_shutdown=1
    opcache.enable_file_override=0

    What Each Setting Means

    • opcache.enable=1 — enables OPcache for web requests (always set this to 1)
    • opcache.enable_cli=0 — disables OPcache for CLI PHP (leave off unless you run long-running CLI scripts that benefit from caching)
    • opcache.memory_consumption=256 — RAM (in MB) allocated to the OPcache shared memory segment. See sizing guide below
    • opcache.interned_strings_buffer=32 — separate RAM pool for interned strings (class/function names). 32 MB is sufficient for most WordPress/Laravel setups
    • opcache.max_accelerated_files=20000 — maximum number of PHP files OPcache can store. Must be higher than the total number of PHP files on the server
    • opcache.revalidate_freq=60 — how often (in seconds) OPcache checks if a file has changed on disk. Set to 0 only in development
    • opcache.validate_timestamps=1 — OPcache checks file modification time before using cached version. Keep at 1 unless you have a deployment process that flushes OPcache on deploy
    • opcache.save_comments=1 — required by Doctrine, Laravel, and many frameworks that use PHP docblock annotations

    Step 4: Size OPcache Memory Correctly for Your Server

    The most common OPcache mistake is setting memory_consumption too low. When the cache fills up, OPcache starts evicting entries and performance degrades to near-uncached levels.

    To size OPcache correctly, first count the PHP files on your server:

    find /home -name "*.php" | wc -l

    Then estimate the memory needed. As a rule of thumb, each PHP file consumes approximately 10–15 KB of OPcache memory after compilation. Multiply the file count by 15 KB to get a conservative estimate:

    # Example: 8,000 PHP files × 15 KB = 120 MB → set memory_consumption=192

    For shared hosting servers with many accounts, set memory_consumption to at least 256 MB. For large servers with 50+ WordPress installations, 512 MB is appropriate.

    Check OPcache memory usage after 30 minutes of production traffic:

    php -r "print_r(opcache_get_status());" | grep -E 'used_memory|free_memory|wasted'

    If used_memory is within 10% of total allocated memory, increase memory_consumption. If wasted_percentage exceeds 5%, consider increasing max_wasted_percentage or restarting PHP-FPM more frequently to compact the cache.

    Step 5: Configure OPcache for Multiple PHP Versions

    DirectAdmin servers often run PHP 7.4, 8.1, 8.2, and 8.3 simultaneously for different user accounts. You must configure OPcache separately in each version's php.ini.

    Find all PHP version ini files:

    ls /usr/local/php*/lib/php.ini

    Apply the same OPcache settings to each file. You can automate this with a loop:

    for ini in /usr/local/php*/lib/php.ini; do
      echo "Configuring OPcache in: $ini"
      # Enable OPcache
      sed -i 's/^;opcache.enable=.*/opcache.enable=1/' "$ini"
      sed -i 's/^opcache.enable=.*/opcache.enable=1/' "$ini"
      # Set memory
      sed -i 's/^;opcache.memory_consumption=.*/opcache.memory_consumption=256/' "$ini"
      sed -i 's/^opcache.memory_consumption=.*/opcache.memory_consumption=256/' "$ini"
      # Set max files
      sed -i 's/^;opcache.max_accelerated_files=.*/opcache.max_accelerated_files=20000/' "$ini"
      sed -i 's/^opcache.max_accelerated_files=.*/opcache.max_accelerated_files=20000/' "$ini"
    done

    After editing any php.ini file, restart PHP-FPM for each version:

    systemctl restart php-fpm74
    systemctl restart php-fpm81
    systemctl restart php-fpm82
    systemctl restart php-fpm83

    Or restart all at once:

    systemctl restart 'php-fpm*'

    Step 6: Verify OPcache Is Working

    Create a phpinfo test file in a domain's web root:

    echo " /home/USER/domains/DOMAIN/public_html/phpinfo.php

    Visit https://yourdomain.com/phpinfo.php in a browser and search for "opcache". You should see a section headed Zend OPcache with Opcode Caching: Enabled.

    Delete the phpinfo file immediately after testing:

    rm /home/USER/domains/DOMAIN/public_html/phpinfo.php

    For a more detailed status check, create a temporary monitoring script:

    cat > /tmp/opcache_check.php << 'PHP'
    

    A healthy OPcache shows a hit rate above 95% after the first few minutes of traffic.

    Disabling OPcache for a Specific Domain (Per-Domain Override)

    If a specific application breaks with OPcache enabled (rare, but can happen with dynamic class generation), you can disable OPcache for that domain without affecting others. Add this to the domain's .htaccess:

    php_flag opcache.enable 0

    Or if using PHP-FPM pools, add to the domain's PHP-FPM pool config:

    php_admin_value[opcache.enable] = 0

    For professional DirectAdmin performance tuning — including OPcache sizing, PHP-FPM pool configuration, and MySQL query optimisation — CloudHouse's server management team can audit your entire server stack and implement changes that immediately reduce load and improve page speeds.

    Get the Free Linux Server Admin Cheatsheet (PDF)

    Essential commands for server management, networking, and troubleshooting — all on one printable page.

    Running Linux servers? Let us manage them for you.

    Our Managed Linux Server plans cover updates, security hardening, monitoring, and 24/7 incident response — so your servers stay up and your team stays focused.

    • Proactive OS patching and security updates
    • 24×7 monitoring with instant alerting
    • Backup configuration and disaster recovery
    • Dedicated Linux engineers on call
    See Pricing Plans →

    What our customers say

    “Our production server went down at 2 AM. CloudHouse had it back online in under 20 minutes. Incredible response time.”

    Arun S.

    CTO, SaaS Startup

    “They migrated our entire infrastructure from Ubuntu 18 to 22 with zero downtime. Couldn't have asked for better.”

    Deepak N.

    DevOps Lead

    Frequently Asked Questions

    No full server restart is needed, but you must restart PHP-FPM after editing php.ini. Run systemctl restart php-fpm81 (or whichever version you edited). If you use Apache's mod_php instead of PHP-FPM, restart Apache with systemctl restart httpd (CentOS) or systemctl restart apache2 (Debian/Ubuntu). The OPcache changes take effect immediately after the PHP service restarts.

    Book your free 15-minute diagnosis

    A certified technician will call you back within 15 minutes during business hours.

    Share this article

    Leave a Comment

    Comments (0)

    Loading comments...

    Need Help Speeding Up Your DirectAdmin Server?

    Enabling OPcache is just the start. CloudHouse's performance engineers can size your OPcache correctly, optimise PHP-FPM worker counts, and tune MySQL — giving you dramatically faster sites without upgrading hardware.

    Call Now — FreeWhatsApp Us

    Why CloudHouse?

    • ISO 27001:2022 certified
    • 12,400+ devices supported
    • 4.9★ on Google
    • Sub-15-minute response

    CloudHouse Technologies

    Innovative cloud solutions for modern businesses. We deliver cutting-edge technology with exceptional service.

    Contact Us

    CloudHouse Technologies Pvt.Ltd
    Special Economic Zone(SEZ),
    Infopark Thirissur,4B-15,
    Indeevaram,Nalukettu Road,
    Koratty, Kerala, India-680308
    0480-27327360
    info@cloudhousetechnologies.com

    Quick Links

    • Our Services
    • Gold Loan Software
    • About Us
    • Contact
    • Terms and Conditions
    • Privacy Policy
    ISO27001:2022
    Certified

    © 2026 CloudHouse Technologies Pvt.Ltd. All rights reserved.

    Back to top