# Drupal

> Enterprise-grade CMS for complex websites and applications.

- Category: CMS & Blogging
- Difficulty: intermediate
- Components: drupal, postgres
- Tags: drupal, cms, enterprise, php
- Source: https://docker.recipes/cms/drupal

## Overview

Drupal is an enterprise-grade content management system (CMS) built on PHP that has powered millions of websites since 2001. Known for its flexibility, security, and scalability, Drupal excels at managing complex content structures with advanced user permissions, multilingual capabilities, and extensive customization options. Unlike simpler CMS platforms, Drupal is designed for organizations that need sophisticated content workflows, enterprise integrations, and the ability to handle high-traffic applications with complex data relationships.

This stack combines Drupal 10 with PostgreSQL 16 to create a robust content management platform optimized for enterprise requirements. PostgreSQL's ACID compliance and advanced querying capabilities complement Drupal's complex content modeling needs, providing superior data integrity compared to MySQL setups. The combination excels at handling structured content with relationships, supporting Drupal's entity system and field API while delivering the performance needed for high-traffic sites with complex queries.

This configuration is ideal for organizations building sophisticated web applications, corporate intranets, educational platforms, or government websites that require enterprise-level security, scalability, and content management features. The PostgreSQL backend provides the reliability and performance needed for Drupal's advanced features like Views, Entity API, and custom content types, making it perfect for developers who need to build complex, data-driven websites with professional-grade infrastructure.

## Features

- Drupal 10 with modern Symfony-based architecture and Twig templating engine
- PostgreSQL 16 with JSON/JSONB support for Drupal's configuration and field storage
- Apache web server with mod_rewrite enabled for clean URLs and .htaccess support
- Persistent volumes for modules, themes, profiles, and sites directories to survive container updates
- Entity-relationship modeling with PostgreSQL's advanced constraint and indexing capabilities
- Full-text search integration using PostgreSQL's built-in search features with Drupal's Search API
- Composer-ready environment for installing Drupal modules and themes via Packagist
- Database connection pooling and transaction support optimized for Drupal's entity system

## Use cases

- Corporate websites with complex content hierarchies and multiple content types
- Educational institutions requiring multilingual content and user role management
- Government portals with strict accessibility and security compliance requirements
- Publishing platforms with editorial workflows and content scheduling
- E-commerce sites using Drupal Commerce with complex product catalogs
- Community portals with user-generated content and social features
- Intranet applications with document management and employee directories

## Prerequisites

- Minimum 2GB RAM recommended for Drupal and PostgreSQL combined workload
- Basic understanding of PHP, Drupal architecture, and content management concepts
- Familiarity with Drupal's admin interface and module/theme management
- Port 8080 available for web access to the Drupal installation
- Environment variable POSTGRES_PASSWORD configured in .env file
- Understanding of PostgreSQL connection parameters for Drupal database configuration

## docker-compose.yml

```yaml
services:
  drupal:
    image: drupal:10-apache
    container_name: drupal
    restart: unless-stopped
    volumes:
      - drupal_modules:/var/www/html/modules
      - drupal_profiles:/var/www/html/profiles
      - drupal_themes:/var/www/html/themes
      - drupal_sites:/var/www/html/sites
    ports:
      - "8080:80"
    depends_on:
      - postgres
    networks:
      - drupal-network

  postgres:
    image: postgres:16-alpine
    container_name: drupal-postgres
    environment:
      POSTGRES_DB: drupal
      POSTGRES_USER: drupal
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - drupal-network

volumes:
  drupal_modules:
  drupal_profiles:
  drupal_themes:
  drupal_sites:
  postgres_data:

networks:
  drupal-network:
    driver: bridge
```

## .env

```bash
POSTGRES_PASSWORD=changeme
```

## Usage notes

- Docs: https://www.drupal.org/docs
- Access at http://localhost:8080 - complete installation wizard
- Database host: postgres, database: drupal, user: drupal
- Install Drush CLI: composer require drush/drush
- Modules/themes persist in mounted volumes across updates
- Strong ecosystem for enterprise sites, multilingual, accessibility

## Troubleshooting

- Database connection failed during installation: Verify postgres container is running and use 'postgres' as database host, not 'localhost'
- Permission denied errors on file uploads: Check that www-data user has write permissions to sites/default/files directory
- Memory limit exceeded errors: Increase PHP memory_limit in custom php.ini or switch to drupal:10-fpm-alpine for better memory management
- Clean URLs not working: Ensure Apache mod_rewrite is enabled and .htaccess files are being processed
- Drupal installation stalls at database setup: Increase PHP max_execution_time and ensure PostgreSQL has sufficient shared_buffers allocated
- Module installation fails: Mount a custom sites/default/settings.php with proper database credentials and trusted host patterns configured

