Showing posts with label Drupal. Show all posts
Showing posts with label Drupal. Show all posts

Wednesday, 8 July 2026

How to Configure Apache Microcache for Drupal?

Configure Apache Microcache

Apache HTTP Server, commonly known as Apache, is a widely used open-source web server. Caching is an essential aspect of web server optimization — it can significantly improve response time and reduce load on the server. “Apache Microcache” typically refers to a small, quickly-accessible cache used to improve performance, often for a short TTL on top of an origin that would otherwise be hit on every request.

Here are the general steps to configure an Apache Microcache in front of Drupal.

1. Enable mod_cache and the disk cache module

Make sure the caching modules are loaded in your Apache configuration:

sudo nano /etc/httpd/conf/httpd.conf

# Ensure mod_cache is loaded:
LoadModule cache_module modules/mod_cache.so

# Load the disk cache backend. The module name/file depends on your Apache version:
#   Apache 2.4+ (current):  mod_cache_disk  ->  modules/mod_cache_disk.so
#   Apache 2.2 (legacy):    mod_disk_cache  ->  modules/mod_disk_cache.so
LoadModule cache_disk_module modules/mod_cache_disk.so

Version note: mod_disk_cache was renamed to mod_cache_disk in Apache 2.4. Check httpd -v first, and match the LoadModule line, the .so filename, and the <IfModule> guard below to whichever version you’re actually running — mixing the 2.2 and 2.4 names is a common cause of “module not loaded” errors.

2. Configure mod_cache and the disk cache

Below is a baseline configuration tuned for Drupal. Adjust it for your own traffic patterns and site structure; other CMSs will need different CacheDisable paths and TTLs.

<IfModule mod_cache.c>
  # Turn off CacheQuickHandler so requests still pass through
  # other output filters (needed for compression below).
  CacheQuickHandler Off

  # Cache headers off by default; enable only for debugging.
  CacheHeader Off
  CacheDetailHeader Off

  # Cache responses even without a Last-Modified header.
  CacheIgnoreNoLastMod On

  # Cache expiry (seconds).
  CacheDefaultExpire 180
  CacheMinExpire 5
  CacheStoreExpired Off
  CacheLastModifiedFactor 0.5

  # Ignore upstream cache-control so short TTLs above take effect.
  CacheIgnoreCacheControl On
  CacheIgnoreHeaders Set-Cookie Cookie

  # Avoid stampedes / stale serving during revalidation.
  CacheLock On
  CacheLockMaxAge 5

  # Never cache the admin area.
  CacheDisable /admin

  # GZIP compression on cached output.
  SetOutputFilter CACHE
  AddOutputFilterByType DEFLATE text/html text/plain text/css \
                        application/javascript \
                        application/rss+xml \
                        text/xml image/svg+xml

  # Disk cache backend.
  <IfModule mod_cache_disk.c>
    # Adjust CacheRoot to a writable path on your server.
    CacheRoot /var/cache/httpd/proxy/
    CacheEnable disk /
    CacheDirLevels 2
    CacheDirLength 1
    CacheMaxFileSize 20000000
  </IfModule>
</IfModule>

Adjust CacheRoot to point to the directory where you want cached data stored, and make sure that directory is writable by the Apache user (chown -R apache:apache /var/cache/httpd/proxy/ or the equivalent for your distro).

3. Save and restart Apache

sudo systemctl restart apache2
# or, on RHEL/CentOS-based systems:
sudo systemctl restart httpd

Things to watch for on a real Drupal deployment

  • Authenticated sessions: CacheIgnoreHeaders Set-Cookie Cookie means Apache will happily cache a response even when a session cookie is present. Pair this with CacheDisable on any authenticated paths (/user, /admin, /node/*/edit, etc.) or you risk serving one user’s personalized page to another.
  • Cache purging: this config has no active purge/ban mechanism — it’s TTL-based only. If you need instant invalidation on content edits, this microcache approach isn’t a substitute for something like Varnish with BAN support; it’s meant as a lightweight buffer for anonymous traffic spikes.
  • Disk I/O: mod_cache_disk writes to local disk, so on multi-node/ECS-style deployments each container gets its own cache — there’s no shared cache state across tasks unless CacheRoot points at a shared volume (and even then, disk cache isn’t designed for concurrent multi-writer access).

That’s it — you’ve configured an Apache Microcache in front of Drupal.

Sunday, 7 June 2026

Drupal Admin Toolbar Missing Structure and Configuration After Core Upgrade [Solved]

Drupal admin menu management page showing Structure and Configuration menu items disabled after Drupal 10.3 core upgrade

After upgrading Drupal core from 10.2 to 10.3, many site admins notice that Structure and Configuration disappear from the admin toolbar. Even accessing /admin/structure directly returns a 403 Access Denied error. This is a known issue introduced in Drupal 10.3 and here is how to fix it.

What Causes This?

Drupal 10.3 tightened access evaluation on top-level admin routes. During the upgrade, disabled menu items inside the Administration menu cause Drupal to treat the Structure and Configuration parent routes as inaccessible — so they silently vanish from the toolbar.

The error you will see in the logs:

Path: /admin/structure
Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException:
in Drupal\Core\Routing\AccessAwareRouter->checkAccess()

Step 1 — Go to the Administration Menu

Navigate to the Administration menu edit page in your Drupal admin:

Administration → Structure → Menus → Administration

Or visit this URL directly on your site:

/admin/structure/menu/manage/admin

Step 2 — Delete the Menu Items

In the menu link list, look for the Structure and Configuration menu items. Look for the disabled Structure and Configuration menu items without any children menu items. Delete and save the menu.

Step 3 — Clear All Caches

After saving, clear all caches:

Administration → Configuration → Development → Performance → Clear all caches

Reload the page. Structure and Configuration should now reappear in the admin toolbar.

If the menus still do not appear, log out and log back in to refresh your session.

Quick Summary

Step Action
1 Go to /admin/structure/menu/manage/admin
2 Delete the Structure and Configuration menu items and save
3 Clear all caches and reload

Reference

D 10.3.0 update: Cannot access admin/structure and admin/config — Drupal.org

Friday, 29 May 2026

[Solved] Drupal Drush Forced Module Uninstall

Drupal Drush forced module uninstall error and fix

When working on a Drupal site, you may encounter situations where a module simply refuses to uninstall — either through the Drupal admin UI or via Drush. This guide shows you how to force uninstall a module using Drush and recover your site.

Quick Fix — Drush Forced Module Uninstall

Use the following Drush command to forcefully remove a module from Drupal's core extension configuration:

drush cdel core.extension module.your_module_name

Replace your_module_name with the actual machine name of the module. For example, to force uninstall CiviCRM:

drush cdel core.extension module.civicrm

After running the command, clear the cache:

drush cr

Why Does This Issue Occur?

There are several reasons why a module cannot be uninstalled through normal methods:

  • Module upgrade failure — An upgrade left the module in a broken state with unexpected dependencies
  • Residual configurations — Leftover config from a previously uninstalled module causes conflicts when re-enabled
  • Misconfiguration in settings.php — The module is referenced incorrectly in the settings file
  • Module enabled but not configured — The module is active in the database but missing its required settings
  • Missing settings file — For example, CiviCRM is enabled but civicrm.settings.php is not present

What Happens When This Occurs?

When a module gets stuck in this state:

  • Running drush pmu module_name throws an error
  • The Drupal Extend page shows an error or the uninstall button is greyed out
  • The entire site may go down with an unexpected error

The error from Drush typically looks like:

The module cannot be uninstalled due to [reason]

Step-by-Step Recovery Process

Step 1 — Force Uninstall the Module

drush cdel core.extension module.your_module_name

Step 2 — Clear Drupal Cache

drush cr

Step 3 — Check Site Status

drush status

Step 4 — Check Logs for Root Cause

# Check Drupal watchdog logs
drush ws --count=20

# Check PHP error logs
tail -f /var/log/php/error.log

Quick Summary

Step Command
Force uninstall module drush cdel core.extension module.module_name
Clear cache drush cr
Check site status drush status
View recent logs drush ws --count=20

This command directly removes the module entry from Drupal's configuration, bypassing the normal uninstall hooks. It gives you immediate relief to bring the site back online, after which you can investigate the root cause through Drupal logs, PHP error logs, and your configuration settings.