WSL Commands and Notes

A collection of commands I find useful for running Windows Subsystem Linux.

Managing WSL Linux

Reboot Linux

This is best done from PowerShell.

wsl --shutdown

Then simply log back in from the terminal.

Backing Up your Linux on Windows Installation

Windows 10 v1903 includes a built-in WSL export/import command. Specifically, wsl --export, which produces a tar file and wsl --import, which imports a previously exported tar file. You can then move this file between computers.

See https://docs.microsoft.com/en-us/windows/wsl/use-custom-distro for more information.

You can also specify stdin/stdout with -, which should allow you to directly transfer to another machine and import using a remote shell like ssh.

Restoring Linux

This doesn’t work the way you expect, that is, restore the files to the original location (under user/AppData/Packages). Instead a disk image file is created under <InstallLocation>, for example D:\wslDistroStorage\Ubuntu-20.04\ext4.vhdx. This is probably better as it’s now easier to back up your Linux installation. Note that <DistroName> must not already exist.

wsl --import <DistroName> <InstallLocation> <InstallTarFile>

HTML Hosting Services

Ideally these would start when you first start WSL and can be set up in /etc/wsl.confunder the [boot] section. More information https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configure-settings-with-wslconfig-and-wslconf

Installing Apache

If not installed this will be need to be done.

Update your system first:

sudo apt update

Next, install Apache:

sudo apt install apache2

Next, start the server with the following command:

sudo /etc/init.d/apache2 start

Go to localhost/ and you should see the Apache default page.

Starting Apache web server:

The following are useful for managing the Apache service.

sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 restart

User Web Directories

If user web directories are required, that is http://localhost/~username is accessible, do the following:

$ ln -s /etc/apache2/mods-available/userdir.conf /etc/apache2/mods-enabled/userdir.conf
$ ln -s /etc/apache2/mods-avaliable/userdir.load /etc/apache2/mods-enabled/userdir.load

Not Enough Upload File Size Error

If you run into the problem with not enough upload file size change the following line in /etc/php/7.4/apache2/php.ini. Search for the setting first and change it, otherwise add a new line to the file.

upload_max_filesize = 100M

See also https://phoenixnap.com/kb/fix-the-uploaded-file-exceeds-the-upload-max-filesize-directive-in-php-ini-wordpress.

Installing MySQL

Likewise for Apache, if MySQL is not present on your system install it with the command below:

sudo apt install mysql-server

An alternative to MySQL is to install MariaDB, which is an open source drop in replacement for MySQL:

sudo apt update
sudo apt install mariadb-server
sudo mysql_secure_installation

Managing MySQL server:

sudo /etc/init.d/mysql start
sudo /etc/init.d/mysql restart
sudo /etc/init.d/mysql stop


An excellent way to manage the database is to use PHPmyadmin. It can be installed with:

sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl

Find WSL’s IP address

To find the IP address, enter the following:

ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1

Point a Domain to WSL

This is an excellent way to set up WordPress websites using a domain. Some plug-ins, like Oxygen Builder, have problems working with a URL and a subfolder.

To access the local server, use the following:


To use the actual IP address determine the address using:

ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1

Then use this as https://[ip-address].

Using the Hosts File

In the files of /etc/hosts and /Windows/System32/drivers/etc/hosts. Add the following: example.test
::1 example.test localhost

From https://github.com/microsoft/WSL/issues/5728, viewed 28-Oct-2022.

Using Bind

I didn’t much success with this and it may be more trouble than it’s worth. See https://ubuntu.com/server/docs/service-domain-name-service-dns on how to do it.

Midnight Commander

Hot Keys

Windows Terminal may have overridden some of Midnight Commander’s hot keys, like Alt+Enter for example, which copies the current file to the command line. To change it go to Settings/Actions and search for Alt+Enter. Change it to another key combination.

Command screen go full sizeControl + o
Copy current file to command lineAlt + Enter


A very useful editor which has a steep learning curve.

Over write modeShift + R
Replace current single character and then return to command mode. r (just press the “r” key)

More Information

Featured photo by Sora Shimazaki from Pexels

Leave a Reply

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram