docker.recipes

Apache HTTP Server

beginner

Classic Apache web server with PHP support.

Overview

Apache HTTP Server, commonly known as Apache, is the world's most widely-used web server software, originally developed in 1995 and maintained by the Apache Software Foundation. Apache serves web pages to clients, handles HTTP requests, and supports numerous modules for extending functionality. Its modular architecture, robust performance, and extensive documentation have made it the backbone of millions of websites worldwide, from small personal sites to enterprise applications. This Docker configuration combines Apache HTTP Server 2.4 with PHP 8.3 in a single container, creating a classic LAMP stack foundation (minus the database). The php:8.3-apache image provides both the Apache web server and PHP interpreter, enabling dynamic web application development. Apache handles incoming HTTP requests and passes PHP scripts to the embedded PHP module for processing, returning generated HTML to browsers. The setup includes volume mounting for easy code deployment and custom Apache configuration management. Developers building PHP web applications, students learning web development, and system administrators needing a quick Apache deployment will find this stack invaluable. Small businesses hosting WordPress sites, agencies developing custom PHP applications, and DevOps teams creating development environments can deploy this configuration to get Apache with PHP support running immediately. The combination of Apache's reliability with PHP's versatility makes this suitable for everything from simple static sites with dynamic elements to complex web applications.

Key Features

  • Apache HTTP Server 2.4 with production-grade stability and security features
  • Integrated PHP 8.3 with modern language features and performance improvements
  • mod_rewrite support for URL rewriting and clean URLs in web applications
  • Virtual host configuration through custom Apache configuration files
  • Real-time code updates through volume mounting without container rebuilds
  • Apache module management with a2enmod and a2dismod commands
  • Built-in PHP error logging and Apache access logs for debugging
  • Support for .htaccess files for directory-level configuration overrides

Common Use Cases

  • 1WordPress and PHP CMS hosting for blogs and business websites
  • 2Legacy PHP application deployment and maintenance
  • 3Local development environment for PHP web applications
  • 4Educational web development projects and classroom environments
  • 5Small business websites requiring dynamic content generation
  • 6Prototype hosting for PHP-based web applications before production deployment
  • 7Testing Apache configuration changes in isolated containers

Prerequisites

  • Docker Engine 20.0+ and Docker Compose V2 installed
  • Port 80 available on host system (not used by other web servers)
  • Minimum 512MB RAM available for container operation
  • Basic understanding of Apache configuration and PHP development
  • Source code directory structure with PHP/HTML files ready for deployment

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.3-apache
4 container_name: apache
5 restart: unless-stopped
6 volumes:
7 - ./src:/var/www/html
8 - ./apache/000-default.conf:/etc/apache2/sites-available/000-default.conf:ro
9 ports:
10 - "80:80"
11 networks:
12 - apache-network
13
14networks:
15 apache-network:
16 driver: bridge

.env Template

.env
1# Apache configuration
2APACHE_RUN_USER=www-data
3APACHE_RUN_GROUP=www-data

Usage Notes

  1. 1Docs: https://httpd.apache.org/docs/2.4/
  2. 2Place PHP/HTML files in ./src directory - served at http://localhost:80
  3. 3Enable modules: docker exec apache a2enmod rewrite
  4. 4Custom VirtualHost in ./apache/000-default.conf
  5. 5PHP 8.3 included - add extensions via Dockerfile if needed
  6. 6Check config: docker exec apache apache2ctl configtest

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 apache:
5 image: php:8.3-apache
6 container_name: apache
7 restart: unless-stopped
8 volumes:
9 - ./src:/var/www/html
10 - ./apache/000-default.conf:/etc/apache2/sites-available/000-default.conf:ro
11 ports:
12 - "80:80"
13 networks:
14 - apache-network
15
16networks:
17 apache-network:
18 driver: bridge
19EOF
20
21# 2. Create the .env file
22cat > .env << 'EOF'
23# Apache configuration
24APACHE_RUN_USER=www-data
25APACHE_RUN_GROUP=www-data
26EOF
27
28# 3. Start the services
29docker compose up -d
30
31# 4. View logs
32docker 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-httpd/run | bash

Troubleshooting

  • 403 Forbidden errors: Check file permissions in ./src directory, ensure files are readable by www-data user
  • PHP scripts downloading instead of executing: Verify PHP module is loaded with 'docker exec apache php -m'
  • Apache won't start with custom config: Run 'docker exec apache apache2ctl configtest' to validate configuration syntax
  • Changes not reflected in browser: Clear browser cache and check volume mount path matches container expectations
  • Container exits immediately: Check Docker logs for Apache configuration errors or port conflicts
  • Internal Server Error 500: Enable PHP error reporting and check both Apache error logs and PHP error logs in container

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