Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

mod_cache not creating cache files?

Discussion in 'Workarounds and Optimization' started by User8472, Apr 24, 2018.

Tags:
  1. User8472

    User8472 Registered

    Joined:
    Apr 24, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    US
    cPanel Access Level:
    Root Administrator
    Hello,

    I'm trying to get mod_cache to work. I believe everything needed is installed through EasyApache4 (mod_cache and mod_cache_disk). I added a configuration to the pre_main_global include (see below) and apache restarts successfully with no errors but no cache files are being put into /var/cache/apache2/mod_cache_disk folder.

    I've read the apache docs and numerous threads but can't seem to find a reason why cache files aren't being generated.

    Here's what I added to the apache pre_main_global include:

    Code:
    # mod_cache code
    #Following line not needed
    #LoadModule3 cache_module modules/mod_cache.so
    
    <IfModule mod_cache.c>
        CacheQuickHandler off
    
        CacheIgnoreNoLastMod On
        CacheDefaultExpire 7200
    
        CacheIgnoreCacheControl Off
        CacheLastModifiedFactor 0.5
        CacheIgnoreHeaders Set-Cookie Cookie
        CacheHeader on
        CacheLock on
        CacheDisable /wp-admin
        CacheDisable /wp-login.php
        CacheDisable /wp-cron.php
    
        SetOutputFilter CACHE
        AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/rss+xml text/xml image/svg+xml
    
        #Following line not needed
        #LoadModule cache_disk_module modules/mod_cache_disk.so
    
        <IfModule mod_cache_disk.c>
            CacheRoot /var/cache/apache2/mod_cache_disk
            CacheEnable disk /
            CacheDirLevels 2
            CacheDirLength 1
            CacheMaxFileSize 2000000
        </IfModule>
    </IfModule>
    
    If I enable the LoadModule lines, I get an error that the modules are already loaded when apache is restarted through the command line (service httpd restart).

    The mod_cache_disk folder is owned by nobody with full 777 permissions (777 is for testing, just to see if folder permissions were an issue).

    The server and site appear to be healthy just not seeing any cache files being generated (this is being tested on a Wordpress installation, the only domain on the server).

    Any insights would be appreciated.
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,749
    Likes Received:
    1,885
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @User8472,

    It looks like the issue might relate to the custom entry you are using under the "Pre Main Include" section. Here are the steps I took when testing with a standard configuration:

    1. Install the required RPMs:

    Code:
    yum install ea-apache24-mod_cache ea-apache24-mod_cache_disk
    2. Create the cache storage directory:

    Code:
    mkdir /var/cache/apache2/mod_cache/
    chmod 0700 /var/cache/apache2/mod_cache
    chown nobody.nobody /var/cache/apache2/mod_cache/
    3. Add the following entry to the "Pre Main Include" section in "WHM >> Apache Configuration >> Include Editor":

    Code:
    <IfModule cache_disk_module>
        CacheQuickHandler Off
    
        # Must be writable by apache 700 nobody:nobody
        CacheRoot /var/cache/apache2/mod_cache/
    
        CacheEnable disk /
        CacheDirLevels 2
        CacheDirLength 1
    
        # X-Cache: [HIT|MISS]
        # CacheHeader on
    </IfModule>
    4. Create /home/username/public_html/cache.php with the following contents:

    Code:
    <?php
    
    header("Cache-Control: must-revalidate, max-age=300");
    
    header("Vary: Accept-Encoding");
    
    echo time() . "\n";
    
     
    // Get the current default response code
    
    var_dump(http_response_code());
    
     
    
    // Set a response code
    
    var_dump(http_response_code(201));
    
     
    
    // Get the new response code
    
    var_dump(http_response_code());
    
    ?>
    5. Open $domain.tld/cache.php in a web browser.

    6. Confirmed the cache files were generated in in the /var/cache/apache2/mod_cache/ directory:

    Code:
    # pwd
    /var/cache/apache2/mod_cache/Q/Y
    # ls -al
    total 4
    drwx------ 3 nobody nobody 81 Apr 25 09:46 .
    drwx------ 3 nobody nobody 15 Apr 25 09:46 ..
    -rw------- 1 nobody nobody 31 Apr 25 09:46 ye5IIyK6mE2K1mVMw7kw.header
    drwx------ 3 nobody nobody 15 Apr 25 09:46 ye5IIyK6mE2K1mVMw7kw.header.vary
    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. User8472

    User8472 Registered

    Joined:
    Apr 24, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    US
    cPanel Access Level:
    Root Administrator
    Thanks for the reply. It turns out that the CacheLock on in my original example was preventing the cache files from being created. Just commenting out that line enabled the cache files to be generated - not sure why though, it's a valid directive according to the apache documentation.

    Unfortunately, both my example and the example you provided produce unexpected results on the Wordpress site. Seemingly random files are served up using either configuration (the homepage seems fine, but further navigation produces unexpected content). But that's a separate issue.

    Also a quick question regarding your example. Shouldn't the CacheQuickHandler off be in a separate section as below?
    Code:
    <IfModule cache_module>
        CacheQuickHandler off
    </IfModule>
    
    Or am I misunderstanding how the cache directives are handled? Can directives from the cache_module be included in the cache_disk_module section? Apache doesn't complain either way.

    Thanks again for your help!
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,749
    Likes Received:
    1,885
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    Yes, it's a directive of cache_module so it's generally better if it's part of the "<IfModule cache_module>" statement. That said, it should still work in either case in this instance because both of those Apache modules are enabled on the system. Any valid configuration value added to IfModule statements should work as long as that particular Apache module is enabled, even if it's not a directive of that particular module. This is documented in more detail at:

    core - Apache HTTP Server Version 2.4

    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice