This repository provides a robust and easy-to-use Docker-based development environment for Symfony applications. It's designed to streamline your local setup, ensuring consistency across different development machines and making onboarding new team members a breeze.
- Isolated Environment: All services (Nginx, PHP-FPM, MySQL, Redis, MailHog, phpMyAdmin, Workspace) run in their own Docker containers.
- Fast Development: Utilizes Docker volumes for real-time code synchronization and leverages PHP-FPM for efficient PHP execution.
- Local Domain: Access your application via a consistent port (default
8080
). - Debugging Ready: Pre-configured for Xdebug integration with your IDE (e.g., PhpStorm).
- Database Management: Includes MySQL with a persistent volume and phpMyAdmin for easy database access.
- Email Testing: MailHog for catching and viewing outgoing emails during development.
- Composer & Symfony CLI: A dedicated
symfony-workspace
container for running Composer commands, Symfony CLI, and other development tools. - Makefile Shortcuts: Convenient
make
commands to manage your Docker services and common development tasks.
Before you begin, ensure you have the following installed on your machine:
-
Clone the repository:
git clone https://github.com/manzolo/symfony-docker-dev-template.git cd symfony-docker-dev-template mkdir -p var/cache var/log make build # Build the Docker images (if not already built) make start # Start all services in the background
Enter the symfony-workspace container and install your project's Composer dependencies:
make enter # Access the workspace container's bash shell composer install # Install PHP dependencies exit # Exit the container make restart
Check your
.env
and.env.dev
respectively. Update the variables as needed, especially for your database connection (.env
). -
Access Your Application: Your Symfony application should now be accessible at
http://localhost:8080
.
This template includes a Makefile
with convenient shortcuts for managing your development environment:
make **build**
: Builds the Docker images. Useful after changes to Dockerfiles.make **start**
: Starts all Docker services in detached mode (-d
).make **stop**
: Stops and removes all Docker containers.make **status**
: Shows the status of all Docker services.make **logs**
: Displays real-time logs from all services. PressCtrl+C
to exit.make **enter**
: Enters thesymfony-workspace
container's bash shell. Use this for running Composer, Symfony Console, or other commands.make **root**
: Enters thesymfony-workspace
container as the root user. Use with caution.make **test-mail**
: Sends a test email via the Mailer to check MailHog setup.make **backupdb**
: Creates a database backup (.sql
file) in thevar/
directory on your host machine.make **restoredb**
: Restores the database fromvar/db_backup.sql
. Make surevar/db_backup.sql
exists and contains your desired backup!
- Symfony Application:
http://localhost:8080
(orhttp://localhost:${SYMFONY_NGINX_PORT}
if changed in.env
) - phpMyAdmin:
http://localhost:8088
(orhttp://localhost:${PHPMYADMIN_PORT}
if changed in.env
) - MailHog:
http://localhost:8025
(orhttp://localhost:${MAILHOG_WEB_PORT}
if changed in.env
)
.env
: Contains core application environment variables..env.dev
: Contains development-specific Docker Compose variables and Xdebug settings.docker/development/nginx/nginx.conf
: Nginx configuration for serving your Symfony application from thepublic/
directory and proxying to PHP-FPM. Ensure this is correctly configured for Symfony.docker/common/php-fpm/Dockerfile
: Defines the PHP-FPM container, including PHP extensions and user permissions.docker/development/workspace/Dockerfile
: Defines the workspace container, including development tools.
Xdebug is pre-configured to connect back to your host machine.
- Ensure
XDEBUG_ENABLED=true
in your.env.dev
file. XDEBUG_HOST
: By default, it's set tohost.docker.internal
, which works on Docker Desktop (macOS/Windows) and recent Docker versions on Linux. If you experience issues, consult Docker's networking documentation for your specific setup.- IDE Configuration: Configure your IDE (e.g., PhpStorm) to listen for Xdebug connections on port
9003
(or the port specified in your PHP-FPM configuration, if different from default) and ensure your project's path mappings are correct (host path.
to container path/var/www
).