phpstorm xdebug with a symfony2 project

前端 未结 5 1190
無奈伤痛
無奈伤痛 2021-02-04 11:52

I am trying to debug a symfony2 application with xdebug and phpstorm.

My local development environment is Ubuntu 14.04 with apache2 and Xdebug version is 2.2.7

I

相关标签:
5条回答
  • 2021-02-04 12:16

    It was a mapping problem. The following are the steps which did the trick

    1. Disable path mapping under Settings > Languages & Frameworks > PHP > Servers > uncheck "Use path mappings
    2. Start debugging
    3. The famous “Remote file path ‘path/to/script/on/the/server.php’ is not mapped to any file path in project“ finally appears
    4. Then I could follow the Troubleshooting section in official guide setting up path mappings

    Hope this helps to anyone else

    0 讨论(0)
  • 2021-02-04 12:20

    I had a similar issue which again proved to be a mapping problem, debugging a Symfony 2 project remotely using PHPStorm.

    If PHPStorm can't map the src file locations, it will break on the first line of code in app_dev.php (if you've set 'Break on first line') but then continue straight through any break points set in /src (e.g. Controllers, Models, etc.) and doesn't flag any error.

    1. Go to Setting -> Languages & Frameworks -> PHP -> Servers
    2. Select your server in the middle-left pane (or add using '+')
    3. Check 'Use path mappings (select if the server is remote or symlinks are used)'
    4. Add mappings such that /app, /src and /web are mapped. These can be individual mappings, but it's better if possible to set a higher level mapping on / which covers them all.

    Once PHPStorm can map these paths, it stops and breakpoints and meaningful debugging can begin.

    0 讨论(0)
  • 2021-02-04 12:24

    I also had to comment out the loading of class cache (symfony 2.7). I did it temporarily in the web/app_dev.php

    //$kernel->loadClassCache();
    

    Otherwise the debugging took place in bootstrap.php.cache or breakpoints did not work.

    0 讨论(0)
  • 2021-02-04 12:27

    If you find that PHPStorm keeps asking for mappings try and create a mapping at the highest level of the project as @stanhope mentioned, that should be enough.

    My first mapping was incorrectly set to the app_dev.php file in /web which meant that the IDE kept asking me for mappings to files in vendor directories.

    e.g. /vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Response.php

    0 讨论(0)
  • 2021-02-04 12:31

    I don't know which browser you are using, but, using Chrome, I use the Xdebug helper extension.

    Once the extension is installed, right click on it > options and select PHPStorm as IDE.

    Then, start listening for connection on PHPStorm using the button near the debug one.

    EDIT:

    Here is my configuration of XDebug:

    zend_extension=/usr/lib/php5/20121212/xdebug.so
    xdebug.max_nesting_level = 1000
    xdebug.collect_params = 1
    xdebug.collect_return = 1
    xdebug.remote_enable = 1
    

    Are you sure XDebug is properly installed on your machine ?

    When in PHPStorm > Run > Edit Configurations..., add a PHP Web Application debugging profile and fill it this way:

    • Name: Acme Project
    • Server: apache2 (you might need to add yours - name, port, adresse, debugger)
    • Start URL : /app_dev.php
    • Browser: Default

    Press OK and you're done !

    0 讨论(0)
提交回复
热议问题