WSL
WSL (WSL 2) – Windows Subsystem for Linux – is a compatibility layer for running Linux binary executables natively on Windows 10 and later. Currently, it supports several Linux distributions, such as Ubuntu, OpenSUSE, and SLES.
note
You can also try to use Remote Development to configure WSL.
Download and install a WSL distribution (for instance, Ubuntu) from Microsoft Store.
For this step, be sure to use at least Windows 10 or later with the latest “Fall Creators Update” (minimum version 1709, build 16299.15). See the official guide Install the Windows Subsystem for Linux for instructions.
To work with WSL 2, your Windows version should be 10 build 18917 or later. Follow these instructions to switch the distributive.
Note that PhpStorm does not support legacy WSL, which you may have installed before upgrading your system to the build 16299.15 or later of Windows 10. In this case, you need to update your WSL distribution.
Run the Linux distribution.
Upon the first launch, the system may prompt you to enable the Windows optional feature. In this case, you need to do the following:
Open Windows PowerShell as Administrator and run
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Restart your computer.
note
If you are using Linux distribution other than Ubuntu, ensure that the distribution has the iproute2 package installed or install it manually once the WSL instance is deployed.
Inside the Linux installation, make sure PHP is installed. For the detailed installation instructions, refer to Debian GNU/Linux installation notes. If you are using Ubuntu, you can run this command in the Terminal to quickly install PHP:
sudo apt install php php-mbstring php-xml php-zip php-curl php-xdebug
Configure a WSL-based remote interpreter as described in Configure remote PHP interpreters. You can appoint the created interpreter for all common tasks: executing scripts or Composer commands, running PHP Quality tools, and so on.
In PhpStorm, you can directly open a project stored in the WSL file system and work with it like with any other project.
Click Open on the Welcome screen or select File | Open from the main menu.
In the Select Path dialog that opens, select the folder in the WSL file system that contains the project to open, or type the path to the
\ project location manually.\wsl$
tip
PhpStorm supports Git from the Windows Subsystem for Linux 2 (WSL2), which is available in Windows 10 version 2004.
If Git is not installed on Windows, PhpStorm searches for Git in WSL and uses it from there. Also, PhpStorm automatically switches to Git from WSL for projects that are opened when you use the
\ path.\wsl$ For more information about working with Git in PhpStorm, refer to Git.
You need to perform the following steps to ensure that the building of a project works properly.
Run the Windows PowerShell as administrator.
Execute the following command to allow connections using WSL:
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
Then execute the command to renew the firewall rules:
Get-NetFirewallProfile -Name Public | Get-NetFirewallRule | where DisplayName -ILike "IntelliJ IDEA*" | Disable-NetFirewallRule
note
If you are using another IDE, replace
IntelliJ IDEA*
with its name.Now start the debugger session. When the Windows Firewall popup appears, select the Public networks checkbox.
Thanks for your feedback!