WAMP虚拟主机配置后,如何让校内其他电脑访问PHP项目?
Hey there! Let's get your virtual host api.local accessible to other machines on your school network. The root problem here is that those other devices don't know how to map the api.local domain to your server's IP (204.XXX.XX.XX). Here are two reliable ways to fix this:
If you only have a handful of computers that need access, this is straightforward:
- On each Windows machine, open Notepad as Administrator, then navigate to
C:\Windows\System32\drivers\etc\hostsand open it. For Mac/Linux, open a terminal and edit/etc/hostswithsudo nano /etc/hosts(you'll need admin/sudo privileges). - Add the exact same line you put on your server:
204.XXX.XX.XX api.local #api - Save the file. On Windows, make sure you don't accidentally save it as a
.txtfile (select "All Files" in the save dialog). - Flush the DNS cache to apply changes immediately:
- Windows: Open Command Prompt and run
ipconfig /flushdns - Mac: Run
sudo dscacheutil -flushcachein Terminal - Linux: Depending on your distro, run
sudo systemd-resolve --flush-cachesorsudo service nscd restart
- Windows: Open Command Prompt and run
After this, those machines should be able to reach your project at http://api.local.
If you need many devices to access the virtual host, manually editing each Hosts file is a hassle. Instead:
- Reach out to your school's network administrator and ask them to create a DNS record that maps
api.localto your server's IP address (204.XXX.XX.XX). - Once the DNS record propagates (usually a few minutes), every computer on the school network can access your project by visiting
http://api.localdirectly—no local Hosts edits required.
Before testing, double these:
- Make sure your server's firewall allows incoming connections on port 80 (the default HTTP port). If WAMP is running, this is often already enabled, but it's worth verifying.
- Confirm that Apache's virtual hosts module is enabled on your server: Open
httpd.confin WAMP, and make sure the lineInclude conf/extra/httpd-vhosts.confisn't commented out (no#at the start).
Once you've set up either method, test by pinging api.local from another school computer—you should see it return your server's IP. Then visit http://api.local in a browser, and your project should load without showing the WAMP default page.
内容的提问来源于stack exchange,提问作者user1687891

