Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

isaackearl's avatar

Why can't I cURL between my virtual hosts? (puphpet)

Heyo,

This might be a silly question, but I'm posting here to see if anybody has run into this issue before. I have 2 applications running on my local VM. I'm trying to use cURL to make a request from one server to the other... but it seems like no matter what I do it can't resolve the hostname.

I've used guzzle, plain curl, and tried some other options and they all just throw an error saying can't resolve hostname to my virtual host.

I CAN however, curl to any live public domain. For example I can hit the address for the production server of my application.

For example let's say I have my local environment server #1 at website.dev and website2.dev. I also have a production version of site #2 at myrealwebsite.com . I can curl from website.dev to myrealwebsite.com, but I can't hit website2.dev using cURL.

I know the local development server that I can't reach via curl is working. I can hit the same endpoint via POSTMAN, or through my browser etc. But it might as well not be there when it comes to trying to hit it with curl.

Thanks if anybody has any ideas. For now I have a workaround for my testing of putting up a test server on a public URL to represent my server #2.

-Isaac

0 likes
9 replies
ohffs's avatar

Maybe manually add entries to the /etc/hosts file on each VM. Like :

192.168.1.55 website.dev
192.168.1.56 website2.dev

Might also work if you put those entries on the "real" servers hosts file - depends how your VM server is resolving addresses.

isaackearl's avatar

@ohffs

Ya currently my hosts file looks very similar to that except they both have the same IP. Since it is a virtual host. To be fully clear I am using puphpet for my local VM that has these 2 apps running.

ohffs's avatar

If you just run 'host website.dev' inside your VM, does it come back with anything? What does your /etc/resolve.conf and /etc/hosts on the VM look like? Also maybe do a 'grep hosts /etc/nsswitch.conf' and check that "files" is the first entry listed against it.

isaackearl's avatar

@ohffs I will post all of that in a minute.. but should I be looking at all these files on my host machine... or on the VM itself?

I did the host command in the VM as you said, and I get

Host website2.dev not found: 3(NXDOMAIN)

ohffs's avatar
ohffs
Best Answer
Level 50

Double check the /etc/hosts file inside your VM. That command usually tries and find things there first (although nsswitch.conf can change things around).

isaackearl's avatar

@ohffs Sorry it took me so long to respond! And I really appreciate the help.

So here are the contents of those files. You are right my /etc/hosts file on my machine has not been modified at all.

/etc/hosts

::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

etc/resolv.conf

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.0.2.3
search Cisco

and the grep looks like this:

$ grep hosts /etc/nsswitch.conf
11:hosts:          files dns

I'll try adding an entry to 127.0.01 for the website2.dev to the hosts file and see what that does.

ohffs's avatar

That's ok - it's Friday evening for me so I'm about to sign off for the night :-) I hope you get it sorted in the meantime - I'll try and look for any replies in the morning :-)

isaackearl's avatar

@ohffs

Well editing my vm's hosts file did the trick! Thanks alot! :D

1 like

Please or to participate in this conversation.