hands on If you’re building a website that will eventually be hosted on a Linux server (as so many are), you have a couple of choices about where you do your development work. You can create a beta version of the site at your web host and upload all of the files there or you can create a local test server that sits in your home or office.
The test server could be a separate Linux machine such as a Raspberry Pi or it could be your main PC if you run Linux as your desktop OS. If you’re doing your coding in Windows, you could run a local Windows web server, but that’s not the best simulation of your production environment.
Instead, I recommend using Windows Subsystem for Linux to run a local Linux web server within Microsoft’s OS. That way you can write your code in Windows while running it on the same platform it’s destined for, no second computer or remote server required. Here’s how.
Start by installing Windows Subsystem for Linux 2 (WSL 2). Launch PowerShell (any version) and enter the following:
wsl --install --no-distribution
Next, we’ll install AlmaLinux 9 to use as our Linux distribution. By default, if you don’t install WSL with the –no-distribution option, it will install Ubuntu, but most web hosting platforms use CentOS or AlmaLinux (which is similar to CentOS) so we’re going with that. Find AlmaLinux 9 in the Microsoft Store and click install.
AlmaLinux OS 9 in Microsoft Store – Click to enlarge
Launch the AlmaLinux environment by finding its shortcut icon in Windows Search. Note that the first time you open it, AlmaLinux will ask you to set a username and password.
Set username for AlmaLinux – Click to enlarge
Since you just installed a new Linux instance, it’s time to run an update to get everything up to the latest specs. You do that by entering the following in AlmaLinux:
sudo dnf update
Next, you’ll need to set a password for the root user. Make sure you keep it handy.
sudo passwd root
After that, it’s time to install a control panel app for the web server. Many hosting services use cPanel, but that comes with a licensing fee, so we’re going to use Virtualmin and its companion Webmin (Virtualmin controls the server while Webmin controls each account), which is a free alternative. If you already own cPanel or another app, use that. To install Virtualmin / Webmin, enter:
sudo sh -c "$(curl -fsSL https://software.virtualmin.com/gpl/scripts/virtualmin-install.sh)" -- --bundle LAMP
If, during the process, you are asked for a fully-qualified domain name, you can enter something like host.example.com just to move the process along. We’ll be using the IP address to get to Virtualmin, Webmin, and our local site.
Enter fully-qualified domain name for Virtualmin – Click to enlarge
When the installation is complete, the script will give you an IP address with :10000 at the end. Copy that and paste it into a browser.
Installing Virtualmin – Click to enlarge
The browser will give you a “Your connection is not private” error. Proceed anyway.
“Your connection is not private” error – Click to enlarge
Enter root as the username and the password you assigned to root into the Webmin dialog box. Then sign in.
Webmin login screen – Click to enlarge
Click Next to continue with the Post-Installation Wizard.
Webmin Post-installation wizard – Click to enlarge
Continue to click Next and accept the default settings until you get to the MariaDB password page. Here you might want to change the password to something more memorable. Or, at least, copy the password down.
Set MariaDB password – Click to enlarge
Check “Skip check for resolvability” on the nameserver page. This will ensure that, even if you use a bogus domain name like host.example.com, you can still get into Webmin using the IP address.
Skip check for resolvability – Click to enlarge
Click Add new virtual server.
click add new virtual server – Click to enlarge
Give your new virtual server an admin password and a domain name that doesn’t have any top-level domain (no .com, .edu, etc). I used the domain name “mysite” for this purpose. Then click Create Server.
give your site a name and click Create Server – Click to enlarge
Now, it’s time to install some applications you may need for your website. Navigate to Virtualmin->Manage Web Apps for a list of available apps. I recommend installing phpMyAdmin for database management and WordPress (if you are running a WordPress site).
Navigate to Manage Web Apps in Virtualmin – Click to enlarge
You should now be able to view the home page of your site by navigating to http://YOUR_IP_ADDRESS (in my case this was http://172.26.88.73) and manage the database by going to http://YOUR_IP_ADDRESS/phpmyadmin.
At this point, you may want to make it easier to access the local site by giving it a plain-language name you can use in lieu of its IP. Do this by editing the C:\Windows\System32\drivers\etc\hosts file and including the name you want (ex: mysite) and the IP address.
add your site name to the hosts file – Click to enlarge
Remember that you’ll have to add the http in front of the name (ex: http://mysite) to view the local site in your browser.
Next, you’ll want to locate and set permissions for the public_html directory, which represents the root of your website. Virtualmin creates a user with the domain name of the site you entered when you created a virtual server and, in our case, that’s mysite. So the relevant folder is located at /home/mysite/public_html.
Grant yourself permissions to this folder by entering the following at the Linux command line:
sudo chmod -R 777 /home/mysite
Now, you should be able to access the site’s files in File Explorer by navigating to Linux->AlmaLinux-9->home->mysite->public_html
File Explorer open to public_html folder – Click to enlarge
With the correct permissions in place, you can do the development work for your site and then view what it looks like by going to http://YOUR_IP_ADDRESS or http://mysite. Just make sure to keep an AlmaLinux WSL terminal window open or the webserver won’t run. ®