Php fpm xdebug phpstorm

Configure Xdebug

Xdebug extension installed

The output should list Xdebug among the installed extensions:
Create a php file containing the following code:

Xdebug 3 support enabled

Xdebug support enabled

Configure Xdebug in PhpStorm

Check Xdebug installation

ps_interpreters_debugger_not_installed.png

  1. Press Ctrl+Alt+S to open the IDE settings and select PHP .
  2. Check the Xdebug installation associated with the selected PHP interpreter:
    1. On the PHP page, choose the relevant PHP installation from the CLI Interpreter list and click next to the field. The list shows all the PHP installations available in PhpStorm, see Configure local PHP interpreters and Configure remote PHP interpreters.
    2. The CLI Interpreters dialog that opens shows the following:
      • The version of the selected PHP installation.
      • The name and version of the debugging engine associated with the selected PHP installation (Xdebug or Zend Debugger). If no debugger is configured, PhpStorm shows the corresponding message:

    Alternatively, open the Installation Wizard, paste the output of the phpinfo() , and click Analyze my phpinfo() output . Learn more about checking the Xdebug installation in Validate the configuration of a debugging engine.

    Define Xdebug behaviour

    1. In the IDE settings ( Ctrl+Alt+S ), select Debug under the PHP node to open the Debug page.
    2. In the Xdebug area, specify the following settings:
    3. Debug port : appoint the port through which the tool will communicate with PhpStorm. This must be the same port number as specified in the php.ini file:
    • Ignore external connections through unregistered server configurations : select this checkbox to have PhpStorm ignore connections received from hosts and through ports that are not registered as deployment server configurations. When this checkbox is selected, PhpStorm does not attempt to create a deployment server configuration automatically.
    • Break at first line in PHP scripts : select this checkbox to have the debugger stop as soon as connection between it and PhpStorm is established (instead of running automatically until the first breakpoint is reached). Alternatively turn on the Run | Break at first line in PHP scripts option from the main menu.
    • Max. simultaneous connections : use this spin box to limit the number of external connections that can be processed simultaneously.

    By default, PhpStorm only listens for incoming IPv4 connections. To enable IPv6 support, you need to make adjustments in PhpStorm JVM options:

    1. Select Help | Edit Custom VM Options from the main menu.
    2. In the .vmoptions file that opens, delete the -Djava.net.preferIPv4Stack=true line.
    3. Restart PhpStorm.

    Configure Xdebug for using in the On-Demand mode

    PhpStorm supports the On-Demand mode, where you can disable Xdebug for your global PHP installation and have it enabled automatically on demand only when you are debugging your command-line scripts or when you need code coverage reports. This lets your command line scripts (including Composer and unit tests) run much faster.

    1. Disable Xdebug for command-line scripts:
      1. In the Settings dialog ( Ctrl+Alt+S ), go to PHP .
      2. From the PHP executable list, choose the relevant PHP interpreter and click next to it. In the CLI Interpreters dialog that opens, click the Open in Editor link next to the Configuration file: file. Close all the dialogs and switch to the tab where the php.ini file is opened.
      3. In the php.ini file, find the [xdebug] section and comment the following line in it by adding ; in preposition:

      ps_interpreters_debugger_not_installed.png

    2. Open the CLI Interpreters dialog and click next to the PHP executable field. PhpStorm informs you that debugger is not installed:
  3. To enable PhpStorm to activate Xdebug when it is necessary, specify the path to it in the Debugger extension field, in the Additional area. Type the path manually or click and select the location in the dialog that opens.

Configure Xdebug for using in the Just-In-Time mode

PhpStorm supports the use of Xdebug in the Just-In-Time (JIT) mode so it is not attached to your code all the time but connects to PhpStorm only when an error occurs or an exception is thrown. Depending on the Xdebug version used, this operation mode is toggled through the following settings:

  • Xdebug 2 uses the xdebug .remote_mode setting, which has to be set to jit .
  • Xdebug 3 uses the xdebug.start_upon_error setting, which has to be set to yes .

The mode is available both for debugging command-line scripts and for web server debugging.

Depending on whether you are going to debug command-line scripts or use a Web server, use one of the scenarios below.

Command-line scripts

For debugging command-line scripts, specify the custom -dxdebug.remote_mode=jit (for Xdebug 2) or -dxdebug.start_upon_error=yes (for Xdebug 3) directive as an additional configuration option :

  1. Press Ctrl+Alt+S to open the IDE settings and select PHP .
  2. From the PHP executable list, choose the relevant PHP interpreter and click next to it.
  3. In the CLI Interpreters dialog that opens, click next to the Configuration options field in the Additional area.
  4. In the Configuration Options dialog that opens, click to add a new entry.

