'Accessing the host machine from within a Homestead guest VM with curl
I'm trying to access api url which runs on my host machine from within a Homestead VM with curl. When I execute the code from within the guest VM it returns the error Failed to connect to 10.0.2.15 port 8001: Connection refused, 10.0.2.15 is the ip of the host inside the guest. I suspect the solution must be found in port forwading, I have tried port forwarding inside Homestead.yml but it did't resolve the issue.
This is the curl call.
$defaultParams = array(
CURLOPT_HEADER => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLINFO_HEADER_OUT => TRUE,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => $this->apiKey.':',
CURLOPT_HTTPHEADER => array( 'Expect:' ),
CURLOPT_FAILONERROR => true
);
$url = 'http://10.0.2.15:8001/api/languages?display=full&ws_key=xxxxx';
$session = curl_init($url);
...
If I access the url on the host I get the expected result:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

