If for some reason the listener does not trigger Xdebug, stop it and clear Drupal cache.To do that, run these commands in the root of your project. I have found that occasionally, if other Lando projects are running, Xdebug will sometimes not be triggered so it might be best to only run one project at a time.Thereafter, you can inspect arrays to your heart’s content! View the Xdebug output Tips and Tricks Once the above is set, you should now see the actual output from Xdebug as shown below. Triggering Xdebug in the IDE View Xdebug output If all goes well, you will now see Xdebug get triggered.Now click accept after choosing index.php.This is the "listener" where we set PHPStorm to listen for incoming connections so as to trigger Xdebug. Click on the Phone icon at the top of the IDE so that it turns green.Click in the left margin parallel to the variable so that you see a red dot.In the example, below, I've set a fake variable, $a =1 within function bartik_preprocess_node(&$variables) Input a variable to set a breakpoint for.Now for the final step, we are ready to trigger Xdebug with the steps below. Choosing the CLI image name Trigger Xdebug Now click apply and ok to save all these settings. Here you will choose "Docker" and then the image name, in our case devwithlando/php:7.4-apache-2. Here you will choose "From Docker." Configuring the CLI interpreter in PHPStorm Choose the CLI image name Choosing a language level and a CLI interpreter in PHPStorm Configure the CLI interpreter Next click on the three vertical dots to choose a CLI interpreter. Here you will want to set PHP 7.4 as the language level. The first thing to do is to go to preferences and search for PHP. Choose a language level and a CLI interpreter The following below is a series of screen captures that illustrate how to set this up. Once that is done, go to your site and make sure it loads. Once that is done, you'll see something like this in terminal: NAME d9xdebug Now that we have Lando all set, go ahead and run lando rebuild -y so that these updates take effect. If you've used an older version of Xdebug in the past, the port was typically 9000. Also note that port 9003 is set for Xdebug, that is because Xdebug 3 requires this. I also like to add memory_limit = -1 to this file as well to avoid any out of memory issues. You'll want to set these variables for Xdebug: Create these directories if they do not exist already. Now, we need to create our php.inifile within lando/config. Pointer to a custom php.ini file where we will need additional configuration for Xdebug.Noting that any time your change your recipe, you will need to run lando rebuild -y. lando.yml file in the root of your project. The TL DR for the one I am using is below. Lando has the notion of "recipes" for specific server setups and you'll want to set up a basic Drupal 9 site running on Lando. Thereafter, be sure to install Drupal as well. In this case, you'd need Composer 2 to be setup globally on your local machine but once Lando is up and running, you can then switch to using lando composer. Therefore, you can use Composer itself composer create-project drupal/recommended-project to create a new Drupal 9 project and then initialize it with Lando. You can spin up a Drupal 9 site using Lando but as of yet, there is no option that will set it up as a true composer based workflow. If you have any issues with getting Lando running, you can check their extensive documentation. You'll also need PHPStorm to be installed as well. Installing Lando will also install Docker desktop, a containerized server environment. You can head over to GitHub to grab the latest stable release of Lando. The core of this tutorial requires Lando and PHPStorm to be running on your machine. In this article I will share with you my basic setup to get up and running with Xdebug 3. a way to step through your code in your IDE or editor while the script is executing. Xdebug is an extension for PHP, and provides a range of features to improve the PHP development experience. When I am coding, I consider Xdebug to be of immense value for debugging and defining variables. In addition, I use PHPStorm for coding, an integrated development environment or IDE. Recently, I onboarded to a new project that required me to use Lando, another popular local development server. For my local Drupal development environment over the past few years, I’ve been quite happy using Docksal for my projects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |