AndroidCSS

Android material design Programming Blog

Connect Android to localhost: Test Android with PHP MySQL using WAMP

If you are using WAMP server to test your PHP files locally, Android localhost connection and testing PHP in your mobile phone is easy.

If you are working on PHP MySQL with your android app, it’s essential that you need to test your app for correct data before moving your database, PHP files and Android app to production. One way you can test for the same is, going live on the internet by hosting your files with hosting provider and it’s bad idea to test your files live on the internet.

Rather than hosting your database and PHP files on the internet, you can test your app for PHP MySQL using localhost WAMP server. To do Android localhost connection, you need to install and setup WAMP server on your windows computer. If you don’t have WAMP server installed on your computer then you can refer tutorial Setup and Install WAMP Server.

People who already installed WAMP may tried connecting android phone by entering http://localhost/ in your android code but that does not worked for you because your phone does not understand what localhost is, and localhost is only an internal reference to your computer. Follow below tutorial to connect Android with localhost using IP address.

Successfully Running WAMP server on your computer indicates a green icon on system tray, click on that, with a menu pop up click on put online item. Wait for few second to process its task. below is the screenshot of wamp menu.

Wamp server put online

Now, you need to find your IPV4 address of your computer, run command prompt in your computer(go to Windows start button and start typig cmd) and type ipconfig and enter to see your IPV4 address of your computer. Below is the screenshot of command prompt.

Find IPV4 address of windows computer

Open your web browser and type your computer IPv4 address and go, for example http://192.168.1.7/. by doing so you likely to see your localhost page. Now, you can access any page in localhost through your computer IP address.

If you don’t know how to connect android to PHP MySQL, you can refer some of tutorial below.

Android connect localhost in Emulator

To test your app for Android localhost connection with PHP MySQL in your android studio emulator, just enter address as http://IP Address/ followed by path of your PHP file in your code.

For example: http://192.168.1.7/test/example.php

Note: Before putting your address into code, test address in your browser for whether path is valid or not.

Android connect localhost in your Android Mobile Phone

Enter address as http://IP Address/ followed by path of your PHP file in your code.

For example: http://192.168.1.7/test/example.php

To test your app for Android localhost connection with PHP MySQL in Android Mobile Phone, your computer and mobile phone should be connected to same Wi-Fi router.

Note: Before putting your address into code, test address in your mobile browser for whether address is accessible or not.

What if i don’t have Internet or Wi-Fi router?

If you don’t have internet or Wi-Fi router connected, you can use below method that may work for you.

  1. method1: Create new wireless network in your windows computer and connect your android phone through Wi-Fi.
  2. method2: Install any Virtual Router and connect your phone through Wi-Fi.

23 Comments

Add yours

  1. Each time I have to change IP??

  2. can you make a tutorial to insert and retrive rows into mysql database from an android application using php and wamp server?

  3. Can You please provide Android and php code for forget password option sent to email to reset password. Thanks in advance

    • Soon i will going to write tutorial on topic “sending email through android” and will notify you once it is done. I’m sure at that time i provide code what you requested.

  4. Its not working when I use SDK version 5.0(lollipop) and above. But when I use API 20, 4.4(kitkat) and below it works.

    • May i know, what portion is not working or any error you are getting? I’m using SDK version 6.0(Marshmallow) to test my app and it’s working fine with me. Usually, it does not depend on the SDK version you are running. May be your IP address changed recheck it and also check WAMP for put online option.

  5. hello everyone i make my android application and i convert it to .APK after this step my application can’t connect to wamp server . what can i do to work it like it was in an emulator thnx

  6. Very Nice and very useful tutorial. I was stuck into the same issue from last night, but using this IP solution it solved my problem.
    Thank you Gururaj

  7. i test my ip address to my mobile device browser before i put into my codes, the problem is , the ip address is not accessible… it’s just load too long..how to i fix that?? plss help..this is for my thesis

  8. I followed your code and used my PC ipv4 address but i am getting connection failed message.
    My wamp server is running perfect.I checked address with mobile browser and it is showing you don’t have permission to access server. What might caused the issue?

  9. When I try to access my php file through mobile browser it gives me error forbidden, I am using ip address as suggested here, please help

  10. it doesn’t work address ip the problem is unsuccessfully
    if there is another idea please tel me thanks

  11. Please look at your logcat for errors.

  12. Man i dont know. How i could make u to get money. with this Blog. Is very clear explanation. Of things.

Leave a Reply

Your email address will not be published.

*

About | Policy | Disclaimer

Creative Commons LicenceUp ↑