

#Install xdebug phpstorm code
This is necessary for code checks in the IDE and for running PHPUnit. Configure your XDebug port and uncheck some pre-checked options, just to avoid creating unnecessaries break points.įirst we must tell PHPStorm which PHP version we’re using and where is that PHP binary. Then, in PHPStorm (I’m using currently version 2017.3), go to Preferences and Languages & Frameworks -> PHP -> Debug. With Xdebug v2.6.0alpha1, Copyright (c) 2002-2017, by Derick Rethans Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies When type php -v in the command line I can saw the XDebug extension enabled: PHP 7.2.0 (cli) (built: 21:47:51) ( NTS ) Zend_extension="/usr/local/opt/php72-xdebug/xdebug.so" My config file is located at /usr/local/etc/php/7.2/conf.d/ext-xdebug.ini:
#Install xdebug phpstorm update
So I had to update my php.ini file to change its port to 9001. We’re assuming here you already have the xdebug PHP extension installed. In my case, I’m using Laravel Valet, and it runs on the port 9000, the same port XDebug runs by default. PHPStorm Configuring XDebugįirst let’s configure XDebug in PHPStorm. I’m gonna use the tests from my open source project Corcel. I’m assuming you already have some tests written and just want to run them in PHPStorm, debugging with XDebug.
#Install xdebug phpstorm how to
I’m not gonna teach you how to write tests and even how TDD is good.

PHPStorm has a dedicated interface to run and debug tests, almost in the same window, what makes the process of writing code safer and easier. I started using TDD on the command line, and still use it sometimes, but since I started using PHPStorm and decided to try how it handles tests, and that’s amazing! When you add debugging tools – like XDebug – to it everything starts making sense, then you have the feeling you’re on the right path. The point here is that one of the most important benefits it’s to use debugging tools together with tests, making your flow more efficient. Test Driven Development (TDD) is an old topic, I know, but it seems many people don’t understand how it makes you write better code. This proves our breakpoints work as intended, and Xdebug has been successfully set up.Learn how to configure XDebug and PHPUnit in PHPStorm, allowing you to write better tests and fix bugs faster. Our $a array has one less element due to the array_pop operation we performed. Clicking the Resume button once more produces a slightly different output: Also notice you can expand it to see what it contains. Clicking the Resume button moves on to the next breakpoint and produces the following output: You’ll notice in the right panel that only the superglobals are declared – no other variables are present at this time. The left frame lists the stacktrace – the files the request already went through – and stops at routes.php, our file. A new tab should launch and immediately return you to PHPStorm with an output similar to this one: Then, go to Run -> Debug and run your predefined debug configuration. If you have the app open in your browser, close that tab now, otherwise PHPStorm won’t be able to re-run it. Then, put a breakpoint next to each line of the closure that does something, like so: In app/routes.php, alter the home route’s closure so that it looks like the code below: Route :: get ( '/', function ( ) )
