sebastiansulinski's avatar

Dusk database migrations with .env.dusk.local and Homestead

I'd really want to make use of Dusk, but after spending hours I'm still without any luck setting it up to make it work with database.

I've added .env.dusk.local and tried sqlite with :memory: and with the actual database file. I also tried mysql with homestead, which is what I use for my local environment using database created specifically for tests with host 127.0.0.1 and port 33060 and standard homestead credentials, but again - without any luck - I constantly get:

Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = cms and table_name = migrations)

The only time that it does work is when I use these settings in the main .env file.

Weirdly, when I check the .env file when dusk is running - it does update all variables to the ones from the .env.dusk.local and makes the backup of the original one so I wonder if the problem is perhaps with the delay between the local directory and the homestead?

Could someone point me in the right direction?

0 likes
5 replies
sebastiansulinski's avatar

It does however fail to work after you reboot your machine and start the homestead again, which is a shame. It looks like the Valet is probably the only way to make it work, unless of course you want to go back to Mamp.

tpraxl's avatar

Solution for making dusk available immediately after the reboot:

I found that somewhere and adapted it (sorry, due to lack of memory, I can not refer to it):

Provide a script start-xvfb.sh with the content:

#!/usr/bin/env bash
#
# Runs virtual frame buffer

Xvfb -ac :0 -screen 0 1280x1024x16 &

In your Vagrantfile, just before the last end, insert this:

# always start virtual framebuffer
config.vm.provision "shell", run: "always" do |s|
    s.name = "Starting Virtual Framebuffer"
    s.path = File.dirname(__FILE__) + "/start-xvfb.sh"
end

(It should be a sibling block to the if/end block if File.exists? afterScriptPath then ... end).

In your after.sh, at the end: (notice that I run it with privileged: false, so I have to sudo, which you might not need):

# enable laravel dusk (google-chrome, xvfb)
sudo apt-get update
sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4
sudo apt-get -y install chromium-browser
sudo apt-get -y install xvfb gtk2-engines-pixbuf
sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
sudo apt-get -y install imagemagick x11-apps

Hope this helps. I'm currently fighting database problems with laravel dusk (sqlite in .env.dusk.local) and stumbled upon this thread accidently.

Please or to participate in this conversation.