Skip to main content

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

Test Android app for PHP MysQL using localhost 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.

Gururaj P Kharvi

An Entrepreneur, Web and Android developer from India.

12 thoughts on “Connect Android to localhost: Test Android with PHP MySQL using WAMP

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

      1. Thank you so much, the login tutorial worked like charm .I have seen many websites but all of them were outdated.I’ll be glad if you can make a tutorial to insert and display in an android device as soon as possible.
        Thanks in advance

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

    1. 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.

  3. 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.

    1. 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.

  4. 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

  5. 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

Leave a Reply

Your email address will not be published. Required fields are marked *