Page 1 of 1

Android cannot connect to server if accessing over internet

PostPosted: 29. September 2017 14:58
by vismay02
I have an android app which requires authentication for user.
I am using xampp as my server, I cannot reach server when trying to access it through internet but able to access when on WIFI ie. the same network on which the xampp is.
Are there any necessary changes I have to make.
I have already granted access to all users.

Re: Android cannot connect to server if accessing over inter

PostPosted: 29. September 2017 20:17
by Nobbie
Which IP do you connect via Internet for Xampp?

Re: Android cannot connect to server if accessing over inter

PostPosted: 01. October 2017 15:33
by vismay02
While accessing over computer as my PC and the server are on same network I use private IP of my PC.
And while accessing remotely from mobile I use public IP.

Re: Android cannot connect to server if accessing over inter

PostPosted: 01. October 2017 16:28
by Nobbie
Public IP of what? Are your running a router? Or is your PC connected directly?

Re: Android cannot connect to server if accessing over inter

PostPosted: 02. October 2017 10:58
by vismay02
In have a router. and my PC is the virtual host connected to that router.

Re: Android cannot connect to server if accessing over inter

PostPosted: 02. October 2017 13:04
by Nobbie
vismay02 wrote:and my PC is the virtual host connected to that router.


Please explain more precisely, what do you mean by that?! A virtualhost and router are totally different thing. You stll did not explain, which IP is the "public IP".

Re: Android cannot connect to server if accessing over inter

PostPosted: 03. October 2017 06:39
by vismay02
My PC contains phpMyadmin, I have all my files in htdocs folder. I have a physical server, the public IP belongs to the server and I have configured the PC as virtual server by using router settings. PC is connected to the same server. I have no problem accessing the database while using a web browser from mobile with my internet connection but when i try to login in my application it says "cannot be connected to server." I hope you understood.

Re: Android cannot connect to server if accessing over inter

PostPosted: 03. October 2017 10:48
by Nobbie
vismay02 wrote: I hope you understood.


Hardly - but I might got it. What you call "virtual server" (above you called it "virtualhost", what is competely wrong!) seems to be the same thing what is called "port forwarding" in other routers.

I think, that you installed your problematic application locally onto your (Xampp?) server, and you applied eithe "localhost" or the local IP (like 192.168.x.x) as server name in the installation routine (most applications require a server name, an IP or similar in the installation dialog). At next, probably your application installs a .htaccess file which does a redirect or rewrite, which routes to that server name you applied in the installation. Maybe a redirect happens without .htaccess, but within the PHP code.

If this is the case (what is very common for many CMS like wordpress, joomla etc.), this finally leads to the problem, that the target IP is a LAN IP (or "localhost"), which is unknown in the scope if you connect from outside your LAN. That finally results in "cannot connect to server". You may check the access_log (and also error_log) of your server in order to find out, if redirects are happening and if they succeed or not.

The general solution to that problem is, if you are planning to connect to your application from outer Internet, do NOT provide the LAN IP as server name, provide the external IP instead already at installation time. In an existing installation you might be successfull to edit any kind of config file (for wordpress it is wp-config.php), where you can change the server name also after the installation.

Re: Android cannot connect to server if accessing over inter

PostPosted: 03. October 2017 12:13
by vismay02
Thanks a lot for your assistance. I finally made it. Thank You!

Re: Android cannot connect to server if accessing over inter

PostPosted: 28. January 2018 11:37
by garryjoshi
Nobbie wrote:
vismay02 wrote: I hope you understood.


Hardly - but I might got it. What you call "virtual server" (above you called it "virtualhost", what is competely wrong!) seems to be the same thing what is called "port forwarding" in other routers.

I think, that you installed your problematic application locally onto your (Xampp?) server, and you applied eithe "localhost" or the local IP (like 192.168.x.x) as server name in the installation routine (most applications require a server name, an IP or similar in the installation dialog). At next, probably your application installs a .htaccess file which does a redirect or rewrite, which routes to that server name you applied in the installation. Maybe a redirect happens without .htaccess, but within the PHP code.

If this is the case (what is very common for many CMS like wordpress, joomla etc.), this finally leads to the problem, that the target IP is a LAN IP (or "localhost"), which is unknown in the scope if you connect from outside your LAN. That finally results in "cannot connect to server". You may check the access_log (and also error_log) of your server in order to find out, if redirects are happening and if they succeed or not.

The general solution to that problem is, if you are planning to connect to your application from outer Internet, do NOT provide the LAN IP as server name, provide the external IP instead already at installation time. In an existing installation you might be successfull to edit any kind of config file (for wordpress it is wp-config.php), where you can change the server name also after the installation.


I was unable to reach the xampp server while I was using internet however working fine with WiFi. I finally now been able to get it done. Thank you so much for the solution Nobbie :)