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

jader's avatar
Level 4

Laravel Dusk x Laradock: Failed to connect to localhost port 9515: Connection refused

Hello guys, I use Laradock in my development environment. Laradock runs on top of WSL, and I'm trying to use Laravel Dusk. I installed it, but when I run "artisan dusk", I get the error message "Failed to connect to localhost port 9515: Connection refused."

I've read some things on the forum, but they're not very recent, so I'm not sure if they apply to my case. In other words, it seems like Chrome has not been installed, and that's why this error appears.

My Linux knowledge is quite limited, so could someone here please guide me on how to fix this error? Thank you very much.

My Dusktestcase.php


namespace Tests;

use Illuminate\Support\Collection;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\TestCase as BaseTestCase;

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;

    /**
     * Prepare for Dusk test execution.
     *
     * @beforeClass
     */
    public static function prepare(): void
    {
        if (! static::runningInSail()) {
            static::startChromeDriver();
        }
    }

    /**
     * Create the RemoteWebDriver instance.
     */
    protected function driver(): RemoteWebDriver
    {
        $options = (new ChromeOptions)->addArguments(collect([
            $this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
        ])->unless($this->hasHeadlessDisabled(), function (Collection $items) {
            return $items->merge([
                '--disable-gpu',
                '--headless=new',
            ]);
        })->all());

        return RemoteWebDriver::create(
            $_ENV['DUSK_DRIVER_URL'] ?? 'http://localhost:9515',
            DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY, $options
            )
        );
    }

    /**
     * Determine whether the Dusk command has disabled headless mode.
     */
    protected function hasHeadlessDisabled(): bool
    {
        return isset($_SERVER['DUSK_HEADLESS_DISABLED']) ||
               isset($_ENV['DUSK_HEADLESS_DISABLED']);
    }

    /**
     * Determine if the browser window should start maximized.
     */
    protected function shouldStartMaximized(): bool
    {
        return isset($_SERVER['DUSK_START_MAXIMIZED']) ||
               isset($_ENV['DUSK_START_MAXIMIZED']);
    }
}
0 likes
6 replies
LaryAI's avatar
Level 58

The error message "Failed to connect to localhost port 9515: Connection refused" indicates that the ChromeDriver server is not running. To fix this error, you need to start the ChromeDriver server.

Here are the steps to start the ChromeDriver server:

  1. Install Chrome on your system if it is not already installed.

  2. Download the ChromeDriver executable from the official website: https://sites.google.com/a/chromium.org/chromedriver/downloads

  3. Extract the downloaded file and move the executable to a directory that is in your system's PATH.

  4. Start the ChromeDriver server by running the following command in your terminal:

chromedriver --port=9515
  1. Once the ChromeDriver server is running, you can run your Dusk tests by running the following command:
php artisan dusk

Note: If you are using Laradock, you need to start the ChromeDriver server inside the container. You can do this by SSHing into the container and running the above command.

jader's avatar
Level 4

@LaryAI I can't install Chrome in Laradock's workspace. To do so, I need admin credentials. If I type "su -", it prompts for a password, but I don't know what the password is.

jader's avatar
Level 4

Could someone help me install Chrome on Laradock's workspace?

jader's avatar
Level 4

I found an instruction on the internet to do the following:

Update WORKSPACE_INSTALL_DUSK_DEPS to true. Run docker-compose build workspace.

So I did that, and now the error is different. I don't know if it got worse than before... any tips?

1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\UnknownErrorException: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Please or to participate in this conversation.