How to Set Up PHPCS & WPCS in VS Code on Windows

This guide walks through configuring a professional WordPress development environment on Windows, integrating PHP CodeSniffer, WordPress Coding Standards, and Visual Studio Code.


🐘 1. Install & Configure PHP Globally

First, verify if PHP is already installed and accessible globally on your system. Open Command Prompt (cmd) and run:

php -v

If it returns a version number, you can skip to Step 2. If it returns “undefined” or “not found,” follow these steps to install PHP manually.

💡 Note on Local environments: Even if you use Local by Flywheel, its bundled PHP isn’t automatically available globally for command-line tools. Installing a manual version (like PHP 7.3.33 or 7.4) globally is often necessary to prevent command-line errors.

📥 1.1 Download & Extract PHP

  1. Go to the PHP Windows Archives: Navigate to the official archive directory at windows.php.net/downloads/releases/archives/.
  2. Find the Thread Safe Zip: Use Ctrl + F to search for your desired version (e.g., PHP 7.3.33 or 7.4.33). Look for the 64-bit Thread Safe zip file. ⚠️ Make sure you do NOT download the “nts” (Non-Thread Safe) version.
  3. Extract to C:\ Drive: Open your Downloads folder, right-click the Zip file, and select Extract All… Change the extraction destination to C:\php7 (Using a versioned folder name prevents conflicts if you install PHP 8 later). Click Extract.

⚙️ 1.2 Add PHP to Windows Environment Variables

(Crucial step to make the php command work globally)

  1. Press the Windows key, type Environment Variables, and select Edit the system environment variables.
  2. Click the Environment Variables… button at the bottom.
  3. Under System variables, find the Path variable, select it, and click Edit…
  4. Click New and add the path to your extracted folder: C:\php7
  5. Click OK on all three windows to save.

To verify, open a brand new Command Prompt and type:

php -v

📦 2. Install Composer

Composer is the dependency manager for PHP.

📥 2.1 Download & Run Installer

  1. Open Command Prompt: Press the Windows Key, type cmd, and press Enter.
  2. Download the Installer: Windows 11 has curl built-in. Run the following command to download the setup file:
curl -O https://getcomposer.org/Composer-Setup.exe
  1. Run the Installer:
Composer-Setup.exe

⚙️ 2.2 Configuration Setup

  1. When the graphical installer opens, choose Install for all users.
  2. Leave “Developer mode” unchecked and click Next.
  3. Crucial Step (Provide PHP Path): The installer will ask you to choose the command-line PHP you want to use. Browse for or paste the exact path to the php.exe file you configured earlier (e.g., C:\php7\php.exe).
  4. Click through the remaining prompts to finish the installation.

To verify, completely close your current Command Prompt, open a new one, and type:

composer -v

🛠️ 3. Install PHP CodeSniffer & WPCS

With Composer installed, you can now pull in the tools required to validate your WordPress plugin code.

🔍 3.1 Install PHP CodeSniffer (PHPCS)

Run this command to install PHPCS globally:

composer global require "squizlabs/php_codesniffer=*"

To verify installation, open a new Command Prompt and type:

phpcs --version

🛑 3.2 Install WordPress Coding Standards (WPCS)

Run this command to install the WordPress rulesets:

composer global require --dev wp-coding-standards/wpcs -W

To verify the rulesets are recognized by PHPCS, run:

phpcs -i

If the output lists WordPress, WordPress-Core, WordPress-Docs, and WordPress-Extra, you are ready to go.


💻 4. Configure Visual Studio Code

To get real-time code linting and formatting inside your IDE, you need the right extensions and settings.

🧩 4.1 Install Extensions

Open VS Code, go to the Extensions tab (Ctrl + Shift + X), and install:

  1. PHPCS (by shevaua)
  2. PHP Sniffer & Beautifier (by ValeryanM)

⚙️ 4.2 Update settings.json

Open your VS Code Command Palette (Ctrl + Shift + P), type Open Settings (JSON), and add the following configuration parameters to your root JSON object:

{
  "php.validate.executablePath": "C:\\php7\\php.exe",
  "phpcs.standard": "WordPress",
  "phpsab.standard": "WordPress",
  "phpsab.allowedAutoRulesets": [
    ".phpcs.xml",
    ".phpcs.xml.dist",
    "phpcs.xml",
    "phpcs.xml.dist",
    "phpcs.ruleset.xml",
    "ruleset.xml"
  ],
  "[php]": {
    "editor.defaultFormatter": "valeryanm.vscode-phpsab"
  }
}

🚨 5. Troubleshooting & Common Errors

If you run into issues during the setup, check these common fixes:

  1. Local by Flywheel PHP not recognized globally:
    Issue: Terminal commands say php is not found.
    Fix: Local does not easily expose its bundled PHP globally. You must manually install a standalone PHP version and add it to your Windows Environment Variables as outlined in Step 1.
  2. WPCS Dependency Conflict Errors:
    Issue: Composer throws an error about incompatible squizlabs/php_codesniffer requirements.
    Fix: Ensure you include the -W (with all dependencies) flag when installing WPCS: composer global require --dev wp-coding-standards/wpcs -W.
  3. VS Code PHP Validation Error (Executable Path Not Found):
    Issue: VS Code shows an error that it cannot validate PHP because the executable path is missing or incorrect.
    Fix: Double-check your settings.json. The php.validate.executablePath must point exactly to your php.exe file, and you must use double backslashes in JSON (e.g., "C:\\php7\\php.exe").
  4. VS Code Cannot Locate PHP_CodeSniffer:
    Issue: The PHPCS extension in VS Code throws an error stating the phpcs tool could not be found.
    Fix: Make sure Composer’s global vendor bin directory is in your Windows system Path. By default, this is usually C:\Users\YourUsername\AppData\Roaming\Composer\vendor\bin. Restart VS Code completely after updating system variables.

Leave a Comment

Your email address will not be published. Required fields are marked *

Explore ALL Animation Styles
Need Custom WordPress Plugin?
Scroll to Top