Skip to content

Complete symfony setup in docker with mysql support. Both filesystem and mysql are contained setup, meaning no data, code loss during development"

Notifications You must be signed in to change notification settings

deepyes02/symfony-docker-setup

Repository files navigation

Symfony 7.1, PHP 8.2 and mysql 8.0 with compose and symfony cli, ready for production

  1. copy .env.example to .env, this file is required by docker compose to setup database access

docker compose up -d
#or
docker compose up --build -d # to rebuild


##shut down
docker compose down

Volume Persistence

For local developement, db and filesystems persist via use of volume. Database lives in var/lib/mysql folder, THere's phpmyadmin included for Database UI if needed. So unless you delete the /var folder, your database is safe.

After docker compose up -d command

  1. Open browser http://localhost

  2. Access mysql via phpmyadmin http://localhost:3000 , see root user and password on .env file (no 1)

  3. Continue as you would on a normal symfony project

  4. Containers have been named for your convinience. Both symfony and composer reside in the container 'php'.

##command line
docker exec -it php /bin/bash
##ready for input
root@71e6cda46218:/var/www/html# 

#
composer 
##or
symfony 

Since this is a barebone symfony framework, here's two package we needed to install in order for the routing to work.

  1. Create server/config/routes/attributes.yaml and fill it up with the info
#config/routes/attributes.yaml
controllers:
  resource:
    path: ../../src/Controller
    namespace: App\Controller
  type: attribute

kernel:
  resource: App\Kernel
  type: attribute
  1. Controller server/src/Controller/BlogController.php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class BlogController{
	#[Route('/', name: 'home_page')]
	public function list(): Response {
		return new Response('<html>Hello world</html>');
	}
}
composer require symfony/framework-bundle symfony/routing

open the browser now :

alt text

Murky waters ahead, you are on your own

About

Complete symfony setup in docker with mysql support. Both filesystem and mysql are contained setup, meaning no data, code loss during development"

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published