title: Debug PHP with VSCode and Docker
body: <p>I'm trying to debug a PHP app running on Docker with VSCode, but without success.</p>
  <p>In the past I was able to easily debug my PHP apps with VSCode running WAMP Server, but since I started working with Docker I'm unable to get debug working. Searched for several tutorials online, checked some threads here on StackOverflow (ex.: <a href="https://stackoverflow.com/a/43365142/1880662">Docker and XDebug not reading breakpoints VSCode</a>), but I'm still not able to get this working.</p>
  <p>Dockerfile:</p>
  <pre><code>FROM php:7.1.8-apache
  
  COPY /cms /srv/app/cms
  COPY .docker/cms/vhosts/vhost.conf /etc/apache2/sites-available/cms.conf
  COPY .docker/cms/vhosts/vhost-ssl.conf /etc/apache2/sites-available/cms-ssl.conf
  COPY .docker/cms/vhosts/certificate.conf /etc/ssl/certs/certificate.conf
  COPY .docker/cms/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
  
  WORKDIR /srv/app/cms
  
  RUN docker-php-ext-install mbstring pdo pdo_mysql
  RUN pecl install xdebug 
  RUN docker-php-ext-enable xdebug
  RUN chown -R www-data:www-data /srv/app/cms
  RUN openssl req -x509 -new -out /etc/ssl/certs/ssl-cert-cms.crt -config /etc/ssl/certs/certificate.conf
  RUN a2ensite cms.conf
  RUN a2ensite cms-ssl.conf
  RUN a2enmod rewrite
  RUN a2enmod ssl
  </code></pre>
  <p>xdebug.ini</p>
  <pre><code>[xdebug]
  xdebug.default_enable=1
  xdebug.remote_enable=1
  xdebug.remote_port=9000
  xdebug.remote_connect_back=0
  xdebug.remote_host='host.docker.internal'
  xdebug.idekey='VSCODE'
  xdebug.remote_autostart=1
  </code></pre>
  <p>docker-compose.yml</p>
  <pre><code>version: '3.7'
  services:
  cms:
    build:
      context: .
      dockerfile: .docker/cms/Dockerfile
    image: php:7.1.8-apache
    ports:
      - 18080:80
      - 14430:443
    volumes:
      - ./cms:/srv/app/cms
    links:
      - mysql
      - redis
    environment:
      DB_HOST: mysql
      VIRTUAL_HOST: my.app.localhost
      PHP_EXTENSION_XDEBUG: 1
  </code></pre>
  <p>VSCode: launch.json</p>
  <pre><code>&quot;configurations&quot;: [
      {
          &quot;name&quot;: &quot;Listen for XDebug&quot;,
          &quot;type&quot;: &quot;php&quot;,
          &quot;request&quot;: &quot;launch&quot;,
          &quot;pathMappings&quot;: {
             &quot;/srv/app/cms&quot;: &quot;${workspaceRoot}/my.app/cms&quot;,
          },
          &quot;port&quot;: 9000
      }, {
          &quot;name&quot;: &quot;Launch currently open script&quot;,
          &quot;type&quot;: &quot;php&quot;,
          &quot;request&quot;: &quot;launch&quot;,
          &quot;program&quot;: &quot;${file}&quot;,
          &quot;cwd&quot;: &quot;${fileDirname}&quot;,
          &quot;port&quot;: 9000
      }
  ]
  </code></pre>
  <p>When I debug the app no breakpoint is being triggered. What am I doing wrong?</p>
  <p><strong>UPDATE:</strong>
  Based on some suggestions i've updated my docker-compose.yml and my launch.json files but nothing changed.</p>
  <p>docker-compose.yml</p>
  <pre><code>ports:
    - 18080:80
    - 14430:443
    - 9000:9000 //added new xdebug default port
  </code></pre>
  <p>launch.json</p>
  <pre><code>&quot;configurations&quot;: [
      {
          &quot;name&quot;: &quot;Listen for XDebug&quot;,
          &quot;type&quot;: &quot;php&quot;,
          &quot;request&quot;: &quot;launch&quot;,
          &quot;pathMappings&quot;: {
             &quot;/srv/app/cms&quot;: &quot;${workspaceRoot}/my.app/cms&quot;,
          },
          &quot;port&quot;: 9000,
          &quot;log&quot;: true
      }
  ]
  </code></pre>
  <p>VSCode Debug Console:</p>
  <pre><code>&lt;- launchResponse
  Response {
  seq: 0,
  type: 'response',
  request_seq: 2,
  command: 'launch',
  success: true }
  </code></pre>
  <p><strong>UPDATE #2:</strong>
  Removed the Xdebug port (9000) from the docker-compose.yml settings. Here is the xdebug log result:</p>
  <blockquote>
  <p>Log opened at 2018-09-30 22:21:09 I: Connecting to configured
  address/port: host.docker.internal:9000. E: Time-out connecting to
  client (Waited: 200 ms). :-( Log closed at 2018-09-30 22:21:09</p>
  <p>Log opened at 2018-09-30 22:21:17 I: Connecting to configured
  address/port: host.docker.internal:9000. E: Time-out connecting to
  client (Waited: 200 ms). :-( Log closed at 2018-09-30 22:21:17</p>
  <p>Log opened at 2018-09-30 22:21:18 I: Connecting to configured
  address/port: host.docker.internal:9000. E: Time-out connecting to
  client (Waited: 200 ms). :-( Log closed at 2018-09-30 22:21:18</p>
  <p>Log opened at 2018-09-30 22:21:18 I: Connecting to configured
  address/port: host.docker.internal:9000. E: Time-out connecting to
  client (Waited: 200 ms). :-( Log closed at 2018-09-30 22:21:18</p>
  </blockquote>
  <p>Any more suggestions?</p>