Skip to content

Instantly share code, notes, and snippets.

@Zayon
Last active November 18, 2020 10:09
Show Gist options
  • Select an option

  • Save Zayon/f8c0a404a86ece1d6c909d4a36fc6d12 to your computer and use it in GitHub Desktop.

Select an option

Save Zayon/f8c0a404a86ece1d6c909d4a36fc6d12 to your computer and use it in GitHub Desktop.

Revisions

  1. Zayon revised this gist Jun 21, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ RUN apk add --no-cache $PHPIZE_DEPS \
    version: xx
    services:
    php-pfm:
    php-fpm:
    environment:
    XDEBUG_CONFIG: idekey=PHPSTORM remote_host=172.23.0.1 remote_port=10000
    ```
    @@ -54,7 +54,7 @@ endif
    version: xx
    services:
    php-pfm:
    php-fpm:
    volumes:
    - ./path/to/xdebug.ini:/usr/local/etc/php/conf.d/20-xdebug.ini.disabled
    environment:
  2. Zayon revised this gist Jun 21, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -56,7 +56,7 @@ version: xx
    services:
    php-pfm:
    volumes:
    - ./path/to/xdebug.ini:/usr/local/etc/php/conf.d/20-xdebug.ini.disabled
    - ./path/to/xdebug.ini:/usr/local/etc/php/conf.d/20-xdebug.ini.disabled
    environment:
    XDEBUG_CONFIG: idekey=PHPSTORM remote_host=172.23.0.1 remote_port=10000
    ```
  3. Zayon revised this gist Jun 21, 2020. 1 changed file with 67 additions and 0 deletions.
    67 changes: 67 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Xdebug with Docker

    ## With docker dev image

    *Dockerfile*
    ```
    FROM production as dev
    @@ -44,3 +46,68 @@ ifneq ($(CI), true)
    || (mv /usr/local/etc/php/conf.d/20-xdebug.ini /usr/local/etc/php/conf.d/20-xdebug.ini.disabled && kill -USR2 1)"
    endif
    ```

    ## Without docker dev image

    *docker-compose.override.yaml*
    ```docker-compose.override.yaml
    version: xx
    services:
    php-pfm:
    volumes:
    - ./path/to/xdebug.ini:/usr/local/etc/php/conf.d/20-xdebug.ini.disabled
    environment:
    XDEBUG_CONFIG: idekey=PHPSTORM remote_host=172.23.0.1 remote_port=10000
    ```

    Remote host is `host.docker.internal` on mac and windows.
    On linux use `docker inspect <container> | grep Gateway` to find the host ip.

    ```Makefile
    .PHONY: debug-start
    debug-start: ## Enable xdebug
    ifneq ($(CI), true)
    docker-compose exec -T -u root php-fpm sh -c "[ -e /usr/local/etc/php/conf.d/20-xdebug.ini ] && exit 0 \
    || (cp /usr/local/etc/php/conf.d/20-xdebug.ini.disabled /usr/local/etc/php/conf.d/20-xdebug.ini && kill -USR2 1)"
    endif

    .PHONY: debug-stop
    debug-stop: ## Disable xdebug
    ifneq ($(CI), true)
    docker-compose exec -T -u root php-fpm sh -c "[ -e /usr/local/etc/php/conf.d/20-xdebug.ini ] \
    && rm /usr/local/etc/php/conf.d/20-xdebug.ini && kill -USR2 1"
    endif
    ```

    Try it out:

    ```
    $ > docker-compose exec php-fpm php -v
    PHP 7.4.6 (cli) (built: May 15 2020 01:43:37) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    $ > make debug-start
    docker-compose exec -T -u root php-fpm sh -c "[ -e /usr/local/etc/php/conf.d/20-xdebug.ini ] && exit 0 \
    || (cp /usr/local/etc/php/conf.d/20-xdebug.ini.disabled /usr/local/etc/php/conf.d/20-xdebug.ini && kill -USR2 1)"
    $ > docker-compose exec php-fpm php -v
    PHP 7.4.6 (cli) (built: May 15 2020 01:43:37) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans
    $ > make debug-stop
    docker-compose exec -T -u root php-fpm sh -c "[ -e /usr/local/etc/php/conf.d/20-xdebug.ini ] \
    && rm /usr/local/etc/php/conf.d/20-xdebug.ini && kill -USR2 1"
    $ > docker-compose exec php-fpm php -v
    PHP 7.4.6 (cli) (built: May 15 2020 01:43:37) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    $ > make debug-start
    docker-compose exec -T -u root php-fpm sh -c "[ -e /usr/local/etc/php/conf.d/20-xdebug.ini ] && exit 0 \
    || (cp /usr/local/etc/php/conf.d/20-xdebug.ini.disabled /usr/local/etc/php/conf.d/20-xdebug.ini && kill -USR2 1)"
    $ > docker-compose exec php-fpm php -v
    PHP 7.4.6 (cli) (built: May 15 2020 01:43:37) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans
    ```
  4. Zayon revised this gist Jun 21, 2020. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -19,10 +19,11 @@ RUN apk add --no-cache $PHPIZE_DEPS \
    *docker-compose.override.yaml*
    ```docker-compose.override.yaml
    version: xx
    services:
    services:
    php-pfm:
    environment:
    XDEBUG_CONFIG: idekey=PHPSTORM remote_host=172.23.0.1 remote_port=10000
    environment:
    XDEBUG_CONFIG: idekey=PHPSTORM remote_host=172.23.0.1 remote_port=10000
    ```

    Remote host is `host.docker.internal` on mac and windows.
  5. Zayon created this gist Jun 21, 2020.
    45 changes: 45 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # Xdebug with Docker

    *Dockerfile*
    ```
    FROM production as dev
    USER root
    RUN apk add --no-cache $PHPIZE_DEPS \
    && pecl install xdebug-2.9.0 \
    && echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so" > /usr/local/etc/php/conf.d/20-xdebug.ini.disabled \
    && echo "xdebug.default_enable=1" >> /usr/local/etc/php/conf.d/20-xdebug.ini.disabled \
    && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/20-xdebug.ini.disabled \
    && echo "xdebug.remote_autostart=0" >> /usr/local/etc/php/conf.d/20-xdebug.ini.disabled \
    && echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/20-xdebug.ini.disabled \
    && echo "xdebug.profiler_enable=0" >> /usr/local/etc/php/conf.d/20-xdebug.ini.disabled
    ```

    *docker-compose.override.yaml*
    ```docker-compose.override.yaml
    version: xx
    services:
    php-pfm:
    environment:
    XDEBUG_CONFIG: idekey=PHPSTORM remote_host=172.23.0.1 remote_port=10000
    ```

    Remote host is `host.docker.internal` on mac and windows.
    On linux use `docker inspect <container> | grep Gateway` to find the host ip.

    ```Makefile
    .PHONY: debug-start
    debug-start: ## Enable xdebug
    ifneq ($(CI), true)
    docker-compose exec -T -u root php-fpm sh -c "[ -e /usr/local/etc/php/conf.d/20-xdebug.ini ] && exit 0 \
    || (mv /usr/local/etc/php/conf.d/20-xdebug.ini.disabled /usr/local/etc/php/conf.d/20-xdebug.ini && kill -USR2 1)"
    endif

    .PHONY: debug-stop
    debug-stop: ## Disable xdebug
    ifneq ($(CI), true)
    docker-compose exec -T -u root php-fpm sh -c "[ -e /usr/local/etc/php/conf.d/20-xdebug.ini.disabled ] && exit 0 \
    || (mv /usr/local/etc/php/conf.d/20-xdebug.ini /usr/local/etc/php/conf.d/20-xdebug.ini.disabled && kill -USR2 1)"
    endif
    ```