Windows Subsystem for Linux

The Windows Subsystem for Linux lets developers run GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a virtual machine.

You can:

Choose your favorite GNU/Linux distributions from the Windows Store.

Run common command-line free software such as grep, sed, awk, or other ELF-64 binaries.

Installing Windows Subsystem for Linux

The installation of Windows Subsystem for Linux is well described by Microsoft's own document Install the Windows Subsystem for Linux.
Instead of the standard Ubuntu distro mentioned in the installation guide, search for and choose the latest Ubuntu 18.04 LTS.

To initialize and update the Ubuntu installation follow Initializing a newly installed distro.
This step may be skipped if you have already initialized the Ubuntu distro in the previous step.

An important aspect of WSL is that Windows tools are not able to access files stored inside Ubuntu. However, Ubuntu can (almost) freely read/write the Windows filesystem. Therefore, files that need to be accessed by Windows tools (e.g. your IDE, Backup) need to be stored on the Windows filesystem.

When accessing the Windows filesystem from within the bash shell, you need to prepend the path with /mnt/c/. Although not required, it is best to use the exact same file path casing when creating symlinks.

Installing Apache

Use the following command in the bash shell to install Apache:

$ sudo apt install apache2

The terminal used by WSL does not support the pasting of text as you are used to. Use right-click for pasting.

Create a project folder for your websites. For reasons mentioned above, this folder needs to be outside of the WSL filesystem. You could use for example: C:/Users/<Username>/Documents/Development/Web/webroot, or simply C:/webroot.

In Ubunto, create a symbolic link to the webroot folder.

$ sudo ln -s /mnt/c/your/path/to/webroot /var/www/webroot

Open the Apache default virtual host configuration file:

$ sudo nano /etc/apache2/sites-available/000-default.conf

Remove existing content by keeping the Shift-key pressed and scroll down using the ↓-key. Then press Ctrl+K to cut the selection.

Installing XDebug (optional)

If you are a developer and want to develop your own plugins and themes, you probably inevitably need to debug your code at some point...

Install XDebug using the following command:

$ sudo apt install php-xdebug

XDebug needs to be enabled in php.ini.
Open the editor:

$ sudo nano /etc/php/7.2/apache2/php.ini

And add the following lines to the end of the file:

[XDebug]
xdebug.remote_enable = 1

In Nano, you can use Alt+/ to jump to the bottom of the file.

Restart Apache again:

$ sudo service apache2 restart

Activating debugger

In order to start debugging, you first need to activate the debugger on the server. For this, you need to set a special GET/POST or COOKIE parameter. You can do that manually, but it is much more convenient to use a browser extension. It allows you to enable the debugger with the click of a button. When the extension is active, it sends the XDEBUG_SESSION cookie directly, instead of going through XDEBUG_SESSION_START. Below you can find a table with the link to the relevant extension for your browser.

Adding extra virtual hosts (optional)

During the different stages in the lifecycle of our site (development, testing, production) different Grav configurations may be needed. Take for example caching or asset pipelines. You might want to switch them off during development and switch them on when testing performance. For more information see the documentation on Automatic Environment Configuration.

Start an editor as Administrator and open file C:/Windows/System32/drivers/etc/hosts.
You could, for example, add the following hosts:

127.0.0.1 mysite-dev
127.0.0.1 mysite-prod

Hosts defined in Windows hosts file will automatically be available in /etc/hosts in WSL/Ubuntu.

Now you can point the browser to http://mysite-dev and it will open the Grav installation at C:/your/path/to/webroot/mysite using the config files in folder /user/mysite-dev/config/.

Automatically start Apache (optional)

For starting and stopping Apache, elevated privileges are required. And to be granted the elevated privileges, a password is requested. To prevent Ubuntu asking for a password you can grant yourself permanent elevated privileges for certain services.

Multiple websites, one Grav codebase

If you are like me and have multiple Grav websites deployed for separate projects, you might want to read the documentation on Symbolic Links and on Copying a Project to create a symlinked copy of a single Grav core.