30-04-2021



Visual Studio Code Xampp

  1. Visual Studio Code installed. A version of PHP placed somewhere on your computer. Preferably PHP 7.0+. A folder and a blank index.php file. Configuring VS Code To Run PHP Code. So, we’ve got everything together and VSCode open, let’s add the settings. Go to File - Preferences - Settings.
  2. XAMPP is a free and easy to use Apache distribution containing Maria DB and PHP. I have used it throught this Php Course. The XAMPP open source package has been designed to be incredibly easy to install and easy to use. Lets see how we can get these softwares quickly into our computers.
  3. Browse other questions tagged php visual-studio-code xampp xdebug or ask your own question. The Overflow Blog Podcast 332: Non-fungible Talking. The Loop: Our Community & Public Platform Roadmap for Q2 2021. Featured on Meta Stack Overflow for Teams is now free for up to 50 users, forever.

It turns out you can run PHP code directly inside VS Code if you hook it up to your local PHP interpreter. No Debug Module Needed! It’s quick and simple to do and is an invaluable tool to have when you want to tinker with your code. Instead of booting up a web server and browser, you can execute instantly without leaving the VS Code IDE.

Prerequisites

In Visual Studio code in gebug panel push icon with gear and select php. Created launch.json. In gebug panel selected Listen for Xdebug. Mark breakpoints in app. Navigate and reload app in browser. Settings for mysite.local/test.php. Create folder 'c:/path-to-xampp/htdocs/mysite.local' In this folder create file test.php.

To follow this tutorial step-by-step, make sure you have the following in place.

Visual studio code xampp mac
  • Visual Studio Code installed.
  • A version of PHP placed somewhere on your computer. Preferably PHP 7.0+.
  • A folder and a blank index.php file.

Configuring VS Code To Run PHP Code

Visual Studio Code Xampp

So, we’ve got everything together and VSCode open, let’s add the settings.

1. Go to File -> Preferences -> Settings.

2. Add the following JSON to the User Settings on the Right Hand Side of the IDE. Replacing C:xamppphp with your path to your php.exe.

It should now look similar to below –

3. Save it.

Visual Studio Code Live Server Xampp

CodeStudio

Visual Studio Code Xampp

4. Go to your index file and add the following code –

Visual Studio Code Xampp Mac

5. Press F5 and VS Code will launch and execute the script. However, if you’ve already got debugging launch settings installed, you will have to explicitly choose ‘Run using local PHP Interpreter‘ from the drop-down list that pops up when pressing F5.

6. The debug console will pop up at the bottom of the IDE and say, ‘Hi Debug Console’. See the image below.

7. That is it! You have successfully set up your local PHP interpreter to execute code directly in VS Code IDE!

Summary

This setup is really great if you want a quick mess around with your code. Without having to configure a web server or any debug modules. It’s a great little gem I’ve stumbled across whilst using this fantastic IDE. I hope it helps you too!