Skip to content

Run and develop your Symfony application locally with docker using combination of PHP/Apache or PHP-FPM/Nginx with Xdebug.

License

Notifications You must be signed in to change notification settings

jabranr/symfony-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 Cannot retrieve latest commit at this time.

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

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

Prerequisites

Setup

Table of Content

  1. Existing symfony application
  2. Start PHP Apache
  3. Start PHP-FPM Nginx
  4. Setup a new symfony application
  5. Shutdown/teardown

Existing symfony application

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:

PHP Apache

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

PHP-FPM Nginx

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.

New symfony application

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 in docker-compose.yml files.

image

You can only run one of the above combinations.

Shutdown/teardown

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

About

Run and develop your Symfony application locally with docker using combination of PHP/Apache or PHP-FPM/Nginx with Xdebug.

Topics

Resources

License

Stars

Watchers

Forks