13

Hi I've just tried and to install Laravel 8 with sail and I've run into a problem

What I've done is to first run the curl one-liner from laravel's own page

curl -s https://laravel.build/sail-test | bash

once that finished I did as it said and run

cd sail-test && ./vendor/bin/sail up

Everything started as it should, I can connect to the database, I can see the site on http://localhost however I get the following error when trying to migrate:

$ sail artisan migrate:install

   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [2002] No route to host (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
    674▕         // If an exception occurs when attempting to run a query, we'll format the error
    675▕         // message to include the bindings with SQL, which will make this exception a
    676▕         // lot more helpful to the developer instead of just the database's errors.
    677▕         catch (Exception $e) {
  ➜ 678▕             throw new QueryException(
    679▕                 $query, $this->prepareBindings($bindings), $e
    680▕             );
    681▕         }
    682▕ 

      +29 vendor frames 
  30  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

Do i need to change anything in the .env file or do I need to do any other changes first?

Touchpad
  • 662
  • 2
  • 12
  • 29
  • 1
    Do you have a password set in your .env file? If so you probably need to set `MYSQL_ALLOW_EMPTY_PASSWORD` to 'no' in your docker-compose.yml file. – JohanTux Dec 26 '20 at 08:22

4 Answers4

21

First (this command will return your mysql container IP address):

$ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name_or_container_ID>

Second in your .env file:

DB_HOST=<ip_address_returned_from_command_above>

And then:

$ sail artisan migrate

Edit:

Just add to your DB_HOST env var the name of your database container:

...
DB_HOST=mysql
...
Gabriel Fonseca
  • 326
  • 2
  • 3
3

You need to artisan command by login in sail. Here are the steps.

  1. Go to your project directory and run the following command

    sail shell

  2. After that command you will be logged in your container and you can run the artisan migrate command.

webshifu
  • 155
  • 7
0

change the port of XAMP MySQL from 3306 to any other port. Sail migration works when the local port should be 3306.

-2

This worked for me. Hoped it helps.

DB_HOST=0.0.0.0
shaedrich
  • 5,457
  • 3
  • 26
  • 42
Rodney
  • 1
  • 1
    Thank you for your answer, however it it very similar to the other answer and doesn't explain much, not even that your code that not formatted as such should go to the .env file. Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – shaedrich Aug 22 '22 at 13:51