Web server debugging

  1. Make sure that the debugging engine on your local or remote web server is properly configured. For details, see Validate the configuration of a debugging engine.
  2. Open the php.ini file which is reported as loaded and associated with Xdebug.
  3. In the php.ini file, find the [xdebug] section.

Configure Xdebug running in a Docker container

To configure Xdebug running in a Docker container, provide the Xdebug-specific parameters in the Dockerfile , for example:

RUN pecl install xdebug \ && docker-php-ext-enable xdebug && echo «xdebug.mode=debug» >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo «xdebug.client_host = host.docker.internal» >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

In this example, we’re modifying /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini providing the mode and client_host Xdebug parameters.

Note that the xdebug.client_host value should be replaced with the IP address of the machine where PhpStorm is running, which is accessible from the Docker container. If you are using Docker for Windows or Docker for Mac, you can set xdebug.client_host to host.docker.internal , which automatically resolves to the internal address of the host, letting you easily connect to it from the container.

RUN pecl install xdebug \ && docker-php-ext-enable xdebug && echo «xdebug.remote_enable=on» >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo «xdebug.remote_host = host.docker.internal» >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

In this example, we’re modifying /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini providing the remote_enable and remote_host Xdebug parameters.

Note that the xdebug.remote_host value should be replaced with the IP address of the machine where PhpStorm is running, which is accessible from the Docker container. If you are using Docker for Windows or Docker for Mac, you can set xdebug.remote_host to host.docker.internal , which automatically resolves to the internal address of the host, letting you easily connect to it from the container.

Configure Xdebug running on a Vagrant instance

To configure Xdebug running on a Vagrant instance, connect to the Vagrant machine and provide the Xdebug-specific parameters in the php.ini file:

[xdebug] zend_extension=»» xdebug.mode=debug xdebug.client_host=10.0.2.2 xdebug.client_port=9003

Note that the xdebug.client_host value is 10.0.2.2 . This is the gateway used in the default Vagrant setup, which allows connecting from the instance to host where PhpStorm is running.

[xdebug] zend_extension=»» xdebug.remote_enable=1 xdebug.remote_host=10.0.2.2 xdebug.remote_port=9000

Note that the xdebug.remote_host value is 10.0.2.2 . This is the gateway used in the default Vagrant setup, which allows connecting from the instance to host where PhpStorm is running.

Источник

Дебажим PHP-контейнер с помощью Xdebug и PhpStorm


Инструкция Docker #9: xdebug

Я создам очень простую php-страницу и подебажу ее с помощью xdebug и PhpStorm.

Исходные файлы можно найти здесь:
github.com/ikknd/docker-study в папке recipe-09

1. Создайте файл «Dockerfile» в папке «docker»:

FROM php:7.2-fpm #Install xdebug RUN pecl install xdebug-2.6.1 && docker-php-ext-enable xdebug CMD ["php-fpm"]

Выполните эту команду из папки docker для создания образа:

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

2. Создайте файл docker-compose.yml в папке «docker»:

version: "3.7" services: web: image: nginx:1.17 ports: - 80:80 volumes: - /var/www/docker-study.loc/recipe-09/php:/var/www/myapp - /var/www/docker-study.loc/recipe-09/docker/site.conf:/etc/nginx/conf.d/site.conf depends_on: - php php: image: php-xdebug-custom volumes: - /var/www/docker-study.loc/recipe-09/php:/var/www/myapp - /var/www/docker-study.loc/recipe-09/docker/php.ini:/usr/local/etc/php/php.ini

Здесь я использую образ «php-xdebug-custom» вместо «php:7.2-fpm „

3. Внесите в файл php.ini следующие настройки:

[xdebug] zend_extension=xdebug.so xdebug.profiler_enable=1 xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_host=host.docker.internal xdebug.remote_port=9000 xdebug.remote_autostart=1 xdebug.remote_connect_back=1 xdebug.idekey=PHPSTORM

4. Настройте сервер в PhpStorm:

File -> Settings -> Languages и Frameworks -> PHP -> Servers
Добавьте новый сервер с помощью иконки + и настройте его, как показано на следующем скриншоте:

Убедитесь, что вы отметили «Использовать сопоставление путей» (“Use path mappings») и сопоставили папку php с /var/www/myapp .

5. Настройте удаленный дебагер PHP в PhpStorm:

Run -> Edit configurations -> PHP Remote Debug

Добавьте новую конфигурацию и присвойте ей значения, как на следующем скриншоте:

6. Выберите конфигурацию дебага на панели дебага PhpStorm

7. Перейдите в /var/www/docker-study.loc/recipe-09/docker/ и выполните:

Если я сейчас введу myapp.loc/ в браузере, я увижу результаты из файла index.php .

Я могу установить точку останова, начать прослушивание соединений в панели дебага PhpStorm и перезагрузить страницу.

Еще по теме

Источник

Читайте также:  Убрать лишние знаки python
Оцените статью