Setup debugging for PHP8.1 with XDebug 3 in VSCode

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up everybody the code to look is here and welcome to my channel in this video we're going to enable X debug 3 in exam installation with the PHP 8.1 and debug PHP applications in vs code first we will debug traditional PHP application in browser with multiple PHP files in a folder then we will debug muc framework application with two different methods also in the browser first using php's built-in server second using exams virtual host we're going to also debug console application we will also see how to use debug console in vs code to execute additional code in your project while we are debugging we'll also see how to activate induce conditional breakpoints this video is going to be really interesting and useful so hit the like button get ready and let's start if you want to see a video for each debug 2 and php7 check my previous video which is released two years ago before we start make sure you have PHP path added in system variables path and is available from command line okay since we have it now we can already enable X debug first I'm going to open the project PHP crash course 2020. that's the project I created for Traverse media's YouTube channel you can watch that video it's a six hour six and a half hour PHP course and that's a source code which you can download from the following repository as well PHP crash course 2020 from my GitHub all right let's open this using vs code and let's open any files like comments for example and I'm going to create Echo PHP info right here so I just want to print the information the PHP information then let's open exam control panel and let's start Apache now let's go in the browser and access to the folder we just opened and here we have this and let's open these comments and here we have the all PHP info we have to copy everything from here just hit the Ctrl a and Ctrl C and now we have to open xdeback.org wizard it's going to open this text area we have to paste everything what we copied and click analyze my PHP info it's going to analyze and give us the corresponding dll file to download and put in our project here is the dll file and it's going to give us also instructions what we need to do I'm going to click on this dll file to download save that open and I'm going to rename this into just phpx debug and I'm going to cut this and go under my exam installation PHP EXT folder and I'm going to paste this right here okay that's the place where the extensions are located and Mike's debug needs to be right here okay now I'm going to open PHP ini which locates under PHP folder that's called scroll down below and find PHP I'm going to open this using vs code open let's scroll down below and I'm going to add the following code at the very bottom so this is just a grouping mechanism so underex debug I put the X debug mode is debug start with request yes and the Zen extension corresponds to the following dll basically this is the Syntax for X debug 3. for X debug 2 it's a different if you want Forex debug to check my previous video if you want to see the detailed explanation or migration guide from xdeback 2 to 3 check the following link docs from mixdeback.org docs upgrade guide basically there are three things you need to remember from this first instead of all these several lines remote enabled default enable and so on you need only this x debug mode corresponds to the back okay that's the one thing you have to remember second is that the default Port was changed from 9000 to 9003 and the third thing you need to remember is that remote remote auto start was removed and now we have to specify start with request yes and that's basically what we're doing right here x debug mode start with the request yes and the default Port because it is already 9003 we don't change the default Port if you want to specify the host and port for each debug you have to specify using client host and client port for example if you have an old configuration where you are listening basically to Port 9000 you can specify it like this previously in extend Back 2 it was remote host and remote Port now as a client host in client port in this case I'm not going to specify because I'm going to use a default client host will be localhost and the client Port will be 9003 so I'm going to remove these now I'm going to save PHP any and we're going to open Nixon control panel stop and start Apache to take the changes we made in PHP next let's open the browser open our project PHP crash course 2020 and let's open for example the folder 12 op the inside which I'm going to basically enable debugging now let's go under extensions and type PHP in debug that's going to open the following extension for mix debug I'm going to click on install then we're going to click run at the top add configuration choose PHP and that will create dot vs code folder in the project with launch Json and we have three options to debug our application and the default Port is 9003 okay let's go in the run and debug and I'm going to choose listen for X debug the very first one and click on play right here then let's open the browser reload the page and the only thing we need is to create a breakpoint so let's open the 12 op and Unix PHP and I already had a breakpoint right here and the code came right here let's actually remove the breakpoint and click play button so without the break point if we just refresh the page it simply works I create a breakpoint now I reload the page and the debugging has started and we see that the line comes right here and we have the following controls which is for continuous step over step into step out to restart and stop the debugging I'm not going to go into two details of the debugging itself like what is step over what is step into Etc if you want to dedicate this video about covering the vs code debugging interface with options more detailed guide like debugging a real world application just let me know in the comment section down below this video is how to set up debugging with vs code so basically the only thing I'm going to show you is the conditional breakpoints which is really handy feature let's hit the breakpoint right here and let's continue and let's step into inside the student Constructor and I'm going to create additional breakpoint right here I'm going to right click on this breakpoint and edit the breakpoint okay and right here I can put an expression which which should either evaluate true or false and whenever this evaluates into true the breakpoint will be active only in this case like I want to write for example stid equals one two three four I'm going to hit the enter so let's open the other file and I'm going to remove all the breakpoints from here and continue now let's open the browser and reload the page okay the debugger comes right here because the stid basically is one two three four okay let's continue and if I change the stid into one two three for example save this file and reload in the browser the debug doesn't get activated okay simply because the conditional breakpoint is not satisfied okay pay attention right here so the break point has equal sign range here which indicates that this is a conditional breakpoint okay let's stop this I'm going to actually close this and now let's debug a second PHP muc framework application by the way I'm working on a video setup vs code for PHP developers in which we will cover all the necessary extensions code Snippets tips and tricks you need in vs code to effectively work on PHP so I think it's good time to click the Subscribe button and enable notifications not to miss my upcoming video If you want to get the source code of this PHP MSC framework you can check this on my GitHub as well I do have also seven or eight video playlists on YouTube channel where I build this framework from completely scratch if you want to see you can check it out if you want to just get the source code check the following repository okay here I have the project I'm going to open this using vs code and the very first thing I'm going to do is Click run add configuration and choose the PHP okay let's go in the launch Json and I have to modify few things first I'm going to run this using a built-in web server so I have to modify a few things in the runtime arguments I'm going to specify dash s I'm going to specify right here localhost Port 8000 and I'm going to specify T and basically dot to specify the current current directory I'm going to remove the program and instead of the D I want to specify public so public needs to be the folder that needs to be served okay so I'm going to remove the pattern in URI URI format from server directions so I'm going to actually save this and go in the run and debug and I'm going to choose launch built-in web server and click play right here this will spin up the server on localhost Port 8000 let's open in the browser localhost Port 8000 we don't have any breakpoints probably so let's open index PHP which is the entry script and that locates under public folder and let's create a breakpoint right here okay let's reload in the browser and voila the debugger was activated okay so again you can step into step out you can do whatever you want right here you can deactivate errors and exceptions if you want like that but the debugging is active and that is happening using php's built-in server now I'm going to show you how to create a virtual host and have X debug activated using virtual host basically it's pretty straightforward so let's open the exam directory let's go in the exam folder go in Apache conf extra and open HTTP DV hosts and right here I'm going to create let's uncomment this and I'm going to create one virtual host for our PHP MSC framework and second which is going to be fallback for localhost let's create the second one which is going to be for localhost it points to hddux folder and the first one will be PHP MVC Dot localhost okay and the directory will be PHP and we see framework slash public okay that's going to be the folder which needs to be served okay we have to save this and we have to open exam control panel stop Apache and start that and now if we open the browser and just type PHP Embassy framework uh sorry PHP MSC localhost that's the server name we gave right here it's gonna open the application we can navigate we see that's working now let's open vs code go in the run and debug and click listen Forex debug and click play we have the breakpoint in index PHP so whenever we reload the page the breakpoint gets activated and just like this we can actually start debugging the only thing I'm going to show you will be how to use debug console let's actually modify a few things like let's create breakpoint right here let's create a variable right here name name equals zura okay and let's say that right here we simply output the name okay so right here I have a breakpoint so let's continue and it comes right here now let's open the debug console click terminal new terminal debug console and right here I'm going to type name equals John on the left side under variables we see before I run this code we see that the name where is it we have the name user-defined constant super Global snow we don't have it in the super globals okay let's step over actually let's top this and we have to rerun because it was always already running when we created this name okay so we save that and reload the page okay now we see Zero right here and let's listen for X debug and reload the page and now we see on the left side name is an initialized let's remove the breakpoint from here and continue now we see name is zura okay now down below I'm going to set the name equals John and I'm going to hit the enter now I see on the left side of the name was changed and if I simply continue and have a look in the browser we see that the name basically corresponds to John now that was our outputted okay so just like these you can use the debug console to modify certain things while you are debugging which is really handy another thing which I want to show you is how to debug console applications so right here we have a console script to run migrations and it's called and it's called migrations PHP so we can run this using PHP migrations PHP migrations PHP and it basically writes there are no migrations it also tries to connect to the X debug on the given Port but because the X debug is not active we are not listening then it writes the following step back warnings so if we simply start listening for X debug and execute the PHP immigrations PHP if we have a breakpoint in migrations PHP it's going to stop so let's open migrations PHP and create breakpoint right here and let's execute the script once again and you'll look at this so in migrations PHP the breakpoint gets activated okay and we can also switch to launch currently open script and click the play button which will immediately start debugging of the immigrations PHP click play right here and the breakpoint gets activated right here and again we can use all the debugging options alright guys that's it for this video and thanks for watching if the video was helpful please hit the like button thanks everyone for watching and see you in the next time
Info
Channel: The Codeholic
Views: 38,834
Rating: undefined out of 5
Keywords: xdebug, debugging php, debugging php with xdebug, php, vscode and xdebug, debugging with vscode, vscode xdebug on windows, xdebug vscode on windows, debugging php with vscode, visual studio code debugging, debugging php with xdebug and vscode, vscode php debugging, php debugging with vscode, vscode php, php vscode, php vscode debug, php vscode debugging, TheCodeholic, debug php8.1, xdebug 3, debug php8.1 with vscode, php8.1 xdebug 3, debug php8.1 with xdebug 3 in vscode
Id: HrQWtbxY1Hs
Channel Id: undefined
Length: 15min 26sec (926 seconds)
Published: Mon Sep 12 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.