WAMP not connecting to my Android phone [duplicate] - android

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?

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

Related

How to access local virtualhost with android device

i setup few virtualhosts on my laptop, and all of them are name based for example :
www.example1.dev
www.example2.dev
...
and i want to access them with my real android device using USB cable.
and im already conncted to same wifi network as well.
but everytime i try to access one of my virtualhost from my android device i get address not found
i also checked this question
How can I access my localhost from my Android device?
but its related to ip address while im using name based virtualhost
edit 1 :
this is one of my virtual host setup that im trying to accessing it from my android device:
/etc/apache2/sites-avaliable/examplesite1.dev.conf :
<VirtualHost *:80>
<Directory /var/www/examplesite1>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ServerName examplesite1.dev.com
ServerAlias www.examplesite1.dev.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/examplesite1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and /etc/hosts :
127.0.0.1 examplesite1.dev.com
192.168.250.1 examplesite1.dev.com
192.168.1.51 examplesite1.dev.com
You can get access to the local host via:
http://192.168.1.1/{{service end points}}
it will help you to access the localhost from your mobile

Android: How to call apis in mobile with sub-domain from local system

I have a Rails application running in my laptop and an android application on phone. I want to call apis of rails application where routes are namespace with sub-domain.
My api look like below:
http://api.localhost:3000/login (With sub-domain)
When I replace localhost with ip address. It will work in browser but in android application it gives me Android java.net.SocketTimeoutException: failed to connect. But when I namespace without sub-domain it works.
http://192.168.1.101:3000/api/login (Works fine)
What is the correct URI with sub-domain ?
http://api.192.168.101:3000/login (Gives above error)
The easiest way to solve the problem is if you have a domain registered. You can add a DNS entry for hostname api.192.168.101.
If not, you have few options.
Setup your wireless router to resolve the hostname api.192.168.101 to 192.168.1.101. I am assuming, your phone's DNS server is your wireless router. If your wireless router does not support adding local DNS entries checkout the next option.
You have to add the entries to "/etc/hosts" file of your Android phone. It is easy for rooted phones
I suggest you consider buying a domain from a good vendor who provides you a decent DNS management console.

Android: HTTP connection to localhost web site

I am developing a tablet application which needs to connect to a web site to collect online content.
I have seen that we can indeed connect to a web server on a local system by addressing it via it's IP address.
However, I am using virtual hosts on my system, so as to use virtual domains.
This is setup on my system in the apache httpd-vhosts.conf file like this -
#
# Project wordpress dev site
#
<VirtualHost *:80>
DocumentRoot "C:/web/www/boutique"
ServerName boutique.project.dev
</VirtualHost>
with my hosts file having the following entry
127.0.0.1 boutique.project.dev # project woocommerce site
I am using the HttpPost and HttpClient classes and I cannot see how I can provide the real IP address whilst still transmitting the host name in the URL request.
So, what I need to know is how can I make queries from my application using the virtual address " boutique.project.dev " ?
Is this possible ?
Edit :
Following one comment, I need to make things more clearer.
I am wanting to do this in code. Each time we make a connection to a site, the URL does a DNS lookup to determine the IP address to use. I need to intercept this and provide the IP address of my local system. I have seen some examples for proxy's using HttpHost, but I am unclear as to how to use this or even if it is relevant.
I think you don't do that unless you modify host file in android device (with root permissions)
This is a similar question: Apache Virtual Host (Subdomain) access with different computer on LAN
You also could setup a DNS server in your computer (i.e bind9) and set entries for your apache virtualhost and configure android in order to use that DNS server.
Here is the solution which I hope will avoid some useless "banging the head against a wall" for those of you who might have the same need.
Two or three steps are necessary.
1st step : Open the firewall to allow connections.
This is obviously necessary or else, whatever you do the connection will not be made. I use Comodo and so I added a rule in the firewall permitting all connections coming from the local LAN.
2nd step : Tell your server, apache in my case, to listen on its IP address.
I added the following entry in my httpd.conf file :
Listen [my ip address]:80
3rd step : Code the connection
The key to getting this to work is to tell which virtual server is needed. So, without further boring details, here is the code :
// setup the needed objects
HttpClient client = new DefaultHttpClient();
// create the request using the IP address of the server machine
HttpGet request = new HttpGet("http://[target ip address]:80/testpage.php");
// here is the code magic - manually set the host header
request.setHeader(HttpHeaders.HOST, "boutique.project.dev");
// now execute the request
HttpResponse response = client.execute(request);
// read back the response as normal
....
The result is that the apache server will map the request to the virtual host.
I hope this will be useful for others here !
Oh, I almost forgot, don't forget to enable the WiFi on your tablet - can save hours of wondering why it doesn't work !

how to access a localhost website from android device

I have an ASP.net Web API in my laptop with this address :
localhost:99949
I add this to IIS Express that I can access my web Api from another computer in same lan network , and it's going this:
Nimis:80
I can access to my web api from other PCs , but when I try to access this with my android device it show me "Web page not available" error.
I turn off all my firewalls.
what should I do to fix it ?
You need to add an inbound rule in the firewall for port 80 (or whatever port you used for your website on IIS):
Go to Control Panel, Windows Firewall
Select Inbound Rules
Add a New Rule
Select "Port" as a Rule Type
Select "TCP and put "80" (and any other ports you want to open) in "Specific local ports"
Select "Allow the connection"
Select the network location where the rule should apply
Give a name and an optional description
After that you should be able to access your site from other devices in the same network using http://computername (e.g. http://myhomepc)
However you might need to use the IP of the server machine with Android. It always seems to override its DNS entries using Google's servers. In this case try to modify DNS settings as explained here.
I had the same problem and this is my solution without changing anything in FireWall or any other settings:
Get the IP of the WebService deployed by IIS-Express (run IIS-Express): For this install the extension "Conveyor" in Visual Studio: Tutorial on Youtube
To check if it is working open browser on your mobile and type in the IP shown in Conveyor: IP of WebService --> e.g. I typed URL: "http://192.168.178.51:45455/api/ToDo" to get the correct HttpGet from my Rest-Webservice
To have it running in Android Studio I used a normal HttpURLConnection (Same URL also runs on Emulator!)

Accessing Apache server on an Android device locally

I'm having trouble finding a way to accessing the page of a virtual host (and the default Apache index.html page) on my Android phone. My hosts file on both my Android and PC use 127.0.0.1 as localhost and domain1.com. I've restarted my Apache server on my PC, and I can access it fine on my PC's browser at domain1.com, but I can't seem to access it on my Android browser. I've tried a public IP address, domain1.com, domain1.com:8000, 127.0.0.1:8000, localhost:8000... but none seem to work. They work on my local PC, though. Here's my httpd.conf file:
<Directory /home/*/public_html/>
AllowOverride FileInfo AuthConfig Limit
Order allow,deny
Allow from all
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
ScriptAlias /cgi-bin/ "/home/*/public_html/domain1.com/public/"
Listen 8000
NameVirtualHost *:8000
<VirtualHost *:8000>
ServerName domain1.com
DocumentRoot /home/*/public_html/domain1.com/public
</VirtualHost>
localhost (a.k.a., 127.0.0.1) on your phone points to your phone. localhost on your PC points to your PC. Your PC is not your phone. Your phone is not your PC.
If you want your phone's Web browser to access your PC, use the IP address of your PC in the URL, along with your desired port number (8000, apparently). Your PC's IP address is something other than localhost.

Categories

Resources