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

aweishaar's avatar

Installing Laravel Dusk - Failed to connect on localhost port 9515: connection refused

I'm trying to install Laravel Dusk following the documentation here: https://laravel.com/docs/5.4/dusk#installation

When I run php artisan dusk, I get the following error:

vagrant@automated-testing:/var/www/html/testing$ php artisan dusk
PHPUnit 5.7.13 by Sebastian Bergmann and contributors.

EE                                                                  2 / 2 (100%)

Time: 1.13 seconds, Memory: 10.00MB

There were 2 errors:

1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY"}}

Failed to connect to localhost port 9515: Connection refused

/var/www/html/testing/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:287
/var/www/html/testing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:121
/var/www/html/testing/tests/DuskTestCase.php:32
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:180
/var/www/html/testing/vendor/laravel/framework/src/Illuminate/Support/helpers.php:639
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:181
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:111
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:85
/var/www/html/testing/tests/Browser/ExampleTest.php:21

2) Tests\Browser\LoginTest::testExample
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY"}}

Failed to connect to localhost port 9515: Connection refused

/var/www/html/testing/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:287
/var/www/html/testing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:121
/var/www/html/testing/tests/DuskTestCase.php:32
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:180
/var/www/html/testing/vendor/laravel/framework/src/Illuminate/Support/helpers.php:639
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:181
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:111
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:85
/var/www/html/testing/tests/Browser/LoginTest.php:20

ERRORS!
Tests: 2, Assertions: 0, Errors: 2.
0 likes
24 replies
aweishaar's avatar

The first thing I tried I needed to do was to make the chromdriver-linux executable.

cd vendor/laravel/dusk/bin; chmod 775 *

It didn't change the error message, but others have noted it did for them.

Also, I realized I had something running on port 9515.

ps -aux | grep 9515

I killed that process

kill ####
7 likes
aweishaar's avatar

I came across this page: https://github.com/laravel/dusk/issues/50

I tried the commands listed by @amochohan

# makes sure all your repos are up to date
sudo apt-get update
# chrome dependencies I think
sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4
# chromium is what I had success with on Codeship, so seemed a good option
sudo apt-get install chromium-browser
# XVFB for headless applications
sudo apt-get -y install xvfb gtk2-engines-pixbuf
# fonts for the browser
sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
# support for screenshot capturing
sudo apt-get -y install imagemagick x11-apps

# Once all this has run through, you need to fire up xvfb on your homestead box. If you’re planning to # do this on a regular basis, you’ll want to get this setup on boot, but for the sake of testing things out:
Xvfb -ac :0 -screen 0 1280x1024x16 &

Which changed my error message to this:

vagrant@automated-testing:/var/www/html/testing$ php artisan dusk
PHPUnit 5.7.13 by Sebastian Bergmann and contributors.

EE                                                                  2 / 2 (100%)

Time: 1.49 seconds, Memory: 10.00MB

There were 2 errors:

1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\UnknownServerException: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.4.0-51-generic x86_64)

/var/www/html/testing/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114
/var/www/html/testing/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:321
/var/www/html/testing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:121
/var/www/html/testing/tests/DuskTestCase.php:32
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:180
/var/www/html/testing/vendor/laravel/framework/src/Illuminate/Support/helpers.php:639
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:181
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:111
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:85
/var/www/html/testing/tests/Browser/ExampleTest.php:21

2) Tests\Browser\LoginTest::testExample
Facebook\WebDriver\Exception\UnknownServerException: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.4.0-51-generic x86_64)

/var/www/html/testing/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114
/var/www/html/testing/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:321
/var/www/html/testing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:121
/var/www/html/testing/tests/DuskTestCase.php:32
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:180
/var/www/html/testing/vendor/laravel/framework/src/Illuminate/Support/helpers.php:639
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:181
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:111
/var/www/html/testing/vendor/laravel/dusk/src/TestCase.php:85
/var/www/html/testing/tests/Browser/LoginTest.php:20

ERRORS!
Tests: 2, Assertions: 0, Errors: 2.
3 likes
aweishaar's avatar

Cannot find Chrome binary took me a long time to realize that didn't mean the chromedriver, but means chrome itself. I installed Chrome following these directions: http://askubuntu.com/questions/79280/how-to-install-chrome-browser-properly-via-command-line

sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt-get install -f
sudo dpkg -i google-chrome*.deb

I attempted to execute google chrome just to make sure the install worked

google-chrome

It gave the error:

[25737:25737:0210/210623.443362:ERROR:browser_main_loop.cc(272)] Gtk: cannot open display:

Since Gtk isn't installed that seemed to be functioning.

After installing that php artisan dusk worked.

I noted afterward in the documentation that the Introduction says: "Instead, Dusk uses a standalone ChromeDriver installation."

On following that link, I clicked on Getting started with ChromeDriver on Desktop. It notes in bold to "Ensure Chromium/Google Chrome is installed in a recognized location."

I didn't catch that, hope it helps someone.

1 like
bickerstoff's avatar

