An Apache HTTP Server with PHP support running on Ubuntu 24.04 LTS inside a Docker container. The container automatically updates all packages to their latest versions on each deployment.
- Docker 20.10+
- Docker Compose v2.0+
.
├── Dockerfile # Container image definition
├── docker-compose.yml # Docker Compose configuration
├── entrypoint.sh # Startup script (runs apt-get upgrade before Apache)
├── config/
│ └── 000-default.conf # Apache virtual host configuration
├── html/ # Web root (mount point for site content, including PHP files)
└── README.md
-
Clone the repository and navigate to the project directory:
git clone <repository-url> cd webserver
-
Place your website files in the
html/directory (it will be created on first run). -
Build and start the container:
docker compose up -d
-
The webserver is now accessible at http://localhost.
Build the image:
docker build -t apache-webserver .Run the container:
docker run -d \
--name apache-webserver \
-p 80:80 \
-v $(pwd)/html:/var/www/html \
apache-webserverEach time the container starts, the entrypoint script runs apt-get upgrade before launching Apache. This ensures the container always runs the latest available package versions, including the most recent stable Apache release, without requiring an image rebuild.
⚠️ Important: Running package upgrades at container start introduces non-deterministic behaviour. Updates may include breaking changes or cause longer startup times. This approach is best suited for non-production environments. For production deployments, rebuild the image on a schedule, test it, and redeploy a known-good image instead.
To pick up the latest updates, simply restart the container:
docker compose restartOr redeploy with a fresh container:
docker compose down && docker compose up -dThe default virtual host configuration is located in config/000-default.conf. It:
- Serves files from
/var/www/html - Enables
AllowOverride Allso.htaccessfiles work - Enables
mod_rewrite,mod_headers, andmod_ssl
To customise the configuration, edit config/000-default.conf and rebuild the image:
docker compose up -d --buildPlace your HTML, CSS, JavaScript, PHP, and other site files in the html/ directory. They will be served at the root URL (http://localhost/).
For PHP websites, ensure your entry file is index.php (or explicitly request a .php file in the URL).
Quick PHP test file:
cat > html/info.php <<'EOF'
<?php phpinfo();
EOFThen open http://localhost/info.php.
Edit docker-compose.yml and update the ports mapping:
ports:
- "8080:80" # Expose on host port 8080 instead of 80Apache access and error logs are written inside the container to /var/log/apache2/. To view them:
docker compose logs webserverOr follow live:
docker compose logs -f webserver# Stop
docker compose stop
# Stop and remove containers
docker compose down
# Stop, remove containers, and remove the built image
docker compose down --rmi local| Component | Version |
|---|---|
| Base OS | Ubuntu 24.04 LTS (Noble Numbat) |
| Web Server | Apache 2.4 (latest stable from Ubuntu repos) |
| PHP Runtime | PHP (latest stable from Ubuntu repos) |
- Added PHP support to the container image (
libapache2-mod-php,php,php-cli). - Updated Apache vhost default index order to prefer
index.php. - Added
html/index.phpsample page for quick PHP verification. - Updated documentation to include PHP usage and testing guidance.