For developers working with PHP, MySQL, or other popular programming languages, having a local testing environment is essential. While many web hosting services operate on Linux, Windows users may find themselves at a crossroads when trying to build a site destined for a Linux server. Fortunately, Windows 10 and 11 offer a solution through the Windows Subsystem for Linux (WSL), enabling users to create a local Linux web server directly on their PCs.
Setting Up Your Local Linux Server
To get started, you can install AlmaLinux OS 9 from the Microsoft Store. Once installed, you’ll need to set up a username and password for your AlmaLinux instance. The next step is to ensure your Linux environment is up-to-date by running:
sudo dnf update
After updating, set a password for the root user with the following command:
sudo passwd root
Next, install VirtualMin by executing a series of commands. This process involves downloading a shell script that will automate the installation. To view the contents of the script before running it, you can type:
less install.sh
Then, proceed with the installation using:
wget -O install.sh https://raw.githubusercontent.com/virtualmin/virtualmin-install/master/virtualmin-install.sh
chmod a+x install.sh
sudo ./install.sh
Once the installation is complete, navigate to the URL provided in your browser, which will typically be your machine name or IP address followed by :10000.
Log in as root using the password you created earlier. You will then be guided through the Post-Installation Wizard. It’s advisable to change the default MariaDB password to something more memorable. Additionally, toggle the “Skip check for resolvability” option for the Primary nameserver to ‘on’ and click to add a new virtual server.
When prompted, provide a domain name, admin password, and admin user details. You can opt to remain logged in as root if preferred. To enhance your setup, consider installing PhpMyAdmin or WordPress through the Virtualmin interface by selecting your preferred options.
Accessing Your Local Site
After installation, you can manage your databases by visiting http://IPaddress/phpmyadmin in your browser. To simplify access, assign a hostname to your IP in the hosts file located at C:WindowsSystem32driversetchosts. This step is optional but can make navigation more user-friendly.
To ensure that all users have read and write access to your public_html directory, execute the following command:
sudo chmod -R 777 /home/[USERNAME]
With this configuration, you can easily access your website files through Windows Explorer, allowing you to edit them using your preferred Windows code editor, such as Notepad++.
As you work on your site, you can test it locally by navigating to either the IP address or the domain name you assigned. The following addresses will guide you through your local setup:
Address (assuming mysite as name) | Use |
---|---|
http://mysite | Home page |
http://mysite:10000 | Virtualmin Control Panel |
http://mysite/phpmyadmin | Database Management |
wsl.localhostAlmaLinux-9homethuserpublic_html | Home page folder in Windows Explorer |
Remember, for your test site to function correctly, ensure that an AlmaLinux-9 window is open in Windows, as the web server relies on it to operate smoothly.