docker.recipes

LAPP Stack (Linux, Apache, PostgreSQL, PHP)

intermediate

LAPP stack for PHP applications with PostgreSQL.

Overview

Apache HTTP Server stands as the world's most widely-used web server software, powering over 30% of all websites globally since its release in 1995. Built from the original NCSA HTTPd server, Apache revolutionized web hosting with its modular architecture, robust security features, and cross-platform compatibility. Its mod_php module enables direct PHP processing within the Apache process, making it a natural choice for PHP-driven applications that require reliable performance and extensive configuration flexibility. This LAPP stack combines Apache's proven web serving capabilities with PHP 8.2's modern language features and PostgreSQL's advanced relational database engine. Unlike LAMP stacks that rely on MySQL, this configuration leverages PostgreSQL's superior JSON support, ACID compliance, and complex query capabilities, making it ideal for applications requiring both relational integrity and document-style data handling. The stack processes HTTP requests through Apache, executes PHP business logic with full access to PostgreSQL's advanced features like window functions, CTEs, and full-text search. Developers building content management systems, e-commerce platforms, or data-driven web applications will find this stack particularly valuable when their projects demand PostgreSQL's advanced features over MySQL's simpler approach. The inclusion of pgAdmin provides comprehensive database administration through a web interface, eliminating the need for separate database management tools and enabling efficient development workflows for teams working with complex PostgreSQL schemas and queries.

Key Features

  • Apache mod_php integration for high-performance PHP execution within the web server process
  • PostgreSQL 15 with advanced JSON/JSONB support for hybrid relational-document data models
  • pgAdmin 4 web interface with visual query builder and PostgreSQL-specific administration tools
  • PHP 8.2 with modern language features including union types, readonly properties, and match expressions
  • PostgreSQL full-text search capabilities with ranking and highlighting for content applications
  • Apache virtual host support for multi-domain configurations and flexible URL routing
  • PostgreSQL table partitioning and logical replication for scalable data architectures
  • pgAdmin dashboard statistics and query analysis tools for database performance optimization

Common Use Cases

  • 1E-commerce platforms requiring complex product catalogs with PostgreSQL's advanced indexing and JSON attributes
  • 2Content management systems leveraging PostgreSQL's full-text search and Apache's mod_rewrite for SEO-friendly URLs
  • 3Business intelligence dashboards utilizing PostgreSQL's window functions and Apache's reliable request handling
  • 4Multi-tenant SaaS applications using PostgreSQL's row-level security and Apache's virtual host configurations
  • 5GIS-enabled web applications combining PostGIS extensions with PHP mapping libraries
  • 6Data analytics platforms processing both structured PostgreSQL data and unstructured JSON documents
  • 7Legacy PHP application modernization projects migrating from MySQL to PostgreSQL's superior feature set

Prerequisites

  • Minimum 2GB RAM available (1GB for PostgreSQL, 512MB for pgAdmin, 512MB for Apache/PHP processes)
  • Docker Engine 20.10+ and Docker Compose V2 for proper container orchestration support
  • Ports 80 and 8080 available on host system for Apache and pgAdmin web interfaces
  • Basic understanding of PostgreSQL concepts like schemas, roles, and ACID transactions
  • Familiarity with Apache configuration files and PHP module management
  • Knowledge of environment variable configuration for database credentials and service settings

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 apache:
3 image: php:8.2-apache
4 container_name: lapp-apache
5 restart: unless-stopped
6 ports:
7 - "${APACHE_PORT:-80}:80"
8 volumes:
9 - ${APP_PATH:-./app}:/var/www/html
10 depends_on:
11 - postgres
12
13 postgres:
14 image: postgres:15-alpine
15 container_name: lapp-postgres
16 restart: unless-stopped
17 environment:
18 - POSTGRES_USER=${DB_USER}
19 - POSTGRES_PASSWORD=${DB_PASSWORD}
20 - POSTGRES_DB=${DB_NAME}
21 volumes:
22 - postgres_data:/var/lib/postgresql/data
23
24 pgadmin:
25 image: dpage/pgadmin4:latest
26 container_name: lapp-pgadmin
27 restart: unless-stopped
28 ports:
29 - "${PGADMIN_PORT:-8080}:80"
30 environment:
31 - PGADMIN_DEFAULT_EMAIL=${PGADMIN_EMAIL}
32 - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PASSWORD}
33 depends_on:
34 - postgres
35
36volumes:
37 postgres_data:

