ide vscode

This guide explains how to configure Visual Studio Code (VSCode) for PHP development on WSL + Docker.
Note: This is based on personal experience.

Environment

  • Windows 10 64-bit
  • Ubuntu 22.04.3 LTS (running on WSL)
  • Docker Engine 26.0.0
  • PHP 8.2.15
  • Visual Studio Code 1.87.2

Prerequisites

  • You already have a PHP project running in a Docker container on WSL.
    For details on setting up a Laravel project on Docker inside WSL, refer to this guide.
  • Visual Studio Code is installed.

Setup Steps

  1. Open the Project on WSL
  2. Set the Executable Path
  3. Configure Xdebug
  4. Install PHP Intelephense
  5. Install PHP DocBlocker

1. Open the Project on WSL

For instructions on how to open a project on WSL with VSCode, see this guide.

2. Set the Executable Path

To configure VSCode to use PHP from inside a Docker container as the executable path, follow this guide.

3. Configure Xdebug

To set up Xdebug in VSCode for debugging PHP running in Docker on WSL, refer to this guide.

4. Install PHP Intelephense

To install PHP Intelephense in VSCode, follow the steps in this guide.

5. Install PHP DocBlocker

To automatically generate PHPDoc comments, install PHP DocBlocker.

Open VSCode, and click on the Extensions icon.

Open Extensions Button

Type php doc in the search bar, and install PHP DocBlocker from the search results.

PHP DocBlocker Extension

PHP DocBlocker is now installed.

You can now generate PHPDoc blocks automatically by typing /** above a function and pressing Enter.

PHPDoc Example