Reputation: 1805
After setting up Apache virtual hosts with hostnames "server1" and "server2", how would I access them with my iPhone (or any mobile device) since there's no way modify the /etc/hosts file in iOS or Android?
My understanding is that you have to reference the virtual hosts by name (assuming you only have 1 IP address on your physical server), but there's no way to map those virtual hostnames to the single IP address on my physical server.
I'm running my server on my laptop using MAMP and my Vonage router/Apple Airport don't support DNS. Do I need to setup a local DNS server? Is there any easy way to run that on my laptop? Thanks.
Upvotes: 10
Views: 18609
Reputation: 6052
It's crazy that in 2023 there's no easier, cleaner way to accomplish this, but here's how I managed to get this working with XAMPP.
In your development machine's OS settings, disable all your firewalls, as these will intercept all incoming connections by default.
In httpd-vhosts.conf
(found in C:\XAMPP\apache\conf\extra
), copy your website's current virtual host entry to create a new one. In my workflow I already have a vhost set up for port 80 (HTTP) and one set up for port 443 (HTTPS) for each website that I need to test locally, so I copied one of these and changed the port to 420
. You can change the port to 420
, 69
or whatever else is likely to be unused. Your new virtual host entry should look something like the following:
<VirtualHost *:420>
DocumentRoot "D:\Users\Hashim\Documents\Projects\Websites\MyProject\myproject\public"
Options +FollowSymLinks
AllowOverride All
Require all granted
</VirtualHost>
Edit your httpd.conf
(found in C:\XAMPP\apache\conf\httpd.conf
) to add a new Listen entry for your new virtual host, using the port number you used above:
Listen 80
Listen 420
Identify your development machine's local IP address - on Windows this is done by running ipconfig
in the command line and looking for the IPv4 Address listed for your WiFi adapter. For example, if your local IP address is 192.168.1.254
you can now access your new virtual host on your mobile browser by navigating to:
192.168.1.254:420
You can also add a bookmark in your mobile browser for this if you plan to use it. Once you're done testing, remember to re-enable your development machine's firewall. It's not something you want to risk having disabled for more than a few hours.
Upvotes: 0
Reputation: 3534
Adding as following
httpd-vhosts.conf
<VirtualHost *:8080>
ServerAdmin [email protected]
DocumentRoot "/opt/lampp/htdocs/api/www"
ErrorLog "logs/app_error"
CustomLog "logs/app_log" common
</VirtualHost>
httpd.conf:
Listen 80
Listen 8080
Then in your mobile you can use:
http://<your laptop address>:8080/
Upvotes: 13
Reputation: 635
The below link has a nice work around for this problem.
Pleas go through this, after you have set the virtual host.
but instead of the path you need to give the local domain name. for example "king.dev" link below
192.168.1.250(your system ip) king.dev
in the hosts.ics file in your system.
now you can access the website from your mobile typing in your browser like.
192.168.1.250:4000[if you have set the port]/your_file.html
your local website will be displayed in the mobile device
you can also have a look at
http://www.tech-otaku.com/local-server/accessing-localhost-virtual-hosts-network-computer/
Upvotes: 1
Reputation: 11425
You could use IP aliasing and configure IP-based virtual hosts. But then you have to access the sites via IP from your mobile device. But I guess using different ports as @Renaud suggests is easier.
If you want to do it, add an IP alias using ifconfig <interface> inet <ip> add
on Mac OS X. Then add a Listen <ip>
and <VirtualHost ip>
directive to your Apache configuration.
Upvotes: 2
Reputation: 8873
You can't if you don't have a local DNS. As a workaround, you could setup your first VirtualHost to listen on the 80 port and the second one on the 81 (or 8080 or whichever ports you want) and access the server by using http://your.server.ip.addr:port.
Upvotes: 6