How to Configure Apache in WSL for Access from Other Devices on same network


This guide explains how to set up Apache in WSL (Windows Subsystem for Linux) so it can be accessed from both Windows and other devices on the same network.
WSL is installed, and you have an Ubuntu distribution set up.root and create a new user.WSL:
sudo apt update
sudo apt install openssh-server
SSH service is running:
sudo service ssh status
If the service is not running, start it with:
sudo service ssh start
SSH on BootSSH to start on boot:
sudo systemctl enable ssh --now
ssh service status:
service sshd status
IP Address of WSL:
ip addr
Note the
IP addressfor the next step.
Windows Terminal with administrator privileges and run:
netsh interface portproxy add v4tov4 listenport=22 listenaddress=0.0.0.0 connectport=22 connectaddress=[wsl_ip_address]
netsh interface portproxy show all
Run wf.msc to open Windows Advanced Firewall:
22.Find the IP address of the Windows machine:
ipconfig
ssh username_or_root@[windows_ip_address]
Open your WSL terminal.
Update your package manager and install Apache:
sudo apt update
sudo apt install apache2 -y
The
-yflag automates the installation process by answering "yes" to prompts.
Check if Apache is running:
sudo service apache2 status
If it’s not running, start Apache:
sudo service apache2 start
Use curl to test if Apache is serving the default page:
curl http://localhost
You should see the HTML of Apache’s default page printed in the terminal.
Open a browser on Windows and navigate to:
http://localhost
You should see the default Apache welcome page.
By default, Apache may only listen to local requests. To make it accessible from Windows and other devices, modify its configuration:
Open the Apache ports.conf file:
sudo nano /etc/apache2/ports.conf
Ensure the following line is present:
Listen 0.0.0.0:80
Save the file and restart Apache:
sudo service apache2 restart
WSL operates in its own network environment, so it has a unique IP address. Find it by running:
ip addr
or
hostname -I
You will see something like 172.28.x.x. Note this down, as it will be used for port forwarding.
To access Apache via http://localhost on Windows, forward traffic from Windows’ localhost to WSL’s IP address using netsh:
Open Command Prompt as Administrator.
Add a port forwarding rule:
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=80 connectaddress=<WSL-IP> connectport=80
Replace <WSL-IP> with the IP address you found in Step 4.
Verify the rule:
netsh interface portproxy show all
It should display:
Listen on ipv4: Connect to ipv4:
0.0.0.0 80 172.28.x.x 80
Allow external traffic to port 80 on Windows:
Allow Apache Port 80).curl http://localhost
http://localhost
You should see the default Apache page.Find the Windows host’s IP address:
ipconfig
Look for the IPv4 Address under your active network adapter.
From another device on the same network, open a browser and navigate to:
http://<windows_ip_address>
Replace <windows_ip_address> with your Windows machine’s IP.
If Not Accessible:
80 is allowed.netsh interface portproxy show all displays the correct forwarding.Check Apache Logs: In WSL, inspect the logs for errors:
sudo tail -f /var/log/apache2/access.log
sudo tail -f /var/log/apache2/error.log
By following these steps, you can configure Apache in WSL to be accessible both from Windows and from other devices on the same network. Let me know if you have any questions!

Learn how to quickly expose a localhost server to your local network on Windows using netsh portproxy. A step-by-step guide to accessing local apps from any device.

Just created a new Git branch and see 500+ modified files? Uncover the GitHub Desktop on Windows trap and resolve annoying line ending & permission errors step-by-step.

Preventing AI disasters in WSL! Learn how to configure Google Antigravity for Frappe & ERPNext projects to avoid 'sudo' errors and master your dev environment.