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
- Go to the PHP Windows Archives: Navigate to the official archive directory at windows.php.net/downloads/releases/archives/.
- Find the Thread Safe Zip: Use
Ctrl + Fto 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. - 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)
- Press the Windows key, type Environment Variables, and select Edit the system environment variables.
- Click the Environment Variables… button at the bottom.
- Under System variables, find the
Pathvariable, select it, and click Edit… - Click New and add the path to your extracted folder:
C:\php7 - 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
- Open Command Prompt: Press the Windows Key, type
cmd, and press Enter. - Download the Installer: Windows 11 has
curlbuilt-in. Run the following command to download the setup file:
curl -O https://getcomposer.org/Composer-Setup.exe
- Run the Installer:
Composer-Setup.exe
⚙️ 2.2 Configuration Setup
- When the graphical installer opens, choose Install for all users.
- Leave “Developer mode” unchecked and click Next.
- 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.exefile you configured earlier (e.g.,C:\php7\php.exe). - 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:
- PHPCS (by shevaua)
- 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:
- Local by Flywheel PHP not recognized globally:
Issue: Terminal commands sayphpis 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. - WPCS Dependency Conflict Errors:
Issue: Composer throws an error about incompatiblesquizlabs/php_codesnifferrequirements.
Fix: Ensure you include the-W(with all dependencies) flag when installing WPCS:composer global require --dev wp-coding-standards/wpcs -W. - 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 yoursettings.json. Thephp.validate.executablePathmust point exactly to yourphp.exefile, and you must use double backslashes in JSON (e.g.,"C:\\php7\\php.exe"). - VS Code Cannot Locate PHP_CodeSniffer:
Issue: The PHPCS extension in VS Code throws an error stating thephpcstool could not be found.
Fix: Make sure Composer’s global vendor bin directory is in your Windows systemPath. By default, this is usuallyC:\Users\YourUsername\AppData\Roaming\Composer\vendor\bin. Restart VS Code completely after updating system variables.