Run and develop your Symfony application locally with docker using combination of PHP/Apache or PHP-FPM/Nginx with Xdebug.
- PHP 8 / PHP-FPM
- Symfony 5+
- Xdebug
- Apache / Nginx
Table of Content
- Existing symfony application
- Start PHP Apache
- Start PHP-FPM Nginx
- Setup a new symfony application
- Shutdown/teardown
This setup works with both an existing and new symfony applications. Here is an expected project structure:
|- symfony-docker/
|- symfony_app/
|- php-apache/
|- php-nginx/
You only need one combination to start your development environment.
- Copy
php-apache
into your symfony app directory for PHP/Apache - Copy
php-nginx
into your symfony app directory for PHP-FPM/Nginx
Choose commands from following for relevant environment:
cd symfony-docker/
# Start PHP with Apache
docker-compose -f php-apache/docker-compose.yml up
# Rebuild docker image then start PHP with Apache
docker-compose -f php-apache/docker-compose.yml up --build
cd symfony-docker/
# Start PHP-FPM with Nginx
docker-compose -f php-nginx/docker-compose.yml up
# Rebuild docker image then start PHP-FPM with Nginx
docker-compose -f php-nginx/docker-compose.yml up --build
The symfony app will be available at http://localhost:8080
If you do not already have a symfony app then follow next section to create a new symfony app.
It's very easy to start a new symfony app.
Open a new terminal and install Symfony with following commands:
# it will create a new symfony app in `symfony_app` directory
docker exec symfony-docker bash -c "composer create-project symfony/skeleton:\"6.3.*\" ."
If you are building a web application then also run following:
docker exec symfony-docker bash -c "composer require webapp"
Refresh your browser at http://localhost:8080 to see symfony welcome page.
You can rename the
symfony_app
to whatever you like but make sure to update the references indocker-compose.yml
files.
You can only run one of the above combinations.
Use following command relevant to your development environment to shutdown/teardown:
# Shutdown/teardown PHP/Apache
docker-compose -f php-apache/docker-compose.yml down
# Shutdown/teardown PHP-FPM/Nginx
docker-compose -f php-nginx/docker-compose.yml down
MIT License © Jabran Rafique since 2017