Hi @lars6 ,

I believe this will guide you in the right direction: https://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04/760452#760452?newreg=346a0f7c472b40f09a5ed32e6c633d15

Essentially

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

sudo dpkg -i --force-depends google-chrome-stable_current_amd64.deb

sudo apt-get install -f

I think those commands are actually easier than the accepted answer though the accepted answer will work, too. You could install it graphically as well, but homestead is headless by default.

5 likes
costi's avatar

I did all the suggested steps, this is what I got now:

There was 1 error:                                                                                                                                                                                                 
                                                                                                                                                                                                                   
1) Tests\Browser\LoginTest::testExample                                                                                                                                                                            
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY"}}                                    
                                                                                                                                                                                                                   
Operation timed out after 500 milliseconds with 0 bytes received                                                                                                                                                   
                                                                                                                                                                                                                   
/usr/share/nginx/msfs/proiect/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:287                                                                                                                     
/usr/share/nginx/msfs/proiect/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:121                                                                                                                         
/usr/share/nginx/msfs/proiect/tests/DuskTestCase.php:33                                                                                                                                                            
/usr/share/nginx/msfs/proiect/vendor/laravel/dusk/src/TestCase.php:209                                                                                                                                             
/usr/share/nginx/msfs/proiect/vendor/laravel/framework/src/Illuminate/Support/helpers.php:652                                                                                                                      
/usr/share/nginx/msfs/proiect/vendor/laravel/dusk/src/TestCase.php:210                                                                                                                                             
/usr/share/nginx/msfs/proiect/vendor/laravel/dusk/src/TestCase.php:116                                                                                                                                             
/usr/share/nginx/msfs/proiect/vendor/laravel/dusk/src/TestCase.php:88                                                                                                                                              
/usr/share/nginx/msfs/proiect/tests/Browser/LoginTest.php:37       

any idea, how can I fix that

potsky's avatar

Same problem in a Docker container. This is a problem of permission with the sandbox default mode of Chrome. I finally solved this by adding the option --no-sandbox in the DuskTestCase class :

        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox'
        ]);
5 likes
coursesaver's avatar

@potsky where in the DuskTestCase class did you put that? I, like costi, have done everything here and have yet to get past the following error...

Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY"}}  
coursesaver's avatar

@potsky THANKS SO MUCH FOR YOUR CODE!!! It made all the difference, a little more digging in the documentation helped me find what you were talking about!

use Facebook\WebDriver\Chrome\ChromeOptions;

/**
 * Create the RemoteWebDriver instance.
 *
 * @return \Facebook\WebDriver\Remote\RemoteWebDriver
 */
protected function driver()
{
    $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox'
        ]);

    return RemoteWebDriver::create(
        'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
            ChromeOptions::CAPABILITY, $options
        )
    );
}
1 like
namdp06's avatar

@COSTI - Did you run php artisan dusk as root user? Please try to run by other user

narh's avatar

In my DuskTestCase file CAPABILITY is cancelled . How do i resolve it . I am using mac

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

narh's avatar

I found the solution. I had to feed the APP_URL with the server url

kodzero's avatar

I have an ARM architecture by Mac OS arm M1 Homestead and I have idea change my defaut browser for get point. then I had changed the default browser to the Firefox I had done:

$sudo apt-get update
$sudo apt-get upgrade
$sudo apt install firefox
$php artisan dusk:install-firefox
$php artisan dusk:firefox-driver

I saw again same as error with another port.

$php artisan dusk
PHPUnit 9.5.16 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 00:00.389, Memory: 20.00 MB

There was 1 error:

1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"firefox","moz:firefoxOptions":{"args":["--headless","--window-size=1920,1080"],"prefs":{"reader.parse-on-load.enabled":false,"devtools.jsonview.enabled":false,"devtools.console.stdout.content":true}}}]},"desiredCapabilities":{"browserName":"firefox","platform":"ANY","moz:firefoxOptions":{"args":["--headless","--window-size=1920,1080"],"prefs":{"reader.parse-on-load.enabled":false,"devtools.jsonview.enabled":false,"devtools.console.stdout.content":true}}}}

Failed to connect to localhost port 4444: Connection refused

/home/vagrant/code/truck-driver.brothersprinting.net/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:333
/home/vagrant/code/truck-driver.brothersprinting.net/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:131
/home/vagrant/code/truck-driver.brothersprinting.net/tests/DuskTestCase.php:48
/home/vagrant/code/truck-driver.brothersprinting.net/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:219
/home/vagrant/code/truck-driver.brothersprinting.net/vendor/laravel/framework/src/Illuminate/Support/helpers.php:243
/home/vagrant/code/truck-driver.brothersprinting.net/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:220
/home/vagrant/code/truck-driver.brothersprinting.net/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:98
/home/vagrant/code/truck-driver.brothersprinting.net/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:66
/home/vagrant/code/truck-driver.brothersprinting.net/tests/Browser/ExampleTest.php:21

I will back if I would finish this way.

Please or to participate in this conversation.