This project provides a lightweight local LAMP environment using Docker Compose. It includes:
- Apache + PHP 8.3
- MariaDB 12
- phpMyAdmin
- A sample PHP page that connects to the database
The main goal is to enable fast local development of PHP applications without needing to install Apache, PHP, and MySQL/MariaDB directly on the host machine.
Note
This project was developed for learning purposes.
.
├── .github/
│ └── workflows/
│ ├── docker-release.yml
│ └── docker-syntax-checker.yml
├── public/
│ ├── index.php
│ └── info.php
├── .dockerignore
├── .env.example
├── .gitignore
├── docker-compose.yml
├── Dockerfile
├── README.md
└── README.es.md
| Service | Image / Base | Port | Purpose |
|---|---|---|---|
| web | custom image built from the Dockerfile | 80:80 | Apache web server for PHP files |
| db | mariadb:12 | internal only | MariaDB database |
| phpmyadmin | phpmyadmin/phpmyadmin:5.2 | 8080:80 | Database administration interface |
- PHP 8.3 with Apache 2
- Alpine Linux base image
- MariaDB database engine
- Docker Compose for orchestration
- Environment-variable-based configuration with
.env.example
Before you begin, make sure you have:
- Docker installed
- Docker Compose installed
- Ports 80 and 8080 available on your machine
This project uses environment variables to configure the application and the database.
- Copy the example file:
cp .env.example .env- Update the values in
.env:
ENV=
DB_ROOT_PASSWORD=
DB_USER=
DB_PASSWORD=
DB_DATABASE=The docker-compose.yml file uses these values for MariaDB and the web container, while the sample PHP page reads them through the environment at runtime.
- Clone or open the project folder:
git clone https://github.com/Akisolu/lamp-docker
cd lamp-docker- Start the containers:
docker compose up --build -d- Access the application:
- Web app: http://localhost
- phpMyAdmin: http://localhost:8080
The database is configured through the variables in your .env file (copy them from .env.example).
Use the values below for local development, or replace them with your own:
| Variable | Value | Description |
|---|---|---|
DB_ROOT_PASSWORD |
password |
MariaDB root password |
DB_USER |
lamp |
Application user |
DB_PASSWORD |
lamp |
Password for DB_USER |
DB_DATABASE |
mydatabase |
Database name |
Note: The host (
db) and port (3306) cannot be configured using this method.
They are fixed by the internal Docker network between containers.
These values are injected via environment variables in docker-compose.yml and then consumed by the sample PHP script in public/index.php.
The public/index.php file is a visual status dashboard that verifies the stack is working. It displays two cards:
- Web Server: Apache version, PHP version, and document root, with a running/online indicator.
- Database: connection status to MariaDB via PDO (engine, host, database name), showing a Connected or Disconnected badge with the error details if the connection fails.
This makes it easy to verify at a glance that:
- The Apache container is serving PHP correctly.
- The web and database containers can communicate over the internal network.
The page also includes quick links to phpMyAdmin and to info.php (full phpinfo() output).
Recent updates added a health check to the MariaDB container and improved service dependencies:
- The
webservice waits for the database to be healthy before starting. - The
dbservice runs a MariaDB readiness check usinghealthcheck.sh. - The
phpmyadminservice also waits fordbto be ready before starting.
This makes the startup sequence more reliable in Docker Compose.
Start the stack:
docker compose up -dStop the stack:
docker compose downView running containers:
docker compose psView logs:
docker compose logs -fRebuild the custom PHP image:
docker compose buildDatabase data is persisted using a Docker named volume:
volumes:
db-data:This ensures that MariaDB data remains available even if the container is restarted or recreated.
- The web root is mounted from
./public/into Apache's document root. - The custom Docker image installs the required PHP extensions, including support for MySQL/MariaDB.
- The Compose network
lamp-networkconnects the web and database services internally. - The project supports environment-variable configuration for database credentials and phpMyAdmin defaults.
Check whether the database container is running:
docker compose psThen inspect the logs:
docker compose logs dbConfirm that the values in .env match the credentials expected by the application and Docker Compose.
If port 80 or 8080 is already occupied, change the host port mapping in docker-compose.yml:
ports:
- "8081:80"Then use the new URL in your browser.