📚
Tech-Posts
  • README
  • Kafka + Maxwell
  • Kafka
  • Docker
  • MySQL connection via SSH
  • Python
    • Django
    • PyCharm+Docker Dev
    • Pip Tools
    • python project with local packages
  • PHP
    • PhpStorm+Docker Dev
  • Cassandra
  • AWS
    • Cheat Sheet
    • Lambda with Kinesis Event Source Mapping
  • AWS DMS
  • Lambda demo function to produce to Kinesis
  • Deploy a static web page with protection of specific static resources on AWS S3
  • Data Engineer
    • Move Salesforce Files out using Pentaho DI
  • A Pentaho DI Project Readme
  • PowerBI
    • Power BI refer to previous row
Powered by GitBook
On this page
  • My Typical Laravel Docker skeleton.
  • Remote Debug
  • Dockerfile should install xdebug
  • Also should enable and config xdebug in php.ini
  • Nginx Dockerfile config
  • docker-compose.yml
  • PHPStorm Config
  • Final Check

Was this helpful?

  1. PHP

PhpStorm+Docker Dev

Previouspython project with local packagesNextCassandra

Last updated 4 years ago

Was this helpful?

My Typical Laravel Docker skeleton.

Remote Debug

Dockerfile should install xdebug

docker-config/php/Dockerfile
FROM php:7.2-fpm
# ...
RUN pecl install xdebug

Also should enable and config xdebug in php.ini

This is Xdebug 2.x version settings:

docker-config/php/php.ini
[XDebug]
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so

xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM

xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.cli_color=1
xdebug.profiler_enable=0
xdebug.profiler_output_dir="~/xdebug/phpstorm/tmp/profiling"

xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_log="/var/www/xdebug_log/xdebug_docker.log"

This is Xdebug 3.x version settings:

docker-config/php/php.ini
[XDebug]
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.idekey=PHPSTORM
xdebug.client_host=host.docker.internal
xdebug.remote_handler=dbgp
xdebug.client_port=9000

;xdebug.remote_connect_back=0
;xdebug.cli_color=1
;xdebug.profiler_enable=0

Xdebug 3.x php.ini setting changed a lot compared to 2.x, check official guide:

https://xdebug.org/docs/upgrade_guide

also check stackoverflow post:

https://stackoverflow.com/questions/8049776/xdebug-for-remote-server-not-connecting

zend_extension part is IMPORTANT, do not use other solution.

Nginx Dockerfile config

should expose a correct port EXPOSE 8080

the port should match the docker-compose.yml -> nginx service's ports mapping (the external port)

docker-compose.yml

services:
    php-fpm:
        container_name: php-fpm
        build: ./docker-config/php
        restart: unless-stopped
        tty: true
        volumes:
            - ./src:/var/www
            - ./docker-config/php/php.ini:/usr/local/etc/php/php.ini
        working_dir: /var/www
        ports:
            - '9091:9000'
        environment:
            XDEBUG_CONFIG: "remote_host=host.docker.internal"
            PHP_IDE_CONFIG: "serverName=api_logix_crm-docker"

map local php.ini to docker container

also notice environment:

XDEBUG_CONFIG: "remote_host=host.docker.internal"
PHP_IDE_CONFIG: "serverName=api_logix_crm-docker"

PHP_IDE_CONFIG's serverName will be used in PHPStorm

PHPStorm Config

  • PHP interpreter

  • Language&Frameworks->PHP->Servers

Name MUST match docker-compose.yml -> php-fpm service -> environment -> PHP_IDE_CONFIG -> serverName

path mapping is important too, make sure local and remote (docker) path mapping is correct. Typically it can be refer to docker-compose.yml -> php-fpm service -> volumes

Final Check

docker-compose up,

set breakpoint, click "Start Listening to PHP Debug Connection", access web application or call api, see if it works.

GitHub - kingshark8848/My-Typical-Laravel-Development-Docker-ConfigGitHub
Logo
Lang->PHP->Servers