Docker compose environment for Symfony (also works for Laravel or plain PHP) projects
- PHP 8.2 with XDEBUG 3
- Apache2
- MySQL 8.0
- PhpMyAdmin - manage MySQL
- Mailhog - local mailing server
- Installs
composer
command - Virtualhost configuration dedicated for Symfony projects
- Docker and Docker Compose (Install docker compose)
- Makefile (Optional) (
sudo apt install make
)
cd to-your-project
git clone https://github.com/kasteckis/symfony-docker-compose.git
mv ./symfony-docker-compose/.docker ./.docker
mv ./symfony-docker-compose/Makefile ./Makefile
mv ./symfony-docker-compose/docker-compose.yml ./docker-compose.yml
mv ./symfony-docker-compose/docker-compose.xdebug.yml ./docker-compose.xdebug.yml
rm -rf ./symfony-docker-compose
docker compose up
By default you can access services via:
- Access your project website via - http://localhost/
- MySQL can be accessed via localhost:3306
- PhpMyAdmin can be accessed via http://localhost:81
- Mailhog can be accessed via http://localhost:8025/ (SMTP Port is 1025)
- Access docker apache-php terminal by writing -
docker exec -it project_web bash
(ormake ssh
)
If you use default IP addresses, append your .env
file with the following:
- For database connection -
DATABASE_URL=mysql://project:project@mysql:3306/project
- For mailing server -
MAILER_DSN=smtp://user:pass@mailhog:1025
(You can you any user and password)
- You can connect to your MySQL via
localhost:3306
- If you don't have any additional software, you can connect to database via phpmyadmin (http://localhost:81)
- Username:
project
- Password:
project
- Default table is called
project
- I use this configuration on
Windows 11
withWSL 2
- You cannot use same
container_name
for multiple projects. Make sure to change them, or you can just delete that optional argument fromdocker-compose.yml
file - You can't run multiple projects that allocate same ports on your localhost.
- If you can't compose a new project, you might need to delete your old docker networks. Type
docker network ls
and then remove your old project network by writingdocker network rm NETWORK_ID
(for exampledocker network rm 528d8c753c17
) cannot start service XXX: network YYY not found
. Open up container list withdocker container ls -a
and remove old containers withdocker container rm ID
.