Skip to main content

Lightning speed development on Windows 10 with WSL 2, Docker, Terminal and Jetbrains IntelliJ/PyCharm/PHPStorm

·5 mins

Untill this year, I mainly developed on a MacOS system when working for my own business. The development experience on MacOS was a lot better than developing on a Windows system because of the special needs that comes with web development. PHP, MySQL and a web server like Nginx, just work better on Linux based systems. The advantage of MacOS is that you are able to install all software locally using Homebrew. On Windows you need a Linux Virtual Machine to install Linux software. Mounting source code into a Linux Virtual Machines causes very poor I/O performance, especially when you work on large projects with a lot of (composer) packages and (frontend) libraries. Docker resolves some of these issues, but Docker on Windows is still running on a Hyper-V Virtual Machine. Mounting source code into a Docker container still causes very poor performance. Fortunately, WSL 2 enables us to resolve these issues by running Docker in WSL 2 aswell as your favorite Jetbrains IDE!

My setup

Hardware

I develop on a Lenovo Yoga AMD Ryzen 4800U laptop with 16 GB of memory and 512 GB of NVME SSD. This laptop combines a lot of processing power with excellent battery performance in a tiny slimbook. I like!

Software

The minimum software I use for development tasks are WSL 2 with Ubuntu 20.04 LTS installed, Docker for Windows on WSL 2, Microsoft Terminal and Jetbrains IntelliJ, PyCharm and PHPStorm. The IDE's are running inside WSL 2 to have the best performance possible.

Installation manual

Start by installing the Windows features Windows Subsystem Linux and Virtual Machine Platform on your system. Open a Powershell shell as administrator and execute the two commands below.

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Reboot your system, otherwise you will experience issues.

After the system has rebooted, set WSL 2 as default.

wsl --set-default-version 2

Open the Microsoft Store and install Ubuntu 20.04 LTS, Terminal, and X410. X410 is not free, and some free alternatives are available (Google is your friend), but X410 just works and it costs only € 10,-.

"Open" Ubuntu 20.04 LTS by clicking on the icon in the start menu. The first time, Ubuntu installs itself in WSL 2 and asks your to create a user. This user is used in WSL 2 and the password is used to become root using sudo.

Start X410 (it won't start automatically) and configure it to allow public access (right mouse button on the icon in task bar). Then, permit access through the Windows Firewall. If the firewall is not configured correctly, X410 won't work in WSL 2. If you encounter any issues with X410, or you want to automatically start it on boot, check out the X410 cookbook.

Open Microsoft Terminal and open a new tab connecting to WSL 2 (CTRL+SHIFT+3).

Configure WSL 2 to use X410 by adding the following line in ~/.bashrc (create this file if it doesn't exist).

export DISPLAY=$(awk '/^nameserver/ {print $2; exit;}' </etc/resolv.conf):0.0

To be able to run Docker containers we need Docker for Windows. Get it from Docker Hub and install it.

When you're running Windows 10 Home, WSL 2 integration is automatically enabled because this edition of Windows doesn't support Hyper-V. When running Windows 10 Pro or higher, enable WSL 2 on the Docker settings page. For both editions, go to the Docker settings resources page and enable integration for the Ubuntu distro.

Check in your terminal if you can access the Docker engine.

docker ps

It should return an empty table.

CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Try to run a Docker container to test if everything works as expected.

To actually develop, we need an IDE. I'm a huge fan of Jetbrain InelliJ, Pycharm and PHPStorm and all those IDE's can be installed on WSL 2. The main reason we install the IDE in WSL 2 is because of performance. While you are able to use source code located on Windows in WSL 2, the performance is not great. Visa versa, using source code located in WSL 2 on Windows, uses a CIFS mount which is not recommended by Jetbrains.

Download the latest PHPStorm, PyCharm or IntelliJ version from the Jetbrains website directly into Ubuntu. In this example I'm using PHPstorm, but the installation process is the same for Pycharm and IntelliJ.

wget https://download.jetbrains.com/webide/PhpStorm-2020.3.2.tar.gz

Create a new directory in /opt and extract the tarball in it.

sudo mkdir -p /opt/phpstorm
sudo tar -xzvf PhpStorm-2020.3.2.tar.gz -C /opt/phpstorm

Check that X410 is running and launch PHPstorm.

/opt/phpstorm/PhpStorm-203.7148.74/bin/phpstorm.sh

If X410 and the firewall are configured correctly, PHPStorm will start a new X410 window and you're good to go!

I created an alias in my .bashrc file so I'm able to launch PHPstorm without I have to remember the full path to the sh file.

alias phpstorm='/opt/phpstorm/PhpStorm-203.7148.74/bin/phpstorm.sh > /dev/null 2>&1 &'

To improve performance (and to fix the file sync complaints by PHPStorm), install inotify and increase the max amount of file watches in /etc/sysctl.conf.

sudo apt install inotify-tools
sudo sh -c "echo \"fs.inotify.max_user_watches = 524288\" >> /etc/sysctl.conf"
sudo sysctl -p

Now, you're ready to start developing! But... the Microsoft Terminal could be configured a bit better. I'm a fan of Oh My Zsh and found this blog post of NillsF very interesting.

Happy developing!

Optional

Scaling on high DPI screens

On some systems you might have scaling issues. To resolve this, add the following two lines to your .bashrc.

export QT_SCALE_FACTOR=2
export GDK_SCALE=2

Extra packages to enable PHPstorm preview functionality

If you want to use the markdown (or other markup language) preview functionality, you need some additional packages installed.

sudo apt install libnss3 libatk-bridge2.0-0 libxcursor1 libgbm1 libxss1 libpangocairo-1.0-0 libscups2