paint-brush
How To Debug PHP Container With Xdebug And PhpStormby@ifomin
34,507 reads
34,507 reads

How To Debug PHP Container With Xdebug And PhpStorm

by Igor Fomin
Igor Fomin HackerNoon profile picture

Igor Fomin

@ifomin

Full stack web developer, tech lead, project manager

May 20th, 2020
Read on Terminal Reader
Read this story in a terminal
Print this story
Read this story w/o Javascript
Read this story w/o Javascript

Too Long; Didn't Read

How To Debug PHP Container With Xdebug And PhpStorm And Dockerfile. I will setup a very simple PHP page and debug it using xdebug and Phpstorm. I can set a breakpoint, start listening for connections in Php storm. I then reload page and see results from index.php file. I use "glyglyglyph" and "glyphglyphph" to set breakpoint and listen for connections. I am a full stack web developer, tech lead, project manager by Igor Fomin.
featured image - How To Debug PHP Container With Xdebug And PhpStorm
1x
Read by Dr. One voice-avatar

Listen to this story

Igor Fomin HackerNoon profile picture
Igor Fomin

Igor Fomin

@ifomin

Full stack web developer, tech lead, project manager

About @ifomin
LEARN MORE ABOUT @IFOMIN'S
EXPERTISE AND PLACE ON THE INTERNET.

I will setup a very simple php page and debug it using xdebug and PhpStorm.

Source files can be found here:

https://github.com/ikknd/docker-study in folder recipe-09

1. Create "Dockerfile" file in "docker" folder:

Execute this command from docker folder to build image:

docker build -t php-xdebug-custom -f Dockerfile .

2. Create docker-compose.yml file in "docker" folder:

Here I use "

php-xdebug-custom
" image instead of "
php:7.2-fpm
"

3. Modify php.ini file with xdebug settings:

4. Configure server in PhpStorm:

File -> Settings -> Languages & Frameworks -> PHP -> Servers

Add a new server using + icon, and configure like on the following screenshot:

image

Make sure to check "Use path mappings" and map php folder to "

/var/www/myapp
"

5. Configure PHP remote debugger in PhpStorm:

Run -> Edit configurations -> PHP Remote Debug

Add a new configuration and give it values like on the following screenshot:

image

6. Select debug configuration in PhpStorm debug panel

image

7. Go to /var/www/docker-study.loc/recipe-09/docker/ and execute:

docker-compose up -d

If I now try

myapp.loc/
in browser, I will see results from index.php file.

I can set a breakpoint, start listening for connections in PhpStorm debug panel, and reload page.

Happy debugging!

L O A D I N G
. . . comments & more!

About Author

Igor Fomin HackerNoon profile picture
Igor Fomin@ifomin
Full stack web developer, tech lead, project manager

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Mardi4nfdi
Shmovahhedi
Hynkov
Thaiamericanillinois
Microprint
Co
Meinneuesich
Announcements
Drjack
Org
Canada-direct
Gigzone
Blogspot
Clojure
Montysmovers
Kuehlkoerper
Github
Unni
Bye
Quero
Acompany
Hashnode
Drjack
Srch
Quero
Accurate
Beam
Audience
Bye
Announcements
Appsonly
Evna
X REMOVE AD