Skip to content

Setting up PHP and MySQL with Docker and XDEBUG enabled

Notifications You must be signed in to change notification settings

bingqiao/php-mysql-debug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP, MySQL, Docker and Debug

This is a small project to demo how to debug PHP in Visual Studio Code
against PHP/MySQL set up via Docker containers.

Build and Run

To build Docker images:

docker-compose build

To start containers:

docker-compose up

Use CTL+C to stop all containers, or run docker-compose down inside
project folder.

The Demo App

Navigate to http://localhost:6080 to show all the notes in DB.
There should be none initially. Go to http://localhost:6080/new-note.php
to add new note.

The launch.json under .vscode is for Visual Studio Code. This config
file allows you to debug the PHP code in this project. You may need to
install PHP Debug extension for VSC first.

A special hostname host.docker.internal is set in docker-compose.yml
for XDEBUG. This hostname works for Windows and MacOS but likely
not for Linux, for which You might need to use 172.17.0.1 or just your
local IP address.

Select Run -> Start Debugging in VSC, then set breakpoints in PHP files
and access them in browser to see breakpoints hit.

Caveat

  • The way MySQL is setup in Docker in this project is for development
    only. It's NOT secure!
  • To totally reset the database, you'll likely need to remove directory
    data before rebuilding Docker images with docker-compose build.

About

Setting up PHP and MySQL with Docker and XDEBUG enabled

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published