Jump to content

How to run a local Linux web server running in a Windows 11 window


Recommended Posts

  • Author

How to run a local Linux web server running in a Windows 11 window

How to run a local Linux web server running in a Windows 11 window

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 the best 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. Using Windows 11 or 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.

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 entering wsl –install at a PowerShell command prompt.

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Tom’s Hardware)

2. Install AlmaLinux OS 9 for WSL. It’s available in the Microsoft Store.

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Tom’s Hardware)

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

3. Update the Linux environment with the latest packages.

sudo dnf update

4. Set a password for the root user.

sudo passwd root

5. Install VirtualMin by 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 typing less install.sh after it has been downloaded.

wget -O install.sh 

chmod a+x install.sh
sudo ./install.sh

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

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Tom’s Hardware)

6. Log in as root with the password you created.

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Future)

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

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Future)

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

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Future)

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

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Future)

8. Click Add new virtual server.

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Future)

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

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Future)

10. Install Phpmyadmin and / or Wordpress by navigating to Virtualmin -> Manage Web Apps, selecting them and clicking Show Install Options then choosing install options or accepting the defaults.

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Future)

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

11. Assign a host name to your IP in 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.

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Future)

13. Give all users read and write access to your public_html directory so you can 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.

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 try to navigate to /home/thuser/public_html in Windows Explorer, you get an error message like the one below.

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Future)

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

sudo chmod -R 777 /home/thuser

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

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

(Image credit: Future)

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.

Swipe to scroll horizontally
Address (assuming mysite as name) Use
http://mysite Home page
http://mysite:10000 Virtualmin Control Panel
http://mysite/phpmyadmin Database Management
\\wsl.localhost\AlmaLinux-9\home\thuser\public_html Home page folder in Windows Explorer

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.



Source link

#run #local #Linux #web #server #running #Windows #window

📬Pelican News

Source Link

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Cookie Consent & Terms We use cookies to enhance your experience on our site. By continuing to browse our website, you agree to our use of cookies as outlined in our We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.. Please review our Terms of Use, Privacy Policy, and Guidelines for more information.