For developers working with Symfony 6.3.*, the latest version of the renowned PHP framework as of 2023, setting up a robust and hassle-free environment is crucial. This is where Docker comes into play, offering a seamless setup for traditional Symfony web apps. Especially beneficial for those who prefer not to install multiple PHP versions and dependencies on their system, this Docker setup simplifies the development process significantly.
Key Components of the Setup
This Docker setup for Symfony 6.3.* includes everything you need to start building traditional web apps:
- Nginx Web Server: A high-performance web server that ensures your Symfony app is served efficiently.
- PHP 8.2 with Composer: The latest PHP version, equipped with Composer for managing PHP dependencies. The PHP container comes pre-loaded with all the necessary PHP extensions required by Symfony, eliminating the need for manual configuration.
- MySQL 8.0: A robust database management system to handle your app’s data needs.
- phpMyAdmin: A convenient web interface for database management.
A Step-by-Step Guide
-
Cloning and Renaming the Repository:
Clone the GitHub repository and rename it as desired. This repository serves as the foundation for your Symfony project.
$ git clone https://github.com/TOA-Anakin/symfony-webapp-docker-dev.git $ mv symfony-webapp-docker-dev your_project_name
User ID and Environment Setup:
Find your user ID using theid -u
command and update the.docker/.env
file accordingly. This step ensures that the containers run with the correct permissions.-
Building Docker Containers:
Navigate to the.docker
directory and build the Docker containers. This process sets up the entire environment needed for your Symfony app.
$ cd your_project_name/.docker $ docker compose up -d --build
-
Creating a Symfony Project:
Access the PHP container's terminal and use Composer to create a Symfony skeleton project. Then, move the contents to the project root and install the Symfony web app packages.
$ docker exec -it symfony_webapp_docker-php-1 bash $ composer create-project symfony/skeleton:"6.3.*" tmp_dir $ mv tmp_dir/* . && mv tmp_dir/.[!.]* . && rmdir tmp_dir $ composer require webapp
Accessing Your App:
Your Symfony web app is now accessible athttp://localhost
, with phpMyAdmin available athttp://localhost:8081
.
Top comments (0)