How To Setup PHP for VSCode | Setting Up VSCode For PHP Programming

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video I'm going to show you how you can run your PHP file on your Visual Studio code editor on your windows 11 operating system so for this you will need two things first one is the zamp server which will help you to run your PHP files and then you need the visual studio code editor so if you don't know how to install Visual Studio code or how to install xampp server I will put the link of those two videos in the description so you can click on those link and see how you can install Visual Studio code and zamp once you have these two things let's start so first of all we need to start our zamp server so you will find your zap server under the Windows start button so click on the Windows start button and then click on all apps and then scroll down until you see a zamp here and then click on zamp control panel which is going to start the zamp control panel so from here you need to start the Apache server so I'm going to click on the start button to start the Apache server you can also start the MySQL server from here so start Apache and MySQL from here so once that's done and you will see a green around these two servers then both of them are running once these two servers are running just minimize this window now we need to go to the location where we have installed the xampp server by default it's installed in the C directory so I'm going to go to my C directory and then I'm going to just go under this XA MPP or xampp folder so click on this zap folder and then here you need to go inside this HD docs folder so once you are inside this HD docs folder you can create any folder of your choice where you want to save all of your PHP files so you can right click here and then create a new folder and name it anything so I'm going to name my folder as my app you can give any name to your folder in my case it's my app and then I'm going to press enter and then I'm going to go inside my folder now in here you can create a PHP file so in order to create a PHP file on Windows you need to create a text file and then change the extension of it otherwise you can open Visual Studio code here right so right click here and then click on show more options and you will be able to see this option which says open with code so just click on this option which is going to open this folder my app in Visual Studio code otherwise if you don't want to open it from here you can just open Visual Studio code first of all and then you can just copy the path of your folder which you have created recently and then click on file and then click on open folder and then just give the path here and then and then click on select folder which is going to open the same folder right so once you have opened this same folder which is essentially this folder which we have created you can see this folder name is my app here we can create our PHP file so I'm going to name my PHP file as test dot PHP here okay and then press enter and at this point Visual Studio code is going to recognize that you want to write some PHP code and you can see cannot validate since a PHP initialization could not be found use the settings PHP path to configure this PHP executable right so for now we are going to ah just close this window otherwise if you want to set the PHP exe file then you can click on the open settings option but we want to run PHP using the xampp server right so we are using right now Visual Studio code as just the editor and everything will be taken care by our xampp server so here you can just write a very simple PHP hello world program like this which just prints hello world in order to test whether it's running or not and once you are done just save your file and once the file is saved we can go to our browser and then just type localhost and if you have added some Port you can also type some Port here you can know the port on which your Apache server is running by just viewing this port under ports you can see it's running on Port 80 in my case and by default The Local Host will run on Port 80. if it's running on any other Port you need to type colon and then the number of ports if it's running on port 8080 then you just need to type the port number here right you can just type localhost colon 80 which essentially mean localhost and then I'm going to press enter here you can see the Apache server is running now in order to see your PHP file what you need to do you need to just open the same folder structure so you need to type the name of your folder which is my app and then test dot PHP right so instead of dashboard just write the name of the folder in which your PHP file is there and then the name of your file which is test dot PHP in my case right and then press enter and it is going to show you this result which is hello world and you can see what we have printed hello world right I can also add some more text here and then save this file and then I can just refresh this file and it's going to show me the output right so this is how you can run your PHP files with Visual Studio code on your windows 11 operating system now if in case you want to run your PHP files using command prompt or command line then what you can do so for that you might need to add the PHP in your environment variables right so if you have installed zamp the path for PHP executable file is you once again need to go to your C directory and then go under zamp folder and here you will be able to see the PHP folder right so here you will be able to see all the PHP related files and you can use php.exe to run your PHP files right so just copy the path in which your php.exe file is there and if you have installed the zamp and if you have installed the zamp in the C directory just copy this path which I have copied and then just click on the search icon here and then just type environment variables so just type environment and once you type few letters of environment you will be able to see this option which says edit the system environment variables so I'm going to click on this and it's going to open this window so here just click on environment variables and then select the path environment variable under system variables and then click on edit or double click on it here we are going to add a new environment variable and then just paste the path which we have copied which is the path of our PHP directory inside our zamp folder okay I'm going to press enter here and then click on OK OK and ok so once you have set the environment variables you might need to restart your Visual Studio code so I'm going to just exit Visual Studio code and I'm going to restart my visual studio code in the same directory in which my PHP file is there in my case it's my app and in my app I have this test dot PHP file right now once I have restarted my visual studio code I can open the terminal from here so I'm going to click on Terminal and then new terminal and here you can see it has started this Powershell terminal for me and in the right hand side I can see the list of all the terminals right so once again terminal new terminal and by default because Powershell is the default terminal on my windows 11 operating system it opens the same folder in the Powershell if you are not a fan of Powershell you can also open the command prompt from here so click on Arrow command prompt and it will open the command prompt now if you know some PHP commands you might also know that in order to run your PHP file you can just type PHP and the name of your file which is test.php in my case and then press enter and you can see it prints the output which is hello world so this was possible because we have set the PHP environment variable right if PHP environment variable is not set this command is not going to work right and if it's not working just restart your Visual Studio code once again and try it so if you want to test small PHP scripts you can directly test these scripts from here otherwise you can always use this browser where your output will be shown right in addition you can also install some popular extensions related to PHP right so when you uh just click on this extensions icon here you will be able to see the extensions which are popular you can also search for the extension for PHP just type pH in the search box and it's going to show all the popular PHP related extensions so you can see this one is most popular here and it's developed by X debug and the number of downloads here is around 6 million right so you can click on install and then just install this extension and this will help you to debug your PHP code using visual studio code editor you also have the other popular extensions for let's say PHP code intelligence for visual studio code and PHP extension pack is also here so in this PHP extension pack some popular packs are here for example PHP debug and PHP intellisense so you can install all these popular extensions and then just try to use this extension in order to debug your code or run your PHP scripts right so this is how you can run PHP files on your Visual Studio code I hope you've enjoyed this video and I will see you in the next video
Info
Channel: ProgrammingKnowledge2
Views: 13,891
Rating: undefined out of 5
Keywords: how to run PHP code in visual studio code, how to run PHP program in visual studio code terminal, visual studio code PHP, PHP extension for visual studio code, how to install pip in visual studio code, PHP download, visual studio code download, PHP interpreter vscode
Id: 8ZRnj_lKiGE
Channel Id: undefined
Length: 12min 14sec (734 seconds)
Published: Sat Mar 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.