Phpstorm Xdebug Php



Learn how to configure XDebug and PHPUnit in PHPStorm, allowing you to write better tests and fix bugs faster.

  1. Phpstorm Xdebug Phpunit
  2. Phpstorm Xdebug Ssh
  3. Phpstorm Debug Php Web Application
  4. Phpstorm Xdebug Hangs
  5. Xdebug Php
  6. Phpstorm Xdebug Not Working
  7. Phpstorm Xdebug Php Docker
Phpstorm debug php web application

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. 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.

This was driving me crazy. I just updated to PHP 7.1 and xdebug that was working no longer worked. I updated the xdebug.so file (Linux) and php -version indicated that xdebug was indeed being loaded and working. But when I would use Postman the debugger never kicked on. Here's the solution. Make sure to check 'Use path mappings' and map php folder to '/var/www/myapp ' 5. Configure PHP remote debugger in PhpStorm: Run - Edit configurations - PHP Remote Debug. Add a new configuration and give it values like on the following screenshot. Php phpstorm xdebug. Improve this question. Follow edited Apr 2 at 11:49. 136k 37 37 gold badges 333 333 silver badges 337 337 bronze badges. Asked Apr 2 at 11:35. 89 4 4 bronze badges. Did you follow step 2 from the Pre-Configuration section shown in your last screenshot and install a browser toolbar or bookmarklet? I have WSL running PHP 7.4 on Ubuntu 18.04 and using PhpStorm 2020 on a new Windows 10 build. I cannot seem to get Xdebug to stop at breakpoints or even log errors. From phpinfo Version 3.0.1 Sup. Tom, you are having a different issue, in your case, PhpStorm is actually communicating with Xdebug. What's wrong is that you are using an older PhpStorm version and Xdebug 2.7, they changed the protocol in this version so you either need to downgrade to Xdebug 2.6 or upgrade PhpStorm to a more recent version, the earliest version that has this fix is 2018.2.

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.

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’m not gonna teach you how to write tests and even how TDD is good. I’m assuming you already have some tests written and just want to run them in PHPStorm, debugging with XDebug. I’m gonna use the tests from my open source project Corcel.

PHPStorm

Configuring XDebug

First let’s configure XDebug in PHPStorm. 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. So I had to update my php.ini file to change its port to 9001. My config file is located at /usr/local/etc/php/7.2/conf.d/ext-xdebug.ini:

When type php -v in the command line I can saw the XDebug extension enabled:

Then, in PHPStorm (I’m using currently version 2017.3), go to Preferences and Languages & Frameworks -> PHP -> Debug. Configure your XDebug port and uncheck some pre-checked options, just to avoid creating unnecessaries break points.

Configuring PHPUnit

First we must tell PHPStorm which PHP version we’re using and where is that PHP binary. This is necessary for code checks in the IDE and for running PHPUnit. Just set that in your IDE’s preferences window. You should set something like this:

Now go to Run -> Edit Configurations. Here we’re going to create a new configuration related to PHPUnit, give it the phpuni name and say PHPStorm we’d like to use the configurations in our phpunit.xml file.

Running Tests

Now let’s run all tests Corcel has. Go to Run -> Run and then select phpunit. This is the name we gave to the configuration we just created. You’ll see a new tab on the bottom of the window with all your tests running:

Running a Single Test

In this case we run all 139 tests. The point here is you can run just one test case or even the last one. In this new tab if you click on a single test case in the left sidebar and Control + Shift + R you’ll run just that specific test. The same can be used when you’re inside a class and want to run just one test/method. Inside any part of that method, if you press this shortcut you’ll run that test case. If you press the shortcut outside a test case method you’ll run tests for that specific class, all them.

Running the Last Test

If you’re fixing a bug in another class, not the test one, and you want to run that test again to see if it’s passing now. You can press Control + R shortcut. This tells PHPStorm to run the last run test, only. Then you don’t have to change the current file you are to run the last test case. Very useful!

Just to remember, Control + Shift + R to run the current test case you are, and Control + R to run the last run test case.

Debugging while Running Tests

The point here is you enabled XDebug. So you can debug while testing. Let’s take a simple test case from Corcel:

