Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save asminog/08dc7aa5000475dd3fc806a0e4d5ac19 to your computer and use it in GitHub Desktop.
Save asminog/08dc7aa5000475dd3fc806a0e4d5ac19 to your computer and use it in GitHub Desktop.
Mac Docker PhpStorm Xdebug
FROM php:fpm
RUN apt-get update && apt-get install -y libicu-dev libmagickwand-dev libtidy-dev --no-install-recommends \
&& pecl install -o -f imagick redis xdebug \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable imagick redis xdebug \
&& docker-php-ext-install tidy intl pdo pdo_mysql opcache mysqli soap zip exif gd \
&& rm -r /var/lib/apt/lists/*
COPY conf/php-fpm/ /usr/local/etc/php-fpm.d/
COPY conf/php/ /usr/local/etc/php/
CMD ["php-fpm"]
# Use xdebug with docker-compose on macOS and PhpStorm
1. For your local dev, create a `Dockerfile` that is based on your production image and
simply install `xdebug` into it. Exemple:
```
FROM php:fpm
RUN apt-get update && apt-get install -y libicu-dev libmagickwand-dev libtidy-dev --no-install-recommends \
&& pecl install -o -f imagick redis xdebug \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable imagick redis xdebug \
&& docker-php-ext-install tidy intl pdo pdo_mysql opcache mysqli soap zip exif gd \
&& rm -r /var/lib/apt/lists/*
COPY conf/php-fpm/ /usr/local/etc/php-fpm.d/
COPY conf/php/ /usr/local/etc/php/
CMD ["php-fpm"]
```
2. Start your container with `docker-compose`:
```yaml
version: '3'
services:
web:
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./www:/www:cached
...
networks:
- my-network
php:
build: ./containers/phpfpm
volumes:
- ./www/test/data:/www/test/data:cached
- ./etc/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
networks:
- my-network
networks:
my-network:
```
3. In Intellij/PHPStorm go to: `Languages & Frameworks` > `PHP` > `Debug` > `DBGp Proxy` and set the following settings:
* `Host`: localhost
* `Port`: 9005
Then you're all set and can start listening for PHP Debug connections from your IDE. On the first run it will ask you to map
your local directoryies to the `docker` directories, but after that nothing will be required anymore!
Happy debugging!
FROM php:fpm
MAINTAINER asminog <asminog@asminog.com>
RUN apt-get update && apt-get install -y libicu-dev libmagickwand-dev libtidy-dev --no-install-recommends \
&& pecl install -o -f imagick redis xdebug \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable imagick redis xdebug \
&& docker-php-ext-install tidy intl pdo pdo_mysql opcache mysqli soap zip exif gd\
&& rm -r /var/lib/apt/lists/*
COPY conf/php-fpm/ /usr/local/etc/php-fpm.d/
COPY conf/php/ /usr/local/etc/php/
CMD ["php-fpm"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment