A collection of commands I find useful for running Windows Subsystem Linux.
This is best done from PowerShell.
wsl --shutdown
Then simply log back in from the terminal.
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
.
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>
Ideally these would start when you first start WSL and can be set up in /etc/wsl.conf
under the [boot]
section. More information https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configure-settings-with-wslconfig-and-wslconf
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.
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
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
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
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
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
To find the IP address, enter the following:
ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1
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:
http://[::1]/
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]
.
In the files of /etc/hosts
and /Windows/System32/drivers/etc/hosts
. Add the following:
127.0.0.1 example.test
::1 example.test localhost
From https://github.com/microsoft/WSL/issues/5728, viewed 28-Oct-2022.
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.
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.
Action | Keys |
---|---|
Command screen go full size | Control + o |
Copy current file to command line | Alt + Enter |
A very useful editor which has a steep learning curve.
Action | Keys |
---|---|
Over write mode | Shift + R |
Replace current single character and then return to command mode. | r (just press the "r" key) |
doc/filePanels/hotkeys – Midnight CommanderCollection of hot keys when using Midnight Commander. | |
How to Access Your Linux (WSL) Files in Windows 10Windows 10’s May 2019 Update introduced an easy, safe, and officially supported way to access and work with your Linux files from within File Explorer and other applications. Here’s how to get at your Windows Subsystem for Linux (WSL) files. | |
How to create symbolic links in UbuntuA symbolic link is a shortcut file for any directory or file. The symlink or soft link are the other names of the symbolic link. In Ubuntu, symbolic links work like a string that generates paths between various files and directories. | |
How To Install and Secure phpMyAdmin on Ubuntu 20.04 | DigitalOcean | |
How to Install phpMyAdmin on Windows WSL with Apache - Website for Students | |
How to Install WordPress on Windows WSL - Geek RewindThis brief tutorial shows students and inexperienced users how to install WordPress on Windows 10 WSL (Windows Subsystem for Linux) 2 with Nginx HTTP server on Ubuntu 20.04 | 18.04. | |
Importing & Exporting WSLImport any Linux distribution to use with WSL | Microsoft Docs | |
Linux Commands - A practical referenceThis is a linux command line reference for common operations. | |
Rebooting WSLHow to Reboot WSL (Windows subsystem Linux) in Windows 10 or 11 - H2S Media | |
Tutorials | DigitalOceanUseful tutorials for working with computer systems. | |
WSL NewsWhat’s new for WSL in Windows 10 version 1903? - Windows Command Line |
Featured photo by Sora Shimazaki from Pexels
You must be logged in to post a comment.