WAMPServer, access server from mobile phone

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

Leave a Comment

tech