In an era where web development is continuously evolving, having a hands-on test environment is paramount for developers and aspiring webmasters. Enter the Windows Subsystem for Linux (WSL), particularly in Windows 11, allowing users to create a robust local web server. If you've ever wished to build a website destined for a Linux host while nursing a Windows PC, you're in luck. This guide will talk you through the steps of setting up a local Linux web server using AlmaLinux 9 and Virtualmin as your control panel, all from the convenience of a Windows window.
This command will enable WSL and install a default Linux environment.
This ensures that you have the latest packages and security updates.
Make sure to review the script content with:
Doing this allows you to access the files using Windows Explorer and edit them with your favorite Windows code editors.
So fire up your command prompt and get started on that project you've been dreaming about. Happy coding!
Source: Tom's Hardware https://www.tomshardware.com/software/linux/how-to-run-a-local-linux-web-server-running-in-a-windows-11-window
Why Use WSL for a Linux Web Server?
WSL provides a seamless integration of Linux within the Windows ecosystem, allowing developers to leverage Linux tools right from their desktop. This compatibility is pivotal, especially since most web hosting environments run on Linux systems.Benefits of Running a Local Web Server
- Testing Grounds: Perfect for developing PHP, MySQL, and other web applications locally without deploying them to a live environment.
- Easier Debugging: Makes it easier to troubleshoot and optimize your code without affecting a production site.
- Familiar Tools: Allows users to use familiar Windows applications like Notepad++ alongside Linux functionality.
Steps to Set Up Your Server
1. Installing WSL
Start by launching a PowerShell prompt and enter the following command:
Bash:
wsl --install
2. Installing AlmaLinux OS
Next, install the AlmaLinux OS 9 from the Microsoft Store. After installation, you’ll create a new user by setting a username and password. AlmaLinux is selected for its widespread use in web hosting and similarity to CentOS.3. Updating Packages
Keep your Linux environment up to date by running:
Bash:
sudo dnf update
4. Setting Root Password
For administrative tasks, set a root password:
Bash:
sudo passwd root
5. Installing Virtualmin
To manage your web server effortlessly, we’ll use Virtualmin. First, download the installation script:
Bash:
wget -O install.sh https://raw.githubusercontent.com/virtualmin/virtualmin-install/master/virtualmin-install.sh chmod a+x install.sh sudo ./install.sh
Bash:
less install.sh
Note on Security
It’s essential to trust the source of any installation script. Always inspect it to mitigate risks.6. Accessing Virtualmin
After installation, navigate to the URL provided during the setup (your machine's name or IP address appended with:10000
) to access the Virtualmin control panel. Log in with the root credentials.7. Post-Installation Wizard
Follow through the Post-Installation wizard, leaving most settings at their default values. However, it's recommended to change the MariaDB password to something memorable.8. Creating Your First Virtual Server
After configuring, click on "Add new virtual server." Here, you’ll assign a domain name and set up an admin password and username.9. Installing Applications
With your virtual server created, you can install web applications directly from Virtualmin. Use theManage Web Apps
feature to select popular applications like PhpMyAdmin or WordPress, facilitating easier content management.10. Configuring Hosts File
To simplify access to your new server, edit thehosts
file located at C:\Windows\System32\drivers\etc\hosts
. Add a new entry with your server's IP followed by the desired local domain for easier access.11. Setting Permissions
Make sure to set appropriate permissions for editing files. Navigate to your public_html directory and grant read and write access:
Bash:
sudo chmod -R 777 /home/[USERNAME]/public_html
12. Testing Locally
Once set up, you can access your website by typing the assigned local domain or IP address into any web browser. You can manage your site and databases easily with:[url="http://mysite%5B/ICODE%5D(http://mysite%5B/ICODE"]http://mysite
(http://mysite%5B/ICODE[/url]) - for the homepage[url="http://mysite:10000%5B/ICODE%5D(http://mysite:10000%5B/ICODE"]http://mysite:10000
(http://mysite:10000%5B/ICODE[/url]) - for Virtualmin Control Panel[url="http://mysite/phpmyadmin%5B/ICODE%5D(http://mysite/phpmyadmin%5B/ICODE"]http://mysite/phpmyadmin
(http://mysite/phpmyadmin%5B/ICODE[/url]) - for database management
13. Keeping Your Instance Active
Remember, for your local web server to be functional, ensure that the AlmaLinux instance is running within your Windows environment.Conclusion
Creating a local Linux web server on Windows 11 through WSL not only opens up a plethora of development possibilities but also provides an efficient environment to test and manage websites with tools like Virtualmin. This setup is a gem for web developers looking to marry the worlds of Linux and Windows without losing functionality or comfort.So fire up your command prompt and get started on that project you've been dreaming about. Happy coding!
Source: Tom's Hardware https://www.tomshardware.com/software/linux/how-to-run-a-local-linux-web-server-running-in-a-windows-11-window