LAPP Stack (Linux, Apache, PostgreSQL, PHP)
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-apache4 container_name: lapp-apache5 restart: unless-stopped6 ports: 7 - "${APACHE_PORT:-80}:80"8 volumes: 9 - ${APP_PATH:-./app}:/var/www/html10 depends_on: 11 - postgres1213 postgres: 14 image: postgres:15-alpine15 container_name: lapp-postgres16 restart: unless-stopped17 environment: 18 - POSTGRES_USER=${DB_USER}19 - POSTGRES_PASSWORD=${DB_PASSWORD}20 - POSTGRES_DB=${DB_NAME}21 volumes: 22 - postgres_data:/var/lib/postgresql/data2324 pgadmin: 25 image: dpage/pgadmin4:latest26 container_name: lapp-pgadmin27 restart: unless-stopped28 ports: 29 - "${PGADMIN_PORT:-8080}:80"30 environment: 31 - PGADMIN_DEFAULT_EMAIL=${PGADMIN_EMAIL}32 - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PASSWORD}33 depends_on: 34 - postgres3536volumes: 37 postgres_data: .env Template
.env
1# LAPP Stack2APACHE_PORT=803APP_PATH=./app4DB_USER=app5DB_PASSWORD=app_password6DB_NAME=app7PGADMIN_PORT=80808PGADMIN_EMAIL=admin@example.com9PGADMIN_PASSWORD=adminUsage Notes
- 1App at http://localhost
- 2pgAdmin at http://localhost:8080
- 3Place PHP files in ./app
- 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 file2cat > docker-compose.yml << 'EOF'3services:4 apache:5 image: php:8.2-apache6 container_name: lapp-apache7 restart: unless-stopped8 ports:9 - "${APACHE_PORT:-80}:80"10 volumes:11 - ${APP_PATH:-./app}:/var/www/html12 depends_on:13 - postgres1415 postgres:16 image: postgres:15-alpine17 container_name: lapp-postgres18 restart: unless-stopped19 environment:20 - POSTGRES_USER=${DB_USER}21 - POSTGRES_PASSWORD=${DB_PASSWORD}22 - POSTGRES_DB=${DB_NAME}23 volumes:24 - postgres_data:/var/lib/postgresql/data2526 pgadmin:27 image: dpage/pgadmin4:latest28 container_name: lapp-pgadmin29 restart: unless-stopped30 ports:31 - "${PGADMIN_PORT:-8080}:80"32 environment:33 - PGADMIN_DEFAULT_EMAIL=${PGADMIN_EMAIL}34 - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PASSWORD}35 depends_on:36 - postgres3738volumes:39 postgres_data:40EOF4142# 2. Create the .env file43cat > .env << 'EOF'44# LAPP Stack45APACHE_PORT=8046APP_PATH=./app47DB_USER=app48DB_PASSWORD=app_password49DB_NAME=app50PGADMIN_PORT=808051PGADMIN_EMAIL=admin@example.com52PGADMIN_PASSWORD=admin53EOF5455# 3. Start the services56docker compose up -d5758# 4. View logs59docker compose logs -fOne-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 | bashTroubleshooting
- 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
Shortcuts: C CopyF FavoriteD Download