8

So I set up a few virtual hosts with unique urls and they work just fine on the desktop. However, when I connect a mobile device on the network, it can't seem to access anything properly but the default localhost virtualhost and that's only when it's the only virtualhost I have up.

My setup and coding is pretty much this except with a different site title

wamp server 3.0 virtual host on another device

and while that solution redirects me to my unique url, it has a lack of images on a default wordpress website.

Has anyone managed to get mobile devices fully accessing links other than on localhost?

Community
  • 1
  • 1
dinky dino
  • 81
  • 1
  • 1
  • 4

1 Answers1

14

Since I posted the answer you referenced, I have decided upon a simpler solution.

What the actual problem is

Because we cannot fiddle with the configuration of a phone like we can with a PC, the phone can never find the domain name we create in our Virtual Host definition on the Server machine, because it does not exist in any DNS Server for it to locate the IP Address in, and a DNS Server is the only place a phone can look, unless it is jail broke.

If you wanted to access one of your Virtual Hosts domains from another PC you could just add a line like this into the HOSTS file on the other PC like this.

192.168.0.10 example.local

But you cannot do that on a phone/tablet.

What Apache expects to be able to asssociate a request to a Vhost

When we create an Apache Virtual Host, we are actually telling Apache to look at the domain name on the incoming connection and match that domain name to a ServerName that exists in one of our multiple Virtual Hosts definitions.

But if we use for example example.local as our virtually hosted domain when we attempt to connect to that from our phone, the phone does a DNS Lookup and does not find that domain and therefore cannot get its ip address.

The simplest way to get round this is:

Assuming we do not have access to adding record to a DNS Server we have to come up with a different solution.

The simplest of these is to use the IP Address of the PC running the WAMPServer(Apache) server and a specific port number. So thats a different port number for each of our sites we want to use from a phone.

So how do we do this

Add the new listening port to httpd.conf like so after the 2 existing Listen statements

WAMPServer 3: Do this using the menus, not by doing a manual edit on httpd.conf

right click wampmanager-> Tools -> Add listen port for Apache


#Listen 12.34.56.78:80
Listen 0.0.0.0:80
Listen [::0]:80
Listen 0.0.0.0:8000
Listen [::0]:8000

Suggested httpd-vhosts.conf file

#
# Virtual Hosts
#

# Always keep localhost, and always first in the list
# this way a ramdom look at your IP address from an external IP
# maybe a hack, will get told access denied
<VirtualHost *:80>
    ServerName localhost
    DocumentRoot c:/wamp/www
    <Directory  "c:/wamp/www/">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

# The normal Vhost definition for one of our sites
<VirtualHost *:80>
    ServerName example.local
    DocumentRoot "c:/websrc/example/www"
    <Directory  "d:/websrc/example/www/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

# Access example.dev from phone for testing
<VirtualHost *:8000>
    ServerName example.local
    DocumentRoot "c:/websrc/example/www"
    <Directory  "d:/websrc/example/www/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
        # assuming yoursubnet is 192.168.0.?
        # allow any ip on your WIFI access
        Require ip 192.168.0      
    </Directory>
</VirtualHost>

Restart Apache from wampmanager after completing these edits.

Now you test this from the WAMPServer PC by using the ServerName i.e example.dev and from the phone using the ip of the PC running WAMPServer with the port number i.e. 192.168.0.10:8000

Apache will find the correct code to serve from both requests.

If you want more than one Virtual Host to be accessible from your phone you just duplicate this idea and change the port number for each new site, lets say you would use 8001,8002,8003 etc. For as many sites as you want to access.

You may also have to amend your firewall to allow access on http on port 8000, or whatever port you pick to use

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • It had the same results as the first solution (loaded the page but no images) but I think I know why now. When I set up my virtual host on my desktop pc and installed wordpress, the links all become integrated with the original servername. So when I try to access it on my phone, the phone keeps trying to access everything using the ip instead of the server name domain making all the images blank. I also found that if I access the virtual host on the phone and install wordpress using the phone itself, it will work but the domain changes to the ip instead of the unique url. – dinky dino Mar 25 '17 at 23:23
  • WordPress is infamous for storing the domain name used on the install in its database and using that for various things like redirects and image urls. Maybe have a look at https://codex.wordpress.org/Moving_WordPress for some insite – RiggsFolly Mar 26 '17 at 11:16
  • Yea as you said my phone could not be directed to the image url so instead I did as you mentioned with the ports playing only with the ip of my pc. So the domain/server name of my sites were 192.168.1.100:8000, 192.168.1.100:8001 and so on after switching on the don't check virtualhost definition and duplicate server names in wamp settings. Changing urls to unique urls isn't too difficult in the end in wordpress under permalink settings and with a few plugins like velvet blues so that works for seeing how different sites look on my phone. Thanks a lot for the detailed explanation! – dinky dino Mar 26 '17 at 23:51
  • I also had to enable `Apache HTTP Server` for Public networks on Windows Firewall. Thanks for your solution, it works! – IvanRF Aug 17 '17 at 00:25
  • I had to open up windows firewall, go to 'add new rule', and select port, then open up port 8000, and then it worked (before this, I disabled windows firewall quickly to see if the connection goes through to determine if it's a firewall issue) – friek108 Aug 04 '19 at 01:14