Skip to content

Commit 076a6d9

Browse files
committed
Enable xDebug usage for Symfony commands and remove unnecessary extra symfony service - use php container for Composer/Symfony commands
1 parent a4960c9 commit 076a6d9

File tree

7 files changed

+32
-32
lines changed

7 files changed

+32
-32
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.env
2-
symfony/composer_cache/**
2+
composer_cache/**

README.md

+21-5
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,33 @@
1414

1515
### Running commands
1616

17-
Symfony commands can be run using the symfony container, e.g.
17+
Symfony commands can be run from the **php** container, e.g.
1818

19-
`docker-compose run symfony bin/console debug:router`
19+
```
20+
docker-compose run php bin/console app:my_command
21+
```
2022

21-
It will save time if you set up an alias within your shell for `docker-compose run symfony bin/console`.
23+
It will save time if you set up an alias within your shell for `docker-compose run php bin/console`.
24+
25+
To enable xDebug step-debugging within commands, you need to set the *xdebug.remote_host* PHP directive - on the command line like so:
26+
27+
```
28+
docker-compose run php php -dxdebug.remote_host=192.168.1.2 bin/console app:my_command
29+
```
30+
31+
Replace *192.168.1.2* with your **host** machine's local network IP. I have a bash alias set up for running commands that does this automatically:
32+
33+
```
34+
alias dcrs="docker-compose run php php -dxdebug.remote_host=$(ip route get 192.168.1.1 | awk '{print $NF; exit}') bin/console"
35+
```
36+
37+
Replace *192.168.1.1* with your local network's gateway, or *8.8.8.8*.
2238

2339
### Using Composer
2440

25-
Composer commands can be run within the symfony container:
41+
Composer commands can be run within the **php** container:
2642

27-
`docker-compose run symfony composer *command*`
43+
`docker-compose run php composer *command*`
2844

2945
### Using other services
3046

docker-compose.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ services:
77
volumes:
88
- ${APP_PATH}:/var/www/symfony
99
working_dir: /var/www/symfony
10-
php-fpm:
10+
php:
1111
build: php-fpm
1212
volumes:
1313
- ${APP_PATH}:/var/www/symfony
14-
symfony:
15-
build: symfony
16-
user: "1000"
17-
volumes:
18-
- ${APP_PATH}:/var/www/symfony
19-
- ./symfony/composer_cache:/var/www/.composer/cache
14+
- ./composer_cache:/var/www/.composer/cache
15+
environment:
16+
- PHP_IDE_CONFIG=serverName=symfony.dev # Replace symfony.dev with the server name you've created in your IDE
2017
mariadb:
2118
image: mariadb:10.3
2219
environment:

nginx/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ADD symfony.conf /etc/nginx/sites-available/
1111
RUN ln -s /etc/nginx/sites-available/symfony.conf /etc/nginx/sites-enabled/symfony
1212
RUN rm /etc/nginx/sites-enabled/default
1313

14-
RUN echo "upstream php-upstream { server php-fpm:9000; }" > /etc/nginx/conf.d/upstream.conf
14+
RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf
1515

1616
RUN usermod -u 1000 www-data
1717

php-fpm/Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ RUN echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebu
1818
RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
1919
RUN echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
2020
RUN echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
21-
RUN echo "xdebug.remote_log='/var/log/xdebug_remote.log'" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
21+
22+
# install composer
23+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
2224

2325
RUN usermod -u 1000 www-data
26+
USER 1000
27+
WORKDIR /var/www/symfony

symfony/Dockerfile

-17
This file was deleted.

symfony/composer_cache/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)