[IONIC 4] How to connect the device app with local database server

I’m trying to set the development server so I can test the device interactions with my local PHP server. I’m trying to do this following some instruction I found (1, 2, 3). I always did this interaction with ionic serve and never had a problem, but now I really need to test some exclusive device functions.

My computer local IP is:
PHP local server: localhost:1337
Device and computer sharing the same network

If I start my app normally with ionic cordova run android --livereload and try to access the PHP server (localhost:1337) with a HTTP POST method firing to, I can’t find the connection.

If I try to change the address with ionic cordova run android --livereload --address= I receive this error:

Error: getaddrinfo ENOTFOUND

I see that some people run with this same node problem, but trying to downgrade the serve library doesn’t work for me.

What is the correct way to accomplish this? If there is any missing info let me know.

I do my best to avoid using localhost, especially when doing mobile development. When running on device, localhost is the device itself. I suggest always using hostnames and DNS.

I agree that using the localhost name can cause some confusion, especially for those who don’t know much about computer networks. Localhost is translated through DNS to, which is the device itself, just as you said.

Taking this into consideration and complementing the details of my problem, from my perspective the main method I’m using to make the connection should work if I can get past this error. This is because my local PHP server is set to (computer), which is connected to my local network as My device is also on the same 10.0.0.x LAN as If I understand correctly when I use the --address: attribute when running the app, the dev server should run in my computer and not in the device. Considering this, the HTTP POST connection method would be fired to, which would be the in the same device that the local PHP server is deployed.

Note: If I try to ping in my computer to, all packages are delivered correctly.

Alternatively I could port forward to port 1337 so that I could access the database from device. However, if possible, I would like to resolve this issue without having to do so.

Updating my problem:

I realized that --address option only accepts the address, without the port. So I ran that way:
ionic cordova run android --address= --port:8100

Now I’m receiving the Ionic message: “Project is running at”, which is a good sign as the dev server is running in the same device as my local PHP server and now I should be able to connect both. However the problem remains the same, I can’t connect to my local server (ERR_CONNECTION_REFUSED).

Apologies if this is either (a) old hat to you and/or (b) irrelevant, but the bind system call takes an address, a host can have many addresses, and if you don’t try to connect to the right one, it will fail. There is a wildcard address of that means “listen on all interfaces”, but if you’re not using it, then you have to care about what address things are listening on. Taking what you said literally,

That must be accessed via

Red herring. Unless the server is listening on, it won’t accept connections to that address.

1 Like

Ok, tried a different approach based on what you said. For debug and development I’m using PHP built in server and I was starting it this way:
php -S localhost:1337

In my APP, the HTTP request was firing to, which was denied right away.

Now I started the PHP server this way: php -S and changed the HTTP request to too. Now I’m not receiving the error imediatelly, but the request in pending for some time until I get the ERR_CONNECTION_TIMED_OUT.

This happened only in one machine, running the same method in other computer worked as expected. Thank you again for helping me with another problem!