Symfony Xdebug Phpstorm



Note the Debugger extension field: if you write xdebug (or xdebug.so or xdebug.dll for PHPPHPStorm will automatically append -dzendextension=xdebug when running a script in “Debug Mode”. Now we have PHP, let’s install PHPUnit! Preferences Languages & Frameworks PHP Test Framework (create new configuration to allow PHPSTORM find PHPUnit). PhpStorm 2020.3 is now available! This major release includes full support for PHP 8, static analyzers PHPStan and Psalm, Xdebug 3, Tailwind CSS, collaborative development via Code With Me, and much more. Download PhpStorm 2020.3 Read on for details on all the new features and significant updates, along with a ton of GIFs! When working with Symfony, checking whether XDebug is installed and enabled is as simple as looking at your Web Debug Toolbar. Inside your appdev.php (dev) environment, mouse of the PHP icon on the toolbar and you'll see a red or green XDebug badge. If it's green, you're good to go. If it's red, you will need to install and enabled XDebug.

How to set up remote debug for symfony app.

1> go to run -> Edit Configurations

2> Click on ‘+’ symbol, top – left corner

3> adding a PHP Remote Debugger, now a window popup, and give a name to this application.

4> select a server, if no server set up, following below steps.

  • 4.1> give server a name.
  • 4.2> your host name and port (not xdebug port)
  • 4.3> choose xdebug
  • 4.5> set up mapping.

Php Docker Xdebug Phpstorm

for example:

if your symfony app is intalled on folder is e:wwwtestdev, and Vagrantfile is under e:wwwtest, then on vagrant server,

you will have /vagrant/dev, and Symfony app’s doc root is /vagrant/dev/web/

now, use above information to set up mapping.

e:wwwtest mapping to /vagrant

e:wwwtestdev mapping to /vagrant/dev

e:wwwtestdevweb mapping to /vagrant/dev/web

5> start URL set to “/”

6> select a browser.

On vagrant server side, install xdebug.

put following xdebuger content to php config file.

xdebug.max_nesting_level=200
xdebug.remote_enable=on
xdebug.remote_host=127.0.0.1
xdebug.idekey=PHPSTORM

restart web server or php5-fpm instance.

Configure Xdebug Phpstorm

now, go back to hosting machine. I am use windows 10.

run putty.exe, on Connection->SSH->Tunnels set up ssh tunnel.

now login into vagrant. make sure port 9000 is not been occupied.

go to phpstrom. turn on debug listener, on top – right corner.

go to File->Settings->Languages & Frameworks -> PHP -> debug, make sure xdebug port is 9000

set a break point on Symfony app,and from run -> Debug “you app” to start debugging symfony app.

If you want to debug a page, go to the page first , then enable phpstorm’s debug listener, then put following as url query,

?XDEBUG_SESSION_START=PHPSTORM

https://youhost.com/page??XDEBUG_SESSION_START=PHPSTORM

If xdebug seems not working, added xdebug.remote_log=/tmp/xdebug.log to xdebug.ini file. then restart php fpm and nginx

PhpStorm provides coding assistance and navigation facilities for developing applications with the Symfony framework.

Symfony support is provided by means of the Symfony Plugin. The source code for the plugin, as well as its issue tracker, can be found on GitHub.

Before you start

Before you start working with Symfony, make sure that the Symfony and PHP Annotations plugins are installed and enabled.

Enabling the Symfony Plugin for a project

Having installed the Symfony plugin, you need to explicitly enable it for the project. After creating or opening a Symfony project, PhpStorm will display a notification message suggesting you enable the plugin.

Enable the Symfony Plugin for a project

  1. Do any of the following:

    • Click the Enable the Symfony plugin with autoconfiguration link in the notification message.

    • In the Settings/Preferences dialog Ctrl+Alt+S, navigate to PHP | Symfony and select the Enable Plugin for this Project checkbox.

  2. Restart PhpStorm for the changes to take effect.

Specifying additional settings

Depending on how the Symfony project is structured, you may have to change some additional settings under PHP | Symfony. When working with a Symfony application that follows the structure generated by, for example, the symfony/framework-standard-edition Composer project, the default paths and settings will work fine.

Note that the appDevDebugProjectContainer.xml and appDevUrlGenerator.php must be located under the Symfony's default path in order to work with all features the Symfony Plugin provides. It will use a fallback mechanism when these files cannot be found, but completion and navigation will be less precise in this case.

When using a non-default project structure, the following paths should be updated in the Symfony Plugin settings:

  • Translation Root Path: the path to the location where all translations are copied. This should be set to the translations path under the cache folder, so that all possible translations are discovered by the plugin. In Symfony 4 and later, the default path is ./var/cache/dev/translations/.

  • App Directory: the path to the app directory. In Symfony 4 and later, the default path is ./config/.

  • Web Directory: the path to the web directory. In Symfony 4 and later, the default path is ./public/.

Symfony profiler

When the Symfony Plugin is enabled for a project, an additional region will be added to the PhpStorm status bar. Clicking Symfony in the status bar will open the popup menu with the related targets for the latest requests being made to our Symfony application.

Navigate to a related target

  • Click the corresponding item in the profiler popup menu:

    • Debug URL: the Symfony profiler URL for the given request, for example, /app_dev.php/_profiler/355651.

    • Routes: the route registration in the application

    • Controller: the controller that was involved in creating a response.

    • Template: any of the templates related to a response.

Symfony Code Style

PhpStorm provides the built-in Symfony2code style tailored for Symfony development.

Set the Symfony2 code style

  1. In the Settings/Preferences dialog Ctrl+Alt+S, navigate to Editor | Code Style | PHP.

  2. Click the Set from link in the upper-right corner and select the Symfony2 option from the popup menu.

Checking code against the coding standards

With PhpStorm, you can use the PHP_CodeSniffer tool, which detects coding standard issues, in combination with Symfony coding standard, which provides a set of -specific standards to PHP_CodeSniffer. This will ensure that your code is clean, consistent, and free of some common errors.

Php docker xdebug phpstorm

To get started, install PHP_CodeSniffer using any technique described in Install and configure PHP_CodeSniffer. Probably the easiest way is to install it with Composer.

Install PHP_CodeSniffer

  1. Inside composer.json, add the squizlabs/php_codesniffer dependency record to the require or require-dev section. Press Ctrl+Space to get code completion for the package name and version.

  2. Do one of the following:

    • Click the Install shortcut link on top of the editor panel.

    • If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press Alt+Enter and select whether you want to install a specific dependency or all dependencies at once.

Next, install Symfony coding standard, which will provide -specific standards to PHP_CodeSniffer.

Install Symfony coding standard

  1. Inside composer.json, add the escapestudios/symfony2-coding-standard dependency record to the require or require-dev section. Press Ctrl+Space to get code completion for the package name and version.

  2. Do one of the following:

    • Click the Install shortcut link on top of the editor panel.

    • If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press Alt+Enter and select whether you want to install a specific dependency or all dependencies at once.

The Symfony coding standard package will be installed, and the corresponding standard will be selected for the PHP_CodeSniffer validation inspection automatically. If necessary, you can further customize the inspection on the Editor | Inspections page of the Settings/Preferences dialog Ctrl+Alt+S. See Configure PHP_CodeSniffer as a PhpStorm inspection for details.

Using the Symfony command line tool from PhpStorm

PhpStorm integrates with the Symfony console and scripting interface. Before you begin, install Symfony Console as described in the Symfony documentation.

Configure Symfony automatically

  • On project opening, PhpStorm will detect and configure Symfony and display the notification in the Composer Log.

    If you want to customize the tool, click to quickly jump to the Command Line Tool Support settings page.

    On Windows, automatic Symfony detection requires a configured local PHP interpreter.

Configure Symfony manually

Xdebug Phpstorm Cli

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Tools | Command Line Tool Support.

  2. Click on the toolbar.

  3. In the Command Line Tools dialog, choose Symfony from the list, and specify its visibility level (Project or Global ).

  4. When you click OK, the Symfony dialog opens.

    Provide the path to the Symfony console executable file and the PHP interpreter, set the Symfony version, and click OK.

    The default executable location is <Symfony-home>/data/bin/symfony for Symfony 1.*, <Symfony-home>/app/console for Symfony 2, and <Symfony-home>/bin/console for Symfony 3 and later.

  5. Click OK to apply changes and return to the Command Line Tool Support page. Optionally, click to edit the tool properties, or to customize the commands set. See Customize a tool for details.

Run Symfony commands

  • From the main menu, choose Tools | Run Command or press Ctrl twice.

    In the Run Anything window that opens, type the call of the command in the <s> <command> format.

    The command execution result is displayed in the Run tool window.

Terminate a command

Phpstorm Xdebug Ssh

  • Click on the Run tool window toolbar.

Debug Symfony commands

Symfony commands are defined in controller classes that extend Command. To debug a command, it is crucial that you initiate a debugging session for the command itself, and not the controller class file it is defined in. Otherwise, the Symfony bootstrapping process will be skipped, and the execution will fail.

  1. In the controller class corresponding to the selected command, click the editor gutter at a code line where you want to set a breakpoint.

  2. Create a run/debug configuration that will run the symfony tool with the selected command. In the main menu, select Run | Edit Configurations, then click and choose PHP Script from the list.

  3. In the PHP Script dialog, provide the run/debug configuration parameters.

    • In the File field, provide the path to the symfony executable file.

    • In the Arguments field, type the actual command and its arguments, such as app:list-users.

  4. On the PhpStorm toolbar, select the created run/debug configuration and click . The command execution will stop at the specified breakpoint.