Home >Development Tools >phpstorm >Teach you step by step how to debug PHP projects in Docker with phpstorm
The following tutorial column of phpstorm will introduce to you how to debug PHP projects in Docker with PHPStorm. I hope it will be helpful to friends in need!
This machine has been developed using docker. For those who are used to debugging, placing PHP in a docker container adds another level of difficulty.
Of course, this only applies to when you don’t understand configuration yet. Once you master the trick, it is actually simpler than, and there is almost no difficulty difference from local configuration.
Before we start, let’s make some environmental assumptions:
/Users/gary/dnmp/www/localhost
/var/www/html/localhost
localhost
and binds it in the host hosts and nginx configuration9000
port The domain name here is not necessarily localhost
, if you use Laravel , Yii, Thinkphp and other frameworks, generally use domain names similar to mydev.com
, dev.awaimai.com
, awaimai.dev
, this article is also applicable.
The main configuration is as follows:
[XDebug] xdebug.remote_enable = 1 xdebug.remote_handler = "dbgp" xdebug.remote_host = host.docker.internal
The functions of these lines are:
dggp
host.docker.internal
, which is docker The host where the container is located. If the host is a Linux system, host.docker.internal
may not be used. You need to use the IP under the same virtual network of the PHP container and the host. Use the docker network inspect dnmp_default
command in the host. It can be found, where dnmp_default
is the network where the container is located. We have not configured xdebug.remote_port
here, because xdebug uses 9000
by default, which is consistent with our FPM, and there is no need to set it again. If FPM uses other ports, remote_port
must also be changed to the corresponding port.
After the configuration is completed, restart the PHP container.
1 Menu selectionRun – Edit Configurations,
2 Click the
number in the upper left corner of the pop-up box and select PHP Web Page
.
#3 There is no server yet, we need to add one. As shown below, click the ...
button on the right side of server.
#4 Then there is the configuration server information, here is the docker container.
localhost
, if your domain name is similar to awaimai.dev
, then fill in awaimai. dev
. 80
port, so the default 80
is retained here. , and then fill in the mapping relationship between local code and container code. If you are using a framework, fill in the root directory of the framework here.
.
we just added.
means the home page, if it is another page, such as
/home/index, then Fill in
/home/index.
OK to save.
Return to the code window, put a [breakpoint] in front of the code, and then click [Debug button] , as follows:
PHPStorm will automatically open the browser and stop automatically when the program reaches the breakpoint.
Here we can see the global variables, call stack, and temporary variables in PHP,
and can single-step debugging, which is very convenient.
The above is the detailed content of Teach you step by step how to debug PHP projects in Docker with phpstorm. For more information, please follow other related articles on the PHP Chinese website!