DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How to Deploy a Full Environment for a Wordpress Site via Docker by Using Terraform
  • When Airflow Tasks Get Stuck in Queued: A Real-World Debugging Story
  • The Evolution of Scalable and Resilient Container Infrastructure
  • Scaling Microservices With Docker and Kubernetes on Production

Trending

  • Software Delivery at Scale: Centralized Jenkins Pipeline for Optimal Efficiency
  • The Perfection Trap: Rethinking Parkinson's Law for Modern Engineering Teams
  • Advancing Robot Vision and Control
  • A Guide to Auto-Tagging and Lineage Tracking With OpenMetadata
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Setup Wordpress Debug Environment With Docker and Xdebug

Setup Wordpress Debug Environment With Docker and Xdebug

By 
Kunkka Li user avatar
Kunkka Li
·
Sep. 24, 20 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
11.2K Views

Join the DZone community and get the full member experience.

Join For Free

It's a common practice to debug PHP using Xdebug. Xdebug is an extension for PHP to assist with debugging and development. 

In this article, I'm going to introduce a more convenient way to quickly set up development environment with PHPStorm, Docker, Docker compose and Xdebug.  The source code for docker compose configs are available in the Github: https://github.com/liqili/wordpress-xdebug-docker/ 

First of all, suppose we have installed Docker and Docker compose in a Linux-like OS, and installed a Wordpress site in production. Then, what we need to do is to setup a development environment for that site so that we can customize plugins or what else. This post will help you learn how to:

  • Use Docker compose to mange docker containers.
  • Export production db to dev Mysql docker container.
  • Integrate Xdebug plugin with docker container as well as PHPStorm.
  • How to initialize MySQL container with sql script file. 

docker-compose.yml for container management

YAML
xxxxxxxxxx
1
33
 
1
version: "3"
2
3
services:
4
  mysql:
5
    image: mysql:5.7
6
    container_name: mysqldb
7
    ports:
8
      - "3306:3306"
9
    command: --max_allowed_packet=1073741824 --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
10
    environment:
11
      MYSQL_ROOT_PASSWORD: 123
12
      MYSQL_DATABASE: log
13
    volumes:
14
      - ./configs/db/:/docker-entrypoint-initdb.d # mysql will execute the initial sql script under the mount point one by one
15
      - db-data:/var/lib/mysql
16
  wordpress-app:
17
    build:
18
      ./configs/php/
19
    container_name: wordpress-app
20
    ports:
21
      - "80:80"
22
      - "443:443"
23
    restart: always
24
    environment:
25
      XDEBUG_CONFIG: "remote_host=host.docker.internal" #This config works for MacOS, otherwise should be ip address of the host machine because docker container cannot find the host by localhost.
26
    volumes:
27
      - ../local-wordpress:/var/www/html # mount your local wordpress site here
28
      - /tmp/wp-errors.log:/tmp/wp-errors.log
29
    depends_on:
30
      - mysql
31
32
volumes:
33
  db-data:

Customize Dockerfile for Apache Web Server

We need to download Xdebug source code and prepare a customized php.ini and dockerfile:

Download the specific version Xdebug source code according to your php version, in this post I'm using php7.4, so I use xdebug-2.9.6(https://xdebug.org/files/xdebug-2.9.6.tgz).

 Dockerfile for php apache web server(please modify php.ini and xdebug location accordingly):

Dockerfile
xxxxxxxxxx
1
19
 
1
FROM php:7.4-apache
2
COPY ./local/php.ini /usr/local/etc/php/php.ini
3
COPY ./xdebug-2.9.6 /app/xdebug
4
RUN apt-get update && apt-get install -y \
5
curl \
6
mariadb-client \
7
wget \
8
zlib1g-dev \
9
libzip-dev \
10
unzip \
11
libmemcached-dev zlib1g-dev \
12
&& docker-php-ext-install pdo pdo_mysql mysqli zip \
13
&& a2enmod rewrite \
14
&& cd /app/xdebug/ \
15
&& phpize \
16
&& ./configure \
17
&& make \
18
&& mkdir -p /usr/local/lib/php/extensions/no-debug-non-zts-20190902/ \
19
&& cp modules/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902/ \


Customize php.ini by adding the following lines to enable xdebug.

Plain Text
xxxxxxxxxx
1
 
1
xdebug.remote_enable=1
2
zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so

Configure your IDE(PHPStorm)

I get used to JetBeans IDEs, so I will only use PHPStorm to illustrate how to configure you IDE. For other IDEs, there are a lot of manuals available that can help with the Xdebug configuration. 

Xdebug configuration

Finally, we need to install browser debug toolbar. Once installed, configure the option to set IDE Key to PHPSTORM. 

IDE key


You will be all set.  Then you can start the docker containers and start debug in your IDE.

Shell
xxxxxxxxxx
1
 
1
docker-compose up --build //build and start up docker containers


Docker (software) Debug (command) WordPress

Opinions expressed by DZone contributors are their own.

Related

  • How to Deploy a Full Environment for a Wordpress Site via Docker by Using Terraform
  • When Airflow Tasks Get Stuck in Queued: A Real-World Debugging Story
  • The Evolution of Scalable and Resilient Container Infrastructure
  • Scaling Microservices With Docker and Kubernetes on Production

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!