DEV Community

Cover image for Docker Setup for Symfony 6.3.* Web Apps
Pham The Anh
Pham The Anh

Posted on • Updated on

Docker Setup for Symfony 6.3.* Web Apps

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:

  1. Nginx Web Server: A high-performance web server that ensures your Symfony app is served efficiently.
  2. 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.
  3. MySQL 8.0: A robust database management system to handle your app’s data needs.
  4. phpMyAdmin: A convenient web interface for database management.

A Step-by-Step Guide

  1. 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
    
  2. User ID and Environment Setup:
    Find your user ID using the id -u command and update the .docker/.env file accordingly. This step ensures that the containers run with the correct permissions.

  3. 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
    
  4. 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
    
  5. Accessing Your App:
    Your Symfony web app is now accessible at http://localhost, with phpMyAdmin available at http://localhost:8081.

Github repo

https://github.com/TOA-Anakin/symfony-webapp-docker-dev

Top comments (0)