cURL + Laravel Valet + dnsmasq not working
Asked Answered
E

5

16

when I execute a PHP script which runs a cURL request to a .test domain that is setup on my Mac with Laravel Valet/dnsmasq, I get this error printed :

Could not resolve: mydomain.test (Domain name not found)

When I test the domain in my browser, it's OK.
When I run curl -Ik https://mydomain.test in the Terminal, I get HTTP/2 200 code, so it's OK.
When I run curl -k https://mydomain.test in the Terminal I get the source code of the page, so it's OK.

Why is it not working with cURL from PHP ? I'm desperate...

UPDATE

Due to popular demand ;-) here is my cURL code. You cannot do more simple :

try {
    $ch = curl_init( "http://mydomain.test" );
    curl_exec( $ch );
    dump(curl_error($ch));
    curl_close( $ch );
} catch (Exception $e) {
    var_dump($e);
}
Euphonious answered 14/2, 2019 at 10:40 Comment(4)
Can you share your PHP curl code?Mathes
It's difficult to say something without your php curl codeFalconiform
I've updated with code.Euphonious
Try this: #54688951Concha
I
49

This problem is caused by curl versions, can you check your curl versions from terminal by

curl --version and php --ri curl

When you run php --ri curl you will see cURL Information => 7.63.0 this line.

Then you can compare your versions and you see which curl version is not working with dnsmasq.

I encountered this problem and my curl version was 7.64.0 in php.


For solve that issue:

You can uninstall curl-openssl, this command will remove last version of curl-openssl:

brew uninstall curl-openssl --ignore-dependencies

Then restart php:

brew services restart php

After restarting, php will see curl which is /usr/bin/curl and this version can access local domain.

Iey answered 27/2, 2019 at 14:57 Comment(6)
I've uninstall curl-openssl (which was 7.64) and it still does not work with the other curl which is 7.54. I restarted valet and php.Euphonious
Worked out for me. Should be the accepted answer ! Thanks a lot mate !Ary
needed valet restart as stated by Leo Moraes's answer, and it works greatBanting
I was looking for solution for days. brew uninstall curl-openssl --ignore-dependencies is worked for me. thank yo very muchZingale
Unfortunately, Apache would not start anymore: httpd: Syntax error on line 194 of /usr/local/etc/httpd/httpd.conf: Cannot load /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so into server: dlopen(/usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so, 10): Symbol not found: _curl_mime_addpart\n Referenced from: /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so\n Expected in: /usr/lib/libcurl.4.dylib\n in /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.soConclusive
Apache also wont start for me. Same error as above. So this answer fixes one issue but introduces another, at least on PHP 7.3Connally
S
7

....After restarting, php will see curl which is /usr/bin/curl and this version can access local domain.

After restarting too the valet: valet restart

Skulk answered 28/2, 2019 at 19:17 Comment(0)
T
5

Adding 127.0.0.1 to my DNS settings fixed this issue for me. i.e. System Preferences -> Network -> Advance -> DNS

And Run valet restart afterwards

Tobytobye answered 18/12, 2019 at 8:10 Comment(0)
N
3

I solved this by adding domain.test to /etc/hosts

i.e., in the hosts file add: 127.0.0.1 domain.test

Nunhood answered 27/8, 2020 at 21:24 Comment(0)
S
2

Just spent the last hour on this. I had a similar problem with curl through PHP not resolving with Valet specially for SSL. I tried changing curl-openssl versions and also setting my domain in the host file etc. Nothing worked apart from the following:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

This is due to the valet SSL not being verified by Curl. Once I added this option to my curl request I was able to fetch data from my local valet url.

Selfdrive answered 17/12, 2019 at 14:12 Comment(2)
No clue why this was downvoted. The widely-accepted answers above make no case for causation, while this answer feels like it's far closer to doing so (although it didn't work for me).Haught
You probably saved me a few hours with this reply. Thank you!Incorrect

© 2022 - 2024 — McMap. All rights reserved.