If you’re building a website or programming web tools using PHP, MySQL or other common languages, it helps to have a test site you can run on your local PC. However, most web hosting services, including thebest web hosting services, use Linux, not Windows as their hosting environments. But what if you have a Windows PC and want to build a site that’s going to live on a Linux server?

We have good news. UsingWindows 11or 10’s built-in Windows Subsystem for Linux (WSL) service, you can create a local Linux web server that you can use locally for testing and building a site. You simply run Linux in a window and then you can visit the website in your Windows-based web browser and edit the key HTML, PHP or other files in a Windows-based editor (ex:Notepad++, my fave). You can even navigate your Linux server’s file system using Windows Explorer.

local Linux web server in Windows

Below, we’ll show you how to create a local Linux web server running in WSL. We’ll use AlmaLinux 9 rather than Ubuntu because AlmaLinux is one of the most commonly used server operating systems for web hosts and it’s similar to CentOS which is also used by many hosts. Our server control panel will be Virtualmin, because it’s a free, easy-to-use control panel. Many people prefer cPanel, but a license for cPanel costs money.

1.Install WSL(Windows Subsystem for Linux) if you don’t have it installed already. You do this by enteringwsl –installat a PowerShell command prompt.

Install WSL

2.InstallAlmaLinux OS 9for WSL. It’s available in theMicrosoftStore.

During this process, you will need to create a username and password for your AlmaLinux instance.

3.Update the Linux environmentwith the latest packages.

Get Tom’s Hardware’s best news and in-depth reviews, straight to your inbox.

4.Set a password for the root user.

5.Install VirtualMinby issuing the following commands. The downloaded file is a shell script that will run a series of commands. It is not best practice to install software via this method if the source is not trusted. You can read the contents of the script by typingless install.shafter it has been downloaded.

5.Navigate to the URL it gives youin your browser (either your machine name or IP address with :10000 at the end)

AlmaLinux OS 9

6.Log in as rootwith the password you created.

7.Navigate through the Post-Installation Wizard, leaving defaults except as noted below.

I recommend changing the MariaDB password to something easier to remember than the default.

navigate to URL

Toggle “Skip check for resolvability"to on for the Primary nameserver

8.Click Add new virtual server.

9.Give your site a domain name, admin passwordandadmin user.You may or may not need the username and password as you may prefer to remain logged in as root.

10.Install Phpmyadmin and / or Wordpressby navigating to Virtualmin -> Manage Web Apps, selecting them andclicking Show Install Optionsthen choosing install options or accepting the defaults.

log in as root

You should now be able to manage your databases by going to http://IPaddresss/phpmyadmin in your browser (ex: http://172.18.231.63/phpmyadmin in my case).

11.Assign a host name to your IPin C:\Windows\System32\drivers\etc\hosts. You do this by adding the IP address, hitting tab and then entering the plain-English name you want to use to access your site. This isn’t necessary as you can always just go to the IP address in your browser, but it makes browsing your local site a little easier.

navigate through post-installation wizard

13.Give all users read and write access to your public_html directoryso you may access all of the websites' folders via Windows Explorer.

If you set up a virtual server with a user that owns it – in my case, I called that user “thuser” – the folder containing the website files is /home/[USERNAME]/public_html (ex: /home/thuser/public_html). That’s where you’ll find the index.html file that has the default home page for your site.

MariaDB password

If, for some reason, you set up the virtual server to run under the root user, the files for the site will be located in /var/www. But, if you followed the instructions above, they are in /home/[USERNAME]/public_html.

There’s just one problem. If you attempt to navigate to /home/thuser/public_html in Windows Explorer, you get an error message like the one below.

skip check for resolvability

To fix this problem, you must entersudo chmod -R 777 [PATH]at the AlmaLinux command prompt. For example.

That will make the entire home folder available in Windows Explorer. Then you may use your favorite Windows code editing software – Notepad++ for example, to open and edit files there.

click add new virtual server

Now you can work on your site and test it on your local PC. You can navigate to it in your browser either by going to the IP address or domain name you chose (ex: mysite). You can edit the files using Windows editing software and access the database by going to http://mysite/phpmyadmin.

Use the following addresses to get to where you need to.

add domain name, admin password, username

In order for this test site to work, you need to make sure that there’s an AlmaLinux-9 window open in Windows. Otherwise, the web server won’t work.

Avram Piltch is Managing Editor: Special Projects. When he’s not playing with the latest gadgets at work or putting on VR helmets at trade shows, you’ll find him rooting his phone, taking apart his PC, or coding plugins. With his technical knowledge and passion for testing, Avram developed many real-world benchmarks, including our laptop battery test.