I’m gonna add a break point inside the $comment->isApproved() method, like this:

Xdebug

New Shortcuts to Debug

You know the shortcuts to run a single current test case (Control + Shift + R) and the last run test case (Control + R). If you to go the test case source code and run it you will not stop anywhere, because you’re running the test only.

To run tests with debugging support use Control + Shift + D for the single test case and Control + D for the last one, just replacing R by D.

If you run the same test with debugging support you’ll stop on that breakpoint, and then the magic starts happening. You will get a lot of information at that specific point, like current variables content and even continuing the executing step by step. You’ll get all that in the same tab you saw your tests running:

Then, debug your code. You have to useful commands/button to press. Here are some examples:

Conclusion

Phpstorm Xdebug Phpunit

TDD and Debugging are two important steps in development. Once you start using them you cannot stop, but for sure, you’re writing better and safer code, believe me.

I hope this post helped you to start with testing and debugging in PHPStorm and made you feel excited about start using that. If you want to use a project to start testing and debugging you can clone Corcel on your machine and start running its tests in PHPStorm.

FeaturesNewsletterTutorials

So, you’ve decided to try something new today and started a project from scratch. Your first step will be to set up a development environment: at the bare minimum, you’d want to run a web server and a PHP interpreter (preferably – with the debugging engine installed).

Phpstorm Xdebug Php

Phpstorm Xdebug Ssh

With Docker, you can start developing, running, and debugging your code in a matter of minutes!

Probably the easiest way to integrate Docker with PhpStorm is to use the PhpStorm Docker registry. It provides a selection of preconfigured Docker images curated by the PhpStorm team, which cover the most common PHP development needs.

Before you proceed, make sure that you have Docker installed on your machine: see how to do it on Windows and on macOS.

Defining the environment

To get started, we create a new project in PhpStorm. Next, we create a new file named docker-compose.yml , which will describe the configuration of the services comprising our app. In our case, it will be a single webserver service:
As you can see, we use the preconfigured Docker image comprising the Apache web server and PHP 7.1 with Xdebug.

Note that we use the host.docker.internal value to refer to the remote host. In Docker for Windows and Docker for Mac, it automatically resolves to the internal address of the host, letting you easily connect to it from the container.

An important note for Linux users: host.docker.internal on Linux is currently not supported. You’ll have to use your local machine’s hostname instead (to find out what your machine’s hostname is, simply execute hostname in Terminal).

The corresponding environment configuration section for Linux will read as follows:
See here for more details and possible workarounds.

Our environment is fully described:

We can now start using it by creating a dedicated run/debug configuration.

Phpstorm Xdebug Php

Creating a run/debug configuration

Phpstorm Debug Php Web Application

Right-click docker-compose.yml and select Create… from the context menu:

In the dialog that opens, provide the name of the configuration and apply your changes:

You can now start the configuration from the toolbar:

PhpStorm will automatically download the required image and start the web server:

That’s it: we’ve got everything ready for running and debugging our code!

Running and debugging code

Let’s ensure that everything works as expected. To do this, we’ll create the most simple Hello world PHP file and try to debug it following the PhpStorm Zero-Configuration Debugging approach.

Since we already have Xdebug installed and configured, this will only require that you:

Firefox

Phpstorm Xdebug Hangs

  • Have a debugging extension installed and enabled for your browser:
  • Set a breakpoint in your code:
  • Enable listening to incoming debug connections in PhpStorm:

Xdebug Php

Now, simply open the page in the browser, and the debugging session will be started automatically:

Phpstorm Xdebug Not Working

We encourage you to further explore the PhpStorm Docker registry: while we’ve looked at a very simple case, you can use the described technique to provide your environment with, for example, a database, or an sftp server.
Using these Docker images will save you a lot of effort and let you start coding in a matter of a minute, or even less!

If you’d like to learn more about Docker and how to use it in PhpStorm, make sure to check out the excellent tutorial series by Pascal Landau, and PhpStorm documentation, of course.

Phpstorm Xdebug Php Docker

Your JetBrains PhpStorm Team
The Drive to Develop