A robust, Docker-based local development workspace designed for PHP development. This setup orchestrates Nginx, PHP, MariaDB, PostgreSQL, and Redis services using Docker Compose.
This workspace includes the following services:
- Nginx:
nginx:stable- Web server listening on port80. - PHP: Custom build from
./docker/images/php- PHP FPM handler. - MariaDB:
mariadb:10.11-ubi- Database server exposed on port3306. - PostgreSQL:
postgres:16-alpine- Database server exposed on port5432. - Redis:
redis:latest- In-memory data structure store exposed on port6379.
.
├── compose.yml # Docker Compose configuration
├── docker/ # Docker images and volume configurations
│ ├── images/ # Dockerfiles for custom builds (e.g., PHP)
│ └── volumes/ # Configuration files mounted to containers
└── www/ # Web root directory (source code goes here)
- Docker
- Docker Compose
-
Clone the repository
git clone <repository-url> cd <repository-name>
-
Configure Environment Variables
Create a
.envfile in the root directory to define your secrets. The following variables are required bycompose.yml:MYSQL_ROOT_PASSWORD=secret MYSQL_ROOT_HOST=% POSTGRES_PASSWORD=secret
-
Start the Services
docker compose up -d
- Web Server: Place your PHP projects inside the
www/directory. Nginx is configured to serve from this location. Access your projects athttp://localhost. - Databases:
- MariaDB: Connect via
127.0.0.1:3306. - PostgreSQL: Connect via
127.0.0.1:5432. - To connect to databases in containers, use the database containers'
hostnamedeclared incompose.yml
- MariaDB: Connect via
- Redis: Connect via
127.0.0.1:6379.
- Nginx: Configuration files are located in
./docker/volumes/nginx/conf.d. - PHP: Custom
php.inisettings can be found in./docker/volumes/php/conf.d. - Data Persistence: Database data is persisted in named Docker volumes (
mariadb-dataandpostgres-data).
This setup is designed to work with dnsmasq to enable wildcard domain mapping. The Nginx configuration (docker/volumes/nginx/conf.d/test.conf) is set up to handle requests for *.test domains and map them to corresponding folders in the www/ directory.
For example, accessing http://project.test will serve files from www/project/public.
To use this feature:
-
Install and configure dnsmasq to resolve
*.testto127.0.0.1. -
Alternatively, add entries to your
/etc/hostsfile for each project:127.0.0.1 project.test 127.0.0.1 another-project.test