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 address
for 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
wf.msc
to open Windows Advanced Firewall:22
. IP address
of the Windows machine:ipconfig
ssh username_or_root@[windows_ip_address]
Apache
:sudo apt update
sudo apt install apache2 -y
The
-y
flag automates the installation process by answering "yes" to prompts.
sudo service apache2 status
sudo service apache2 start
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. 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:
ports.conf
file:sudo nano /etc/apache2/ports.conf
Listen 0.0.0.0:80
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
:
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. 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. IP address
:ipconfig
Look for the IPv4 Address
under your active network adapter. http://<windows_ip_address>
Replace <windows_ip_address>
with your Windows machine’s IP. 80
is allowed. netsh interface portproxy show all
displays the correct forwarding. 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!