Are you a beginner PHP learner and want to know How to Run PHP Code in VSCode Terminal console? Then this blog post is for you!
In this blog post, I will show you How to Run PHP code in the visual studio code terminal console window and how to Run PHP Code in VSCode Terminal console.
If you’re a web developer, you know that there are times when you need to Run PHP Code in VSCode Terminal. But what if you want to run the code in a specific environment? Or maybe you want to Run PHP Code in VSCode Terminal in a specific console? VSCode has a built-in terminal console that can help you do just that!]
In this blog post, we’ll show you how to Run PHP Code in VSCode Terminal.
What is Visual Studio Code Terminal Console?
If you’re a web developer, you’re probably familiar with Visual Studio Code (formerly Visual Studio Code Terminal). It’s a powerful tool that can help you write and debug code faster than ever before. But did you know that there’s also a console version of VS Code?
In this post, we’ll take a look at what it can do and how to Run PHP Code in VSCode Terminal.
- Can we run PHP code in Visual Studio Code?
- How do I run a PHP script in the terminal?
- How do I run code in Visual Studio Code in the terminal?
- How to Run PHP Code in VSCode Terminal?
Steps to Run PHP in VSCode Terminal
Follow these steps to run PHP code in the Visual Studio Code terminal:
- Install the Code Runner Extension.
- Install PHP or XAMP on your computer
- Add the PHP executable file path (C:\\xampp\\php\\php.exe) in Code Runner JSON configuration settings
- Also, add the same PHP executable path in Windows environment variables
- Open the PHP code file in VS Code Text Editor
- Use a shortcut (Ctrl + Alt + N), or right-click the Text Editor and then click Run Code in the editor context menu.
Watch the Full Video Tutorial
You can watch the below video tutorial to learn the step-by-step process to execute the PHP script in your Visual Studio Code Terminal!
Recommended for You!
- How Text Color in VSCode Affects Eyes and Brain: Expert Insights and Solutions
- How to Change Keyboard Shortcuts VSCODE 2023
- How to Customize Bracket Colors in VSCODE | Bracket Pair Colorizer
- Top 10 Best VSCODE Extensions For Web Developers in 2023
Now, I am going to explain each step in detail with an image presentation.
Step 1- Install the Code Runner Extension
First of all, install the code runner extension in your VSCode editor. Code runner extension allows you to run multiple programming languages inside VS Code terminal.

Step 2- Install PHP or XAMP on Your computer
In this step, You need to install the PHP source code or XAMPP application on your computer.
Follow these steps to Install XAMPP on your computer:
- Open the Apache Friends website.
- Click the Download button for the Windows version of XAMPP and save the file on your computer.
- Double-click the downloaded file to launch the installer.
- Click the OK button.
- Click the Next button
Video Tutorial to Install XAMPP Localhost
Step 3- Adding the PHP Executable File Path
After that, you need to add the PHP executable file path in the code runner JSON configuration settings.
Follow these steps to open the VSCode settings.json configuration.
- Open the command palette (either with F1 or Ctrl + Shift + P )
- Type “open settings”
- You are presented with two options, choose Open Settings (JSON)
After that copy the following JSON code into your settings.json file to configure the code runner extension to run PHP code in the terminal window. And update the following PHP file path:
C:\\xampp\\php\\php.exe
"code-runner.executorMap": {
"php": "C:\\xampp\\php\\php.exe",
}

Step 4- PHP executable path in Windows environment variables
After that, you need to add the same executable file path in the Windows environment variable.
Follow these steps to add the PHP executable path in Windows environment variables:
- In Search, search for and then select: System (Control Panel)
- Click the Advanced System settings link.
- Click Environment Variables.
- In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable.
- Reopen the Command prompt window, and run your Java code

Step 5- Open the PHP code file in VS Code
After that, open any PHP code file in your Visual Studio Code editor to run the PHP program.

Step 6- Run the PHP code file in VS Code
Finally, Run the PHP code in your vscode editor. There are two ways to debug the PHP and show output in VS Code Terminal window.
Use a shortcut (Ctrl + Alt + N), or right-click the Text Editor and then click Run Code in the editor context menu.

After running the code a terminal window will be open to show you the output. And below is the output of the above PHP code script:

Final Words
In this blog post, I have shown how to run PHP code in the visual studio code terminal console window and how to run PHP code directly in the visual studio code console terminal.