.env Template

.env
1# LAPP Stack
2APACHE_PORT=80
3APP_PATH=./app
4DB_USER=app
5DB_PASSWORD=app_password
6DB_NAME=app
7PGADMIN_PORT=8080
8PGADMIN_EMAIL=admin@example.com
9PGADMIN_PASSWORD=admin

Usage Notes

  1. 1App at http://localhost
  2. 2pgAdmin at http://localhost:8080
  3. 3Place PHP files in ./app
  4. 4PostgreSQL for database

Individual Services(3 services)

Copy individual services to mix and match with your existing compose files.

apache
apache:
  image: php:8.2-apache
  container_name: lapp-apache
  restart: unless-stopped
  ports:
    - ${APACHE_PORT:-80}:80
  volumes:
    - ${APP_PATH:-./app}:/var/www/html
  depends_on:
    - postgres
postgres
postgres:
  image: postgres:15-alpine
  container_name: lapp-postgres
  restart: unless-stopped
  environment:
    - POSTGRES_USER=${DB_USER}
    - POSTGRES_PASSWORD=${DB_PASSWORD}
    - POSTGRES_DB=${DB_NAME}
  volumes:
    - postgres_data:/var/lib/postgresql/data
pgadmin
pgadmin:
  image: dpage/pgadmin4:latest
  container_name: lapp-pgadmin
  restart: unless-stopped
  ports:
    - ${PGADMIN_PORT:-8080}:80
  environment:
    - PGADMIN_DEFAULT_EMAIL=${PGADMIN_EMAIL}
    - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PASSWORD}
  depends_on:
    - postgres

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 apache:
5 image: php:8.2-apache
6 container_name: lapp-apache
7 restart: unless-stopped
8 ports:
9 - "${APACHE_PORT:-80}:80"
10 volumes:
11 - ${APP_PATH:-./app}:/var/www/html
12 depends_on:
13 - postgres
14
15 postgres:
16 image: postgres:15-alpine
17 container_name: lapp-postgres
18 restart: unless-stopped
19 environment:
20 - POSTGRES_USER=${DB_USER}
21 - POSTGRES_PASSWORD=${DB_PASSWORD}
22 - POSTGRES_DB=${DB_NAME}
23 volumes:
24 - postgres_data:/var/lib/postgresql/data
25
26 pgadmin:
27 image: dpage/pgadmin4:latest
28 container_name: lapp-pgadmin
29 restart: unless-stopped
30 ports:
31 - "${PGADMIN_PORT:-8080}:80"
32 environment:
33 - PGADMIN_DEFAULT_EMAIL=${PGADMIN_EMAIL}
34 - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PASSWORD}
35 depends_on:
36 - postgres
37
38volumes:
39 postgres_data:
40EOF
41
42# 2. Create the .env file
43cat > .env << 'EOF'
44# LAPP Stack
45APACHE_PORT=80
46APP_PATH=./app
47DB_USER=app
48DB_PASSWORD=app_password
49DB_NAME=app
50PGADMIN_PORT=8080
51PGADMIN_EMAIL=admin@example.com
52PGADMIN_PASSWORD=admin
53EOF
54
55# 3. Start the services
56docker compose up -d
57
58# 4. View logs
59docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/apache-php-postgres-stack/run | bash

Troubleshooting

  • Apache returns 500 Internal Server Error: Check that PHP files have proper syntax and PostgreSQL connection credentials are correct in environment variables
  • pgAdmin shows 'server not found' error: Verify postgres container is running and use 'lapp-postgres' as hostname in pgAdmin server configuration
  • PostgreSQL connection refused from PHP: Ensure DB_USER, DB_PASSWORD, and DB_NAME environment variables match PostgreSQL container settings
  • Apache serves PHP files as plain text: Confirm php:8.2-apache image includes mod_php and .htaccess files don't override PHP handling
  • pgAdmin login fails with authentication error: Double-check PGADMIN_DEFAULT_EMAIL and PGLADMIN_DEFAULT_PASSWORD environment variables are properly set
  • PostgreSQL data disappears after container restart: Verify postgres_data volume is properly mounted and not being deleted during container recreation

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space