Skip to content

Instantly share code, notes, and snippets.

@sophiaphillipa
Last active May 15, 2022 06:39
Show Gist options
  • Save sophiaphillipa/f08a1e21aaaff4fce752993c86f08427 to your computer and use it in GitHub Desktop.
Save sophiaphillipa/f08a1e21aaaff4fce752993c86f08427 to your computer and use it in GitHub Desktop.
Configuring PHPStorm to work with xDebug and Docker, by listening.

For this setup, I'm using PHP 7 FPM and Nginx

Also created a xdebug.ini, php.ini and vhost.conf as separated setup files, that are copy for volumes by docker compose.

  1. Docker image is just an example. You can use any other image, but should have xdebug extension.
  2. As Docker image, Docker yml is an example. If using Mac, port on docker compose have be mapped, on Linux, should skipe this step. You must have a separated xdeubg.ini file, setted up like this example. Pointed port on this file, must be the same on all port setup, steps.
  3. On xdebug.ini file change remote_host parameter, with your local machine ip address
  4. Apply all PhpStorm session settings, like screeshots.
  5. On PhpStorm Server Session, you are asked to point Host, this parameter must be the same as your nginx vhost, server name.
  6. Take the index file of you project (or the first running one) and place a breakpoint there.
  7. Start listening for php Connections on PhpStorm (there is a button besides VCS ones, to start listening, it's gonna be green on click)
  8. Back to your browser and refresh. On first launch, PhpStorm will ask you for script map, point your index file.
web:
image: nginx:stable
ports:
- "80:80"
- "9001:9001"
volumes:
- .:/var/www
- ./config/vhost.conf:/etc/nginx/conf.d/default.conf
links:
- php
php:
image: php7-xdebug
volumes:
- .:/var/www
- ./config/php.ini:/usr/local/etc/php/php.ini
- ./config/php-fpm.conf:/usr/local/etc/php/php-fpm.conf
- ./config/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
FROM php:7-fpm
RUN apt-get update && \
apt-get install -y \
zlib1g-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
RUN docker-php-ext-install pdo pdo_mysql zip mcrypt
RUN apt-get install -y unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www
server {
listen 80;
index index.php index.html;
server_name docker.dev;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www;
sendfile off;
client_max_body_size 7M;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_read_timeout 9000;
}
}
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
;xdebug.remote_handler=dbgp
#To activate XDEBUG remote host must be your local IP addres.
#This is not Docker machine ip address, but the ones runing Phpstorm
xdebug.remote_host=your_machine_local_ip_address
xdebug.remote_port=9001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment