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

cyberduck's avatar

Laravel Brower Test (Dusk) error on MacOS (Docker): Failed to connect on localhost port 9515: connection refused

I just installed Laravel's Dusk to add browser tests. However, when I run a test, I get a Failed to connect on localhost port 9515: connection refused error.

I checked online and it seems like a lot of people are having the same issue. I came across few solutions e.g. this but it seems like they are all for Windows and Homestead whilst I am running my project on MacOS and Docker.

I did try to follow the solution but I found out sudo apt is not available for MacOS. I then installed Homebrew and tried to run the commands starting with brew instead of sudo apt but it responds saying no formula available for the name.

I would really appreciate it if you could recommend a solution or source I could look at. Thank you.

0 likes
3 replies
aurawindsurfing's avatar

Hey @cyberduck

This I did try to follow the solution but I found out sudo apt is not available for MacOS clearly shows that you try to run your commands in wrong place. If you have docker then this is where your application lives, this is where you run your php artisan commands and etc.

Brew is for MacOS, your are not on MacOS, you are on docker which is linux and has apt get I'm sure you know how to log in into your docker machine and run php artisan commands in there. This is the right place.

On another note, do yourself a favour and install https://laravel.com/docs/master/valet I should mark a day when I discovered it in my calendar next to other important stuff 🤪

Hope it helps!

cyberduck's avatar

Hey, I just realised this recently. I still have a lot to learn, haha.

I've pretty much been running my tests locally and not on docker which I shouldn't have been doing in the first place.

I've got this working now though by following the steps to running Laravel Dusk 3.0 tests in Docker environments.

Thanks you very much for the link too. I will install it, looks like a lifesaver.

aurawindsurfing's avatar

I ended up using it after laradock and homestead. Simple and really impressive.

Please or to participate in this conversation.