I am developing a site on my machine. I am using a Virtual Host, so that my site address for the project is mysite.local.
Typically, I can access my site on other machines on the network by typing http://ipaddress/projectfolder (which is in htdocs). But since I am on virtual host, I "can" access it on any computers by pointing the host file to the xampp host machine. But I don't think I can do so on my android tablet, since there is no host file to speak off.
Any advice on this?
Thanks.
One possible solution is to use one of the localhost tunneling tools to temporarily make your site visible to the public Internet - this would allow you to test it from any device that has Internet access, so you can do things like test how it performs over 3G or ask a friend to take a look too.
Two such tools include:
PageKite - https://pagekite.net/ (disclaimer: I wrote this one)
Localtunnel - http://progrium.com/localtunnel/
There are others, but these two are both open source with an optional online service component, so you can choose whether you want to run your own relay in the cloud or use one provided by the authors of the tools.
Even though the question might not be the most recent, I just ran into the same issue and found another possible solution.
If you want to access one site from within your lan, you can add another virtual host that listens to your local IP, as follows:
<VirtualHost 192.168.0.100:80>
ServerName loc.al
DocumentRoot "/path/to/project/"
DirectoryIndex index.php
<Directory "/path/to/project/">
Options -Indexes +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
That would forward any incoming requests from your local IP to the DocumentRoot specified inside that virtual host.
Related
I have my Laravel backend that I am trying to connect to from android app. my hosts file has
127.0.0.1 my.backend.test
the httpd conf file in my backend is
<VirtualHost *:80>
ServerName my.backend.test
DocumentRoot /var/www/mybackend.co.uk/code/public/
DirectoryIndex index.php
RewriteEngine On
ErrorLog /var/www/mybackend.co.uk/code/storage/logs/apache_error.txt
Header set Access-Control-Allow-Origin "http://localhost:4200"
<Directory /var/www/mybackend.co.uk/code/public/>
AllowOverride All
</Directory>
I can access http://my.backend.test/api/some-route fine from google ARC but not from my phone. I seem to have to use my local ip address but I dont understand how to set that up.
I tried adding
<VirtualHost 192.168.my.ip:8080>
ServerName my.mobilebackend.test
DocumentRoot /var/www/mybackend.co.uk/code/public/
DirectoryIndex index.php
RewriteEngine On
ErrorLog
/var/www/mybackend.co.uk/code/storage/logs/apache_error.txt
<Directory /var/www/mybackend.co.uk/code/public/>
AllowOverride All
</Directory>
to httpd conf and
192.168.my.ip my.mobilebackend.test
to hosts
If I understand correctly : you can access your server from a different machine on the same network (so this is not a firewall problem) but only if you use the name (added in client's hosts file) and not the IP address.
Is your configuration the first virtualhost ? apache search for a ServerName matching the name provided in the query (e.g. the URL), then falls back to the first one, in your case the ubuntu home page.
As a test, what happens if you use
ServerName 192.168.0.1 (i.e. the IP used in the URL)
I think it will work if you access the server by IP address, but not anymore by name
Try this method
ip:port
Example
10.0.2.2:80
Note: Firewalls may cause problems with this. Windows has Microsoft Windows Firewall enabled by default. You may have to disable it
IP address
If you are using an emulator:
10.0.2.2
If you are using a real device:
Connect them into the same network. Either using a WiFi connection or using USB tethering option in your phone.
Find the IP address of your computer by typing ipconfig in cmd (if you are using Windows)
Port
Default port is 80. If you have changed it, use the new one.
OK, Let's first clarify the problem that you are encountering so that my solution will be clearer.
Your problem is that you are hosting a backend locally on your computer and although you are able to access it without a problem on your computer itself, when you try to connect to it from a different device you are unable to access it.
This problem comes from the fact that your website is hosted locally on your computer and is not accessible to the outside world, Therefore your phone which is presumebly on a mobile network, cannot access your backend since your backend is on your own private network and your phone cannot access this private network from its own network, This is due to the fact that generally your router/isp block incoming requests to port 80, so even if you would know your computers public ip address you still would be blocked.
Now that we discussed the problem, lets go through what a solution would entail.
A solution would entail that either both your phone and your computer are on the same network, or you expose your computer to the public internet.
Lets go through some ways to acheive this.
The first and arguably the simplest way to acheive this would be to put your computer and your phone on the same network. This can be acheived by connecting your phone to the same router that provides your computer with internet access. Once you are connected to the same network, all you have to do is instead of using this url http://my.backend.test/api/some-route, replace my.backend.test with the local ip address of your computer so if your computers local ip is 192.168.0.2 then it becomes this http://192.168.0.1/api/some-route and now you will be able to access your backend from your phone.
Note: You may be wondering how do I figure out my computers local ip address? On windows it can be found by going into network settings > right click on your network connection > click properties from the context menu and then look for the field that says ipv4 address, that is your local ip. On mac you can find it by going to System Preferences > Network > clicking on the connection that has a green dot next to it > Then underneath the status label you will see the current local ip address that you are connected to.
Solution #1 is great if you don't mind going through the hassle of connecting your phone to the same network as your computer, but lets say its a pain, or impracticle for various reasons like lack of wifi etc or its just that you want your phone to be able to access the computer from Anywhere and no matter what network it is on If this is the case, solution 2 is for you.
We will enable access to your computers localhost to the entire internet by using reverse tunneling software, in our case one of the most popular choices is Ngrok, available here. What Ngrok does is it creates a tunnel to your local host and assigns it a publicly accessible domain such as yourapp.ngrok.io which you can use in place of my.backend.test to access your application from anywhere. So once you enable Ngrok you just replace http://my.backend.test/api/some-route with http://yourNgrokAppDomainName.ngrok.io/api/some-route and you will then be able to access your backend from your phone from anywhere no matter which network you are on.
In summary these are two ways for you to access your backend that is on your computer from a phone. Hope it helps.
Maybe I'm typing the wrong words by google but I' totally lost and can't a solution.
On my work we all access our projects through server alias like project.company.local
But when I'm at home with my company notebook I can't reach my websites aliases from e.g. my smartphone or any other device at home. Although they are all in the same network.
I have Ubuntu and Apache on my notebook.
My etc/hosts has
127.0.0.1 projectA.company.local
What am I missing?
Your hosts file only works for the computer itself, not other machines on the network. Your work must have the appropriate entries set up on the DNS server. You could just access a site on your home computer, from other devices on the network, using the IP address of your computer, instead of a host name, if it's just one site. Otherwise perhaps your router will allow adding DNS entries for the local network. If you're going to do that, you'd also best set up a static IP address for your home computer so it doesn't change. Hope that is enough info for you to get it sorted.
I am trying to debug my visual studio 2012 asp.net project from my phone and have followed all steps here and here.
However none of them work, can't even connect from my other laptop. When I add my public IP or use * IISExpress doesnt even seem to pick up on it (Can't find it in IISExpress->show all applications). But When I used my local IP at least it showed up there and I could connect to it from my own computer, but no other computer/phone.
The cmd commands are successful, I add the extra binding, I open the firewall. Dont know what is wrong.
Which IP (local/public) should I use? what should I type in as URL when I want to test it? I am trying http://IP:port and http://IP:port/Default.aspx.
EDIT: Using this solution I got it to work on my laptop, however I still can not get it to work on my phone.
Basically, the points mentioned in the links you have cited are enough for enabling communication with the phone. But here is one point to make sure (since you have not mentioned it): You have to make sure that both the server and the clients (in your case, the machine that runs the visual studio and your phone and the other laptop) are on the same wireless network. To find out the IP that your server/development machine is currently using, you can issue ipconfig command in cmd and look at the Wireless Network Adapter IPV4 address. For example, if your laptop IP address is 192.168.1.2, you should use http://192.168.1.2:8080/Default.aspx (assuming that your site runs on the port 8080).
You use the local IP if you're on the same network as your server (for example, use WiFi on your phone and join the same network that your server is on).
You use the public IP if the device is outside your network, and you have to configure the firewall to forward the correct ports to the local IP. That's NAT traversal. This would be if you're using the phone's cellular data connection, or you're using a WiFi or wired network that's different from the one your server is on.
Your URL should always be of the format <protocol>://<IP or DNS name>:<port>/<path>. However, you can omit the IP (and the colon) if you're using HTTP on port 80, or HTTPS on port 443. And you can omit the path if you're accessing the root of the site, and your site has a page correctly configured for the root (either via default document in IIS, or route defaults if you're using routing features).
I've an android app installed on my phone (debug build) and a local dev server. The app is using GAE Endpoints. I've updated the API builder by adding
b.setRootUrl("http://[myIP]:8080/_ah/api");
However, the app cannot connect. I've verified the dev server is up and running.
As a test, I tped
http://localhost:8080/
in by browser and I get the api explorer, etc.
However, if I do
http://[myIP]:8080/
I get "this webpage is not available". So clearly that must be the root cause.
The way I get my IP address is by running ipconfig in a cmd.
I tried turning off my firewall but that didn't make any difference.
Any and all help much appreciated. Thank you.
Figured it out.
i have a router so need to go into my router settings and add a 'virtual server' (that feature may be called something else for your router) redirecting from my ROUTER ip address (not what you get from ipconfig), and a port (whatever you want, need to use it in the setRootUrl), to my server address (what you DO get from ipconfig) and the local dev server port (typically 8080)
when i start my server in Android Studio i need to specify address 0.0.0.0, can be easily done in Android Stuiod by editing the run config (don't forget to restart it after that change)
update b.setRootUrl to point to the router ip address from 1. and the port you picked in 1. as well (don't forget to rerun your app after the update which will re-install it on your phone)
disable firewall -- however that's unsafe so instead i've created a special rule for this connection. (when setting inbound rules, a big gotcha is that there are usually predefined rules to block ALL connections from Java SDK/JRE for all installed versions on your system which will take precedence. You would need to modify those: I wouldn't advise disabling the whole rule, but you can modify to specific ports as such Ports: 1-[your server port-1], [your server port + 1, 65535].
The combination of those four works for me. Hope this helps someone!
I am developing a webpage in django (on my pc with windows 7) and now i need to test some pages in tablet pcs. suddenly the thought came if i can have an access to my localhost in windows from android tablet. is that possible? I am in the same wifi connection in both devices at home.
i read a lot questions and answers regarding this issue in stackoverflow and other places, but none of them gave me some concrete solutions.
I have samsung tab 2 10.1 with android 4.0.4.
appreciate any help, thanks
So, there are a couple of issues it seems. The question most of the answers are addressing is "how do you connect to another server in your local network?" (or variants). There are two answers, you can use the computer's IP directly, or you can use the computer's name (you may need to append .local). For example, my computer is xavier.local.
The second issue is that you seem to be addressing is that runserver is not accessible via other computers on the network (this is your actual question). The reason is that by default Django's runserver will only acknowledge requests from the machine which is calling them. This means that the default settings would make it so that you would only be able to access the server from Windows (and they did this on purpose for security reasons). In order for it to listen to other requests you have two options:
runserver 192.168.1.101:8000
# Only handle requests which are made to the IP address 192.168.1.101
Or (and this is easier when dealing with more than one environment):
runserver 0.0.0.0:8000 # handle all requests
So, if your IP address is 192.168.1.101:
runserver # only requests made on the machine will be handled
runserver 127.0.0.1 # only requests made on the machine will be handled
runserver 192.168.1.101 # handles all requests (unless IP changes)
runserver 192.168.1.100 # does not handle any requests (wrong IP)
runserver 0.0.0.0 # handles all requests (even if the IP changes)
I do think it important to note that 0.0.0.0 is realistically not a security question when dealing with a local, development machine. It only becomes a significant problem when working on a large app with a machine which can be addressed from the outside world. Unless you have port forwarding (I do), or something wonky like that, you should not be too concerned.
Though this thread was active quite a long time ago. This is what worked for me on windows 10. Posting it in details. Might be helpful for the newbies like me.
Add ALLOWED_HOSTS = ['*'] in django settings.py file
run django server with python manage.py 0.0.0.0:YOUR_PORT. I used 9595 as my port.
Make firewall to allow access on that port:
Navigate to control panel -> system and Security -> Windows Defender Firewall
Open Advanced Settings, select Inbound Rules then right click on it and then select New Rule
Select Port, hit next, input the port you used (in my case 9595), hit next, select allow the connections
hit next again then give it a name and hit next for the last time.
Now find the ip address of your PC.
Open Command Promt as adminstrator and run ipconfig command.
You may find more than one ip addresses. As I'm connected through wifi I took the one under Wireless LAN adapter WiFi. In my case it was 192.168.0.100
Note that this ip may change when you reconnect to the network. So you need to check it again then.
Now from another device (pc, mobile, tablet etc.) connected to the same network go to ip_address:YOUR_PORT (in my case 192.168.0.100:9595)
Hopefully you'll be good to go !
You can find out what the ip address of your PC is with the ipconfig command in a Windows command prompt. Since you mentioned them being connected over WiFi look for the IP address of the wireless adapter.
Since the tablet is also in this same WiFi network, you can just type that address into your tablet's browser, with the :8000 appended to it and it should pull up the page.
127.0.0.1 is a loopback address that means, roughly, "this device"; your PC and your android tablet are separate devices, so each of them has its own 127.0.0.1. In other words, if you try to go to 127.0.0.1 on your Android tab, it's trying to connect to a webserver on the Android device, which is not what you want.
However, you should be able to connect over the wifi. On your windows box, open a command prompt and execute ipconfig. Somewhere in the output should be your windows box's address, probably 192.168.1.100 or something similar. You tablet should be able to see the Django server at that address.
need to know the ip address of your machine ..
Make sure both of your machines (tablet and computer) connected to same network
192.168.0.22 - say your machine address
do this :
192.168.0.22:8000 -- from your tablet
this is it !!!
If both are connected to the same network, all you need to do is provide the IP address of your server (in your network) in your Android app.
Tested using easy EasyPHP DevServer 14.1.
The trick is you must first add your local ip address to the Apache server to listen to it.
Right click on the tray icon, go to "Configuration" -> "Apache" in the "httpd.config"
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 127.0.0.1:80
Listen 192.168.0.201:80 <<-- ADD THIS LINE
Then go to your Control Panel and deactivate your Windows Firewall or add your Smartphone/Tablet Ip Address to the exception.
That's it. I hope it helps.
The IP Address 192.168.0.201 may be different from yours. 192.168.0.X
I've struggled with this problem myself, and I couldn't figure out what it was, since it worked perfectly on my iPhone, I decided to look into the problem and find a quick solution.
My local machine is a Mac OSX 10.10+, one option would have been to start an Apache server, but that's super unhandy - changing the DocumentRoot every time you want to check something quickly on your Android device. Besides that, changing the DocumentRoot is a pain in the a** on Mac OSX 10.10.
If you want to use:
python -m SimpleHTTPServer
on your Android, do this:
sudo python -m SimpleHTTPServer [ANY PORT YOU WANT, BUT NOT 8000]
I hope this helps.
cheerz -Pit
Try this
python manage.py runserver
then connect both tablet and system to same wifi and browse in the address
eg: python manage.py runserver 192.168.0.100:8000
In tablet type that url in adress bar
In my case I was required to disconnect and reconnect to the same network (both phone and pc), after changing the firewall settings.