A Windows subsystem for Linux…
… or how to have a Linux server inside Windows by installing a version of Ubuntu Server from the Windows store.
For some years now, Windows have included a compatibility system to natively execute Linux within Windows 10 and, if I remember correctly, it was also possible in Windows Server since the 2019 version.
The installation process of a Linux Server is very simple and it takes two steps:
First, we need to install the Windows subsystem for Linux from the control panel.
Once it is installed, we can go to the Windows Store. From the Windows Start Menu, we search the Microsoft Store, if it is not available in the task bar (usually it is pinned by default).
Inside the store, we search for Ubuntu and from the list of suggestions we select the last version. In this example, it is version 20.04. Then, we click on “Get” to start the installation:
The installation process is very quick and once it is over, we can click the Init button that appears in the top-right corner and the Linux terminal will come out. After the installation it is going to ask us to create a user and password to access the system.
Once this is done, and we are inside the linux console, we already have a system with Ubuntu Server installed in Windows 10.
And what can we do now?
We have just installed an Ubuntu Server and, therefore, we can do everything or almost everything we could do if we install it in a Cloud or in a Hosting Service. We must take into consideration that they are not production serverservers, but are perfectly suitable for development. In this way, we avoid installing virtual machines or docker containers.
For example, we can install an Apache2 server, php and MySQL and access to the services they offer from windows. To do so, we write in the Windows console the following command:
sudo apt install apache2 php
We press return and the system will ask you the password. Then, it installs Apache2 and PHP. When it is done, we can go to the directory /var/www/html, and we will see that there is a file named index.php, and that is the default file for the Apache installation. Before using it, we need to start the server using the following command:
sudo /etc/init.d/apache2 restart
And allow access to the system from Windows.
Now from Windows, we write in the address bar of Edge web browser the following address, http://localhost/, and the example web page of Apache2 server will appear. If we do not believe we are accessing to Linux from Windows, we can create a new file in the route /var/www/html/, for example, named “pruebas.html” and writing inside the file “HELLO LINUX”. To create the file from the terminal, we execute the following command:
sudo echo “HELLO LINUX” | sudo tee -a /var/www/html/pruebas.html
and now we can write in the web browser: http://localhost/pruebas.html
Two important information about the Ubuntu Installation in Windows:
From Linux, we have access to the Windows routes to the disks we have already installed. We can access the route.
Here we can observe the units c:/ d:/ f:/ … and all the others we have in our system.
In the same way, from Windows we can access the Linux file system from the route.
In this way, we can work with the same files from the two systems very easily.
Truth be told, this Microsoft option of supporting Linux from Windows 10 is very comfortable and useful to perform developments and/or get familiar with Linux Systems.
More articles of Alex Arenols – English version – Spanish version