How to Run PHP Code in VSCode Terminal Console

How to Run PHP Code in Visual Studio Code Terminal Console
How to Run PHP Code in Visual Studio Code Terminal Console
Spread the love, Share this Article!

Subscribe to Our YouTube Channel!

Are you a beginner PHP learner and want to know How to Run PHP Code in the 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 directly in the visual studio code console terminal.

If you’re a web developer, you know that there are times when you need to run PHP code. But what if you want to run the code in a specific environment? Or maybe you want to run the code 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 use the terminal console in VSCode and run PHP code.

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 use it.

  • Can we run PHP code in Visual Studio Code?
  • How do I run a PHP script in terminal?
  • How do I run code in Visual Studio Code in the terminal?

Steps to Run PHP in VSCode Terminal

Follow these steps to run PHP code in the Visual Studio Code terminal:

  1. Install the Code Runner Extension.
  2. Install PHP or XAMP on your computer
  3. Add the PHP executable file path (C:\\xampp\\php\\php.exe) in Code Runner JSON configuration settings
  4. Also, add the same PHP executable path in windows environment variables
  5. Open the PHP code file in VS Code Text Editor
  6. Use a shortcut (Ctrl + Alt + N), or right-click the Text Editor and then click Run Code in the editor context menu.

Watch 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!

Steps to Run PHP in VSCode Terminal

Recommended for You!

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.

Install the Code Runner Extension

Step 2- Install PHP or XAMP on Your computer

In this step, You need to install PHP source code or XAMPP application on your computer.

Follow these steps to Install XAMPP on your computer:

  1. Open the Apache Friends website.
  2. Click the Download button for the Windows version of XAMPP and save the file on your computer.
  3. Double-click the downloaded file to launch the installer.
  4. Click the OK button.
  5. 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.

  1. Open the command palette (either with F1 or Ctrl + Shift + P )
  2. Type “open settings”
  3. 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",
    }
PHP code runner configuration
PHP code runner configuration

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:

  1. In Search, search for and then select: System (Control Panel)
  2. Click the Advanced system settings link.
  3. Click Environment Variables.
  4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable.
  5. Reopen Command prompt window, and run your java code
file path windows environment variable
File path windows environment variable

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.

Run PHP in VSCODE

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.

run php using code runner
Run PHP using code runner

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:

PHP code output
PHP code output

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.

Hit The Subscribe Button to Get Daily New video!

Spread the love, Share this Article!

Important Tags:

Leave a Reply

Your email address will not be published.