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

This site runs on Cloudways.
It's fast isn't it?
Cloudways offers high-quality, fast and affordable hosting.

Learn more

Need a hand? Post your project and hire me and other top notch developers on Codeable.

Hire me on Codeable

Leave a Reply Cancel reply

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

Ready to take action?

I'm looking forward to discuss your projects and goals!
Feel free to reach out using the contact details below.

Marinus Klasen

[email protected]
twitter.com/marinusklasen
linkedin.com/in/marinusklasen

  • GitHub
  • LinkedIn
  • Twitter

Have you read?

  • Storing private data with SSH on WPEngine sitesDecember 15, 2022
  • Get the HTML content of a block edit page or post in WordPressNovember 30, 2022
  • Rename Coupon code text to Discount code in WoocommerceNovember 3, 2022
  • Background-size cover in mPDFOctober 22, 2022
  • WordPress.com SSH & duplicating a WordPress.com website locallyOctober 11, 2022

Copyright © 2023 · Marinus Klasen | Webdesign by Team Rood