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

hamntur's avatar

Laravel Valet share: Failed to connect to 127.0.0.1

Hello!

I'm trying to use the command "valet share" but I'm getting this error: [Httpful\Exception\ConnectionErrorException] Unable to connect to "http://127.0.0.1:4040/api/tunnels": 7 Failed to connect to 127.0.0.1 port 4040: Connection refused

What do I need to do?

Also this: ERROR: Tunnel 'command_line' specifies invalid address 'free.dev:80': unexpected '[' in address free.dev:80

0 likes
29 replies
hamntur's avatar
hamntur
OP
Best Answer
Level 1

Well.. I upgraded composer and runned the command "valet install", and it works!

Max13's avatar

I did it (uninstall, self-update, reinstall) but I still get the same message :(

hamntur's avatar

You also get this? ERROR: Tunnel 'command_line' specifies invalid address 'free.dev:80': unexpected '[' in address free.dev:80

Max13's avatar

Yes, I had this error, not solved by the update/reinstall

dali's avatar

composer global remove laravel/valet

composer self-update

composer global require laravel/valet

valet install

solved mine

14 likes
drouten's avatar

Dali's advice (uninstall, update, reinstall) did not solve this issue on my machine. I'm running Composer -v 1.2.0, Valet v. 1.1.19 and continue to get the Failed to connect to 127.0.0.1 port 4040: Connection refused error repeating every time I try to use valet fetch-share-url from my machine. Does anyone else have any idea how to tackle this issue?

Max13's avatar

@drouten Did you check if you don't have anything listening on port 4040?

lsof -itcp:4040

drouten's avatar

Nothing listening on 4040, anything else I can provide/check? I apologize, my networking skills are still pretty light!

Max13's avatar

@drouten Do you have any error when you install valet? And then you can valet share?

drouten's avatar

Nope, composer uninstall/install work perfectly as does valet install.

fabianhenzler's avatar

I have the same issue :(

valet fetch-share-url --> Failed to connect to 127.0.0.1 port 4040: Connection refused

āžœ matrix42 lsof -itcp:4040

just gives me 0 result

1 like
webbur's avatar

Same issue here as well

Failed to connect to 127.0.0.1 port 4040: Connection refused

1 like
Illess's avatar

All you guys need to do:

  1. sudo apachectl stop
  2. valet restart
debiprasad's avatar

Don't we need to run valet share first before we run valet fetch-share-url?

1 like
bristoldigital's avatar

I've generally experiences hours of problems upgrading Composer/Valet without it necessarily solving the problem.

Valet uses: ngrok

I installed it directly, overwriting the existing (most likely Valet) version. Plus the SSL works!

1 like
Reppair's avatar

Well, same problem latest version of valet and composer also tried all of the above nothing works, nothing is using port 4040 :S ideas?

Unsure's avatar

My own search brought me here for the same error. I ran valet unsecure to remove my local ssl and re attempted valet share and that worked. ngrok will give you a secure and unsecure url to share.

Bradley James Ahrens's avatar

I had this error, followed the instructions to create an account on https://dashboard.ngrok.com/get-started/setup, am able to run ngrok http 80 with no problem, but for some reason, I keep getting this error:

An account is required to use host header rewrite. 

Please register for an ngrok account at: https://dashboard.ngrok.com/signup and install your authtoken.

ERR_NGROK_9018

In CurlFactory.php line 210:
                                                                               
  cURL error 7: Failed to connect to 127.0.0.1 port 4040 after 0 ms: Connecti  
  on refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for htt  
  p://127.0.0.1:4040/api/tunnels       
rhmtin's avatar

@Bradley James Ahrens Finally I found a solution to my problem. Thank You!

Brainmaniac's avatar

I need to upgrade my valet version:

composer global require laravel/valet --ignore-platform-reqs

Please or to participate in this conversation.