Performance & DevOps 2026-11-01 ยท 6 min read

Drupal 11 on PHP 8.4: Cache Optimization, Security & Shared/Cloud Hosting Pitfalls

Carlos Del Hierro
Carlos Del Hierro
Senior Drupal 10/11 & AI Architect ยท 10+ years Drupal experience
Drupal 11 on PHP 8.4: Cache Optimization, Security & Shared/Cloud Hosting Pitfalls

Upgrading to Drupal 11.4 and PHP 8.4 brings noticeable improvements in memory usage, JIT compilation, and security. However, two subtle mistakes in custom code or server configuration can ruin both your performance and your login flow in production.

1. The #1 Anonymous Cache Killer in Custom Controllers

If you embed a form or a Webform inside a custom controller using getForm() directly without proper render caching, Drupal may attach max-age = 0 or session contexts, forcing X-Drupal-Cache: UNCACHEABLE on your homepage. Instead, render webforms via their lazy render element:

return [
  "#type" => "webform",
  "#webform" => "contacto",
];

Combined with page_cache_maximum_age: 3600 in system.performance, your anonymous pages will immediately return X-Drupal-Cache: HIT and Cache-Control: max-age=3600, public.

2. Fixing "Redirects to external URLs are not allowed by default" on Subdirectory Rewrites

On hosts where public_html/.htaccess rewrites requests into Composer's web/index.php, PHP populates $_SERVER["SCRIPT_NAME"] = "/web/index.php". Drupal's DrupalKernel::initializeRequestGlobals() then sets $base_url with a /web suffix while URL generators emit root URLs, causing login redirects to fail with TrustedRedirectResponse errors. Normalizing SCRIPT_NAME and PHP_SELF at the top of web/index.php before autoload_runtime.php solves it permanently.

#Drupal 11.4 #PHP 8.4 #Performance #Security #Cache

Want to implement this in your Drupal platform?

Have questions about this architecture, Drupal 11 + PHP 8.4, or AI/MCP workflows? Feel free to reach out and connect.