DEV Community

Cover image for How to run PHP in Visual Studio Code in 2021?
Sainath Poojary
Sainath Poojary

Posted on

How to run PHP in Visual Studio Code in 2021?

1) Download and Install XAMPP

You can find the XAMPP installer on the following permalink:
https://www.apachefriends.org/index.html

2) Create a new project/folder

Go to the xampp\htdocs folder and create a new folder (with your project name)

3) Create a PHP file inside the project folder

Open vs code in the project folder and create a new PHP file with a .php extension (i.e FileName.php) with the following code
image

4) Open XAMPP Control Panel and start Apache server.

image

5) Open the browser and search localhost/FolderName/FileName.php

image

Congratulations you have successfully created and run your first PHP code using visual studio codeπŸŽ‰.

You can also check my youtube video β€œhow to run PHP in Visual Studio Code in 2021” if any doubt.πŸ‘‡
IMAGE ALT TEXT HERE

Top comments (2)

Collapse
 
alexanderadelau profile image
Alex • Edited

I have just moved to VS Code from Eclipse. Eclipse had a nice feature where you can connect a server to the XAMP/htdocs folder and it would sync to that folder which means that you can keep your source separate from the deployment folder. A nice feature would be to be able to run a script from within VS Code that did the deployment automatically.

Collapse
 
sarveshprajapati profile image
Sarvesh Prajapati

Simple and precise explanation. Awesome.
I have a question though, would you prefer xampp rather than just install php, mysql and apache server manually.