Work
Travel
Various
Emulating an Apache + PHP server locally
Docker Compose can spin up a local Apache + PHP server without installing anything on the host. This is useful for developing and testing PHP pages before deploying them.
docker-compose.yml
Place this file in the directory you want to serve:
services:
web:
image: php:8.3-apache
ports:
- "8080:80"
volumes:
- .:/var/www/html
The volume mount .:/var/www/html maps the current directory to the Apache document root,
so every file in that directory is immediately available without rebuilding.
To serve a subdirectory (e.g. web_portal/) instead, change the volume to:
- ./web_portal:/var/www/html
Starting and stopping
From the directory containing docker-compose.yml:
docker compose up -d
Stop and remove the container:
docker compose down
Accessing the server
Open a browser and navigate to:
http://localhost:8080/<filename>.php
For example, if docker-compose.yml mounts ./web_portal and that directory contains type1.php:
http://localhost:8080/type1.php
Useful commands
Tail the Apache error log while a page is loading:
docker compose logs -f
Open a shell inside the container:
docker compose exec web bash