Apr.17

Set Up XDebug On PhpStorm to work with Symfony

Today, I am going to show a very simple way to use Xdebug, PHPStorm, and Symfony in order to debug an application. PHPStorm is the best IDE I have used so far and it comes with amazing functionalities.
Anyways here we go:

Run/Debug Configuration

In order to run/debug a Symfony application within PHPStorm, we need to create a new configuration under “Run/Debug Configurations”.

The new configuration will be based as a “PHP script”. The file for this script will point to “bin/console”, which is under our code directory and the arguments should be entered as “server:run”. Basically what this does is that anytime you hit run or debug under PHPStorm, it will call Symfony console with arguments “server:run”. So you don’t need to run your application from terminal anymore. It will be running under PHPStorm’s terminal 🙂

Xdebug

The configuration part is basically useless without a debugger. Therefore, we will be using Xdebug’s debugging functionality to capture what’s going on in Symfony. In order to do this, go to Languages & Frameworks > PHP > Servers under PHPStorm preferences.

symfony-xdebug-phpstorm

Add a new server here. The host of the new server will be 127.0.0.1 (or your site domain instead) and port will be 8000 and debugger should be set to Xdebug. Don’t use path mappings since this may cause problems with Symfony.

CLI Interpreter

It’s quite possible that your CLI interpreter might be completely missing or its Xdebug is not configured properly. You need to make sure that your local PHP contains Xdebug configuration.

symfony-xdebug-phpstorm

The “information” button next to PHP executable path will output PHP info. Under PHPinfo you should be able to see the following:

xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.remote_cookie_expire_time = 3600
xdebug.remote_enable = 0
xdebug.remote_host = localhost
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp

If you don’t have Xdebug values here then you should either put them in a separate INI file or just add it under php.ini. A separate file is usually a recommended way to do this.

Time To Debug

So if everything is setup correctly, then simply hit the run button. This will call “bin/console” and output its contents to PHPStorm’s terminal. The local server should be accessible at http://orocrm.test:8000.

Let’s add a breakpoint somewhere in your main controller. The breakpoint will be ignored if you don’t tell PHPStorm to start listening for PHP Debug Connections. So click on the following button and make sure PHPStorm is listening.

That’s it! The debugger should now stop at the breakpoint and you should be able to access locals.

xdebug Listen button

Note: You can actually do this with Vagrant or Docker too. I can write an article if enough people are interested. Cheers 🙂

Run debug from PHPStorm console

Enable listening and run command:

XDEBUG_CONFIG="idekey=PHPSTORM" app/console oro:cron:graph-save-push-campaign
references: 
meduim
oroinc


Comments(2)

  1. Add for website
    157 days ago

    Add a new server here. The host of the new server will be 127.0.0.1 and port will beand debugger should be set to Xdebug. Don’t use path mappings since this may cause problems with Symfony.

  2. Instagram Followers
    147 days ago

    Thanks. As I mention in the question I debug with phpstorm and xdebug any others projects except this one, so xdebug is properly working. I updated with my xdebug configuration. I am going to check with yours now, I am only aware about the port configuration, but let s see. EDIT: got nothing at all hosseio Apr 21 ’15 at 6:26

Leave a Reply to Instagram Followers Cancel reply