make virtual host available through local network for iphone - iphone

I'm building a site on my localhost with a virtual host (mynewsite.com). Instead of uploading files to an actual server and I'd prefer to just test locally. I have the virtual host working on my desktop, I just want it to be available so I can see it on my iPhone or any computer on my network. So if I go to mynewsite.com on my iPhone it will display the site from my localhost. I think I need to do port forwarding but I'm having difficulty figuring it out. I'm on a Mac with MAMP.
How do I make the virtual host available to my iPhone through my Linksys router for testing?
My httpd.conf in MAMP looks like:
<VirtualHost *:80>
DocumentRoot "/Users/jaysonp/Sites/mynewsite"
ServerName "mynewsite.com"
ServerAlias *.mynewsite.com
...
Then in my host file I have:
127.0.0.1 mynewsite.com
I should note that I can't just hit the ipaddress on my iPhone, there is code that checks against the domain name for the site to work.
Thanks!

Please see my answer here. But basically, you just have to modify the Wifi settings in your iPad to use the IP address of your development machine as an HTTP proxy.

You can use application to edit hosts file on the devices. Use iFile application. You can add more any hostname. You can see some picture here but I wrote in my language.
http://www.anop72.info/iphoneipad-เรียก-url-vhost-ทำอย่างไร/
Hope this helps.

You just need to change the host file of respective machine on which you want to see your virtual host.
For Example:
(in Linux and macOS ): /etc/hosts
(in Windows ): c:/windows/system32/drives/etc/hosts
(in Android ): Android is also the part of linux so the host file location is same in android too. But you need root access to change the host file.
(in iOS ): (anyone who knows can edit here!!)
Open the host file and
192.168.1.70 mynewsite.com
192.168.1.70 is the ip address of the machine in which your project is running on a virtual hosting -> mynewsite.com
All of the other devices must be connected to the same network .

Just use the IP address of your virtual host. If your iPhone is on the same local network as your [virtual] host - the IP address will work fine.
I am not quite sure how you are defining "virtual" host - i.e. are you using Xen or VMware or something - or just running a web service on your dekstop?
If it is the former - you need to set up the IP services through Xen/VMware - if it's the later - its you desktop machine's IP address.

Related

Access local site with subdomain on iPhone

I understand that you can access your computer's local site from a mobile device running on the same network by entering your computer's IP address (with relevant local port) into the address bar. However, I often use subdomains for development. On my local I access subdomains using lvh.me. For example:
blog.lvh.me
However, this will not work for mobile because lvh.me is redirecting to the IP 127.0.0.1 .
Is there a way to access a subdomain on an IP address? Essentially, doing the same thing as the above code but allowing for a dynamic IP address depending on the IP my computer has at the time?
So, after continuing research, I found an awesome tool that allows for exactly the above functionality:
xip.io
For example, if my computer has the IP address of 124.4.1.3 and I was running a web server at blog.lvh.me, where lvh.me redirects to localhost or 127.0.0.1, I could access my computer's localhost from another device on the network using blog.124.4.1.3.xip.io
I hope that helps someone!
Sidenote: The app in question was running on a rails server and the above setup required the following setting to be added to the environments/development.rb file:
config.action_dispatch.tld_length = 5
As rails was running on port 3000, this also required a url like:
blog.124.4.1.3.xip.io:3000

DNS problems with local hosts especially with Iphone/Ipad

I have some problems communicating with different devices each other in my local network. I suggest some DNS problems or incorrect DNS settings
First of all, a short overview of my devices:
Router: Speedport W 921V (latest Firmware 1.22.) using also dyndns for remote operation
File-/Web-Server: Debian Squeeze running samba and apache
Client1: Computer using Win 7 Pro
Client2: Iphone/Ipad
Internet works fine on all devices! All clients have set the DNS to the IP of my router. The router also has the settings for port forwarding from port 80 to port 80 of my Webserver as well for port 8080. To access to my Webserver outside my local networks also works fine, but....
Problem 1) Resolving public dyndns-address
When I ping my public address mysubdomain.dyndns-home.com inside my local network, the IP will be resolved correctly without any timeout problems on all devices, but when I use my public address in a browser (Chrome, Firefox, IE) there is a timeout error message or server down message. This is the same behavior on all devices. So why can I not use my public address in my local network? To change that, what do I have to change?
Problem 2) Resolving local devices on Iphone/Ipad
Because I can not use my public address in my local network I want to communicate by my local device names. So all my devices are registered by their mac-address in the router. When I log into my router I can see all devices and their IP-addresses which are currently running. So if the router is the DNS for my clients, the router should resolve the local device names. That works so far for the Computers running Windows or Linux. But on my Iphone or Ipad the names will not be resolved. I also tried to refresh the lease or to forget the network and reconnect again, but still I can not communicate with my Iphone/Ipad and my other devices. So what can I do to resolve the names on my Iphone/Ipad?
Thanks for your help
1) Because you are in your local network you have to use private ip (you can see private ip using ipconfig on windows or ifconfig command line on linux). The public ip is for all others computers on the network. If you want test that the server works correctly you can use a proxy (like www.anonymouse.org)

how to view "localhost" on my iPod touch

I have a website I am building on localhost:
http://localhost/my-website
I need to test it on my iPhone, but I'm not sure how to go about it. Do I just change my httpd-vhosts.conf file, and, if so, what are the settings?
Assuming that your development machine is called my-macbook-pro, you should just be able to navigate to http://my-macbook-pro.local/mywebsite on your iPhone.
To expand slightly on Richard J. Ross III's answer, "localhost" is a name used to refer only to the local computer. In order for your iPhone to be able to access content on that machine it must:
Have an IP address on the same network as the server machine.
This can be achieved by connecting the iPhone to a wireless access point that is on the same network as the PC, or by creating an ad-hoc wireless network between the two devices.
Respond to HTTP requests from network clients.
Assuming the server and the iPhone are on the same network, it should be possible for traffic to flow between them. However in order for your web content to be visible to the iPhone, the web server must also be configured to respond to requests made to the server machine's IP address.
This is not normally a problem as web servers are commonly configured to respond to HTTP requests sent to any of the machines IP addresses. It is possible that a server could be configured to only respond to local requests, however this is not a typical default setting
How you check or modify this setting is dependent upon the HTTP server software you are using. As this information is not specified I will include instructions for Apache2 as this is a very common choice of HTTP server.
Apache's Listen Directive
Apache's main configuration file is httpd.conf and it is located in the conf subdirectory of your Apache directory. The location of your Apache root directory will vary depending upon what operating system you are using and whether or not a custom location was chosen at installation.
The httpd.conf file contains a directive named Listen which controls the interface (IP address and port) on which Apache listens for incomming HTTP requests.
The default form of this directive is commonly
Listen 80
This specifies that the machine will respond on any of it's IP addresses to requests made on port 80, which is the default port for HTTP traffic.
You can modify the Listen directive to use any address associated with the machine including the loopback address (127.0.0.1) which the name localhost resolves to.
If Apache is set up to only listen on the loopback address then your server machine will only respond to requests made on the local machine. In this configuration, your Listen directive will look something like:
Listen 127.0.0.1:80
If this is the case, you will need to change to either listening on all addresses, as in the example above, or listening only on the address used by the iPhone to communicate with the server machine.
100% working solutions
(for linux + apache + vhosts)
If you are using vhost (several sites on the same server apache) the next several tips can help you view your local websites on mobile:
1) VHOST edit -You should go to /etc/apache2/sites-available/ on your server. There can be several files .conf, each file contain a virtual host configuration for apache. Default file will look like 000-default.conf. Open it (or another one) with admin permissions sudo. In that file you should see something like this:
<VirtualHost *:80>
ServerName auction.dev
ServerAdmin test#test.com
DocumentRoot /var/www/public_html/html
ErrorLog /var/www/logs/error.log
CustomLog /var/www/logs/access.log combined
</VirtualHost>
2) XIP.IO - this special service (its totally free) can help you. You should add to .conf file next line - ServerAlias auction.dev.*.xip.io, after this operation your file will look like this:
<VirtualHost *:80>
ServerName auction.dev
ServerAlias auction.dev.*.xip.io
ServerAdmin test#test.com
DocumentRoot /var/www/public_html/html
ErrorLog /var/www/logs/error.log
CustomLog /var/www/logs/access.log combined
</VirtualHost>
After editing you should save this file and restart apache with command sudo apachectl restart.
3) View from mobile - You need to know ip of your server, in my situation ip = 192.168.1.247. Now in your mobile browser just type auction.dev.192.168.1.247.xip.io and you should see your local website.
I'm working with xampp. localhost works on port 8080.
I just find my ip with ipconfig and surf to http://10.0.0.1:8080.
That easy!
If you just want a better feel of the native behavior instead of just browser dev tools you can use the iOS simulator and type localhost:xxxx in safari app.
For OSX, go to System Preferences / Sharing. There, you can find and change the name of your computer. In the same section, you also have to enable "Internet Sharing" service with "iPhone USB" port.
Then you can view your website at http://{ computer_name }.local/my-website.
When you connect your ipod with the cable to your macbook the device appears in safari on your mac in the menu under developers. When you click this option you can see exact the same as you can on your ipod.
Following these steps worked for me:
https://mtm.dev/iphone-localhost-mac
It is based on Internet Sharing via USB and setting & using the device_name which is then used as mentioned as <device_name>.local:<port>

Viewing a local web site on the LAN under a different hostname

In short I'm trying to browse a Mac's web site on the local wifi network under a .local hostname that is not the same as the machine's 'computer name' and think I'm missing a setup step.
I have a local install of nginx on my Macbook, with the proper /etc/hosts and nginx.conf entries to serve multiple sites, each with their own distinct local hostname. Assume the Macbook's network name is computername.local, and I have 2 sites running, one at http://computername.local and another at http://servicename.local. I can access each of these sites just fine from the local machine, but also want to be able to access http://servicename.local from an iPhone on the same WiFi network. I'm getting a timeout for that URL, but the other one works just fine.
I'm guessing something has to be done to allow servicename.local to be used on the local network, which I've left out. What is required to do that? Do I need to use Bonjour for that? Where would I add this new local hostname?
Another Mac on the same network can access this one under servicename.local just fine if I define the IP in its /etc/hosts file too, but I can't modify that file on the iPhone obviously. It's not jailbroken, and I'm not really interested in doing that just to get this working.
Not sure if it will help the OP, but another way of doing this - besides running a DNS server or jailbreaking the phone - is to run an HTTP proxy on the Mac, and configure the iPhone to use the proxy. Then the iPhone will pick up the Mac's local hosts file entries because it resolves DNS queries through the proxy. I've blogged about how to do this using the free Mac proxy "SquidMan" here: http://egalo.com/99j

Remote access to apache2 server

I'm trying to test my iPhone application on the device.
I have a mac computer which stores my development environment.
Right now I can only access PHP files using the http://localhost/PHPFileLocation
which does not work when I try to test my app on real device.
How do I configure apache2 to be accessible from outside?
Is it possible to configure it to a specific IP address?
I want to reach some php scripts located on my development machine running apache2 from my iPhone device.
Thanks
If your computer has a WiFi card then you should be able to attach the iPhone remotely to a ad-hoc Wifi network created on your dev machine.
I'm assuming your Mac is behind a router. You should be able to configure your router to port forward connections to your WAN facing IP address to port 80 (the HTTP port) on your Mac - see http://portforward.com/ for some help.
You may also need to turn the firewall off on your Mac.
Once this is set up correctly you can hit http://yourexternalIP/PHPFileLocation in your iPhone app and this will be directed by your router to the Apache2 server on your Mac. The external IP is normally found on your router's admin page somewhere.