Marinus Klasen

Marinus Klasen

  • Development
  • Consultancy
  • Developer Resources
  • Blog
  • Contact

September 29, 2022

Setting up xdebug and Webgrind in docker compose for in-depth PHP profiling

Marinus Klasen

Yep – it’s necessary. I really need to dig into that page load; what’s happening in this evironment and why? It’s time to setup xdebug and webgrind.

We’ll use the Geniem Oy’s images and repo for the foundation. I’m specifically interested in the webgrind service, and will add this to my docker-compose.yml file:

webgrind:
  image: devgeniem/webgrind
  ports:
    - 80
  volumes_from:
    - web

I will customize it a bit, so it fits my workflow, and I’ll make the UI available on port 8081;

  webgrind:
    image: devgeniem/webgrind
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik_proxy"
      - "traefik.http.routers.${NAME}-debug.rule=Host(`debug.schoolupdate.c7`)"
      - "traefik.http.routers.${NAME}-debug.tls=true"
    ports:
      - 443:80
    volumes:
      - ./debug:/tmp/xdebug

I then need to confirm or configure my own wordpress service and make the xdebug output dir is set. My WordPress service looks like this:

  wordpress:
    container_name: ${NAME}-wordpress
    user: "1000:1000"
    build:
      context: /home/mklasen/server-management/config/wordpress
      dockerfile: wordpress.Dockerfile
    depends_on:
      - db
    expose:
      - "9000"
    volumes:
      - /home/mklasen/server-management/config/php/default.conf:/usr/local/etc/php/conf.d/php.ini
      - ./:/var/www/
      - ./debug:/tmp/xdebug
    links:
      - db
    external_links:
      - catchall
    environment:
      PHP_AUTOCONF: /usr/bin/autoconf

and the xdebug part of my php.ini (not all settings here are relevant):

xdebug.client_host = localhost
xdebug.mode = debug,develop,profile,trace
xdebug.start_with_request = yes
xdebug.client_port = 9003
xdebug.idekey=VSCODE
xdebug.cli_color=2
xdebug.var_display_max_depth = 10
xdebug.var_display_max_children = 256
xdebug.var_display_max_data = 1024 
xdebug.output_dir=/tmp/xdebug

Alright, let’s move ahead and restart the docker compose environment with:

docker-compose stop && docker-compose up -d

Now, I did run into some issues like “NOTICE: PHP message: Xdebug: [Profiler] File ‘/tmp/xdebug/cachegrind.out.*’ could not be opened.”

This was related to the permissions the directory has. After running a chmod -R 777 debug on my docker volume folder, this was resolved.

Now, that’s all to really start understanding what’s going on in your PHP web applications,

Happy developing!

About Marinus Klasen

Marinus has been working in software/web development for more than a decade. Since 2020 his attention shifted on sharing knowledge and developing products and tools for sharing knowledge.

Marinus Klasen on Twitter

Looking for a WordPress expert?
Hire top notch developers on Codeable!

Consult an expert

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get in touch

Contact me using the details below

Marinus Klasen

Wilhelmina van Pruisenweg 35, 2595 AN Den Haag

marinus@mklasen.com
twitter.com/marinusklasen
linkedin.com/in/marinusklasen

  • GitHub
  • LinkedIn
  • Twitter

Have you read?

  • Elementor Widget UsageMarch 27, 2025
  • Programmatically showing popups with ElementorMarch 25, 2025
  • The Elementor sanitize_settings errorSeptember 12, 2024
  • Announcing.. Wooping Shop Health!June 13, 2024
  • Swiper setup when using wp-scriptsMarch 14, 2024

Copyright © 2025 ยท Marinus Klasen | Webdesign by Team Rood