4

Just went through all the steps listed on the Laravel site to install and get up and running for MacOS HighSierra. I currently have Composer, Homebrew, valet, PHP 7.2.8, MySQL version 8.0.11 and Laravel 5.6.28 installed. I can create a new project by doing the Laravel new blog command and not have any problems. Also when I go to my browser I can see current project I just created or am working on. I can run the valet list command and so I know its running/working. I also can create a migration and have it show up in my project as well by running the php artisan make:migration test_test_test.

My PATH also has ~/.composer/vendor/bin in it as well.

my .env file look like such

APP_NAME=Laravel
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog        
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1 
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp 
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

I run the php artisan migrate -vvv command and it runs and stalls/hangs up with no output. I have to ctl-c to get out of it. tried the -v /-vv as well, did the same thing.

I created a database named blog and even add a table test manually to make sure that the database was working/running.

Update

Went ahead and uninstall MySQL and reinstall it. I was able to get the php artisan migrate -v command to run and am getting this error.

now I'm getting this error.

MacBook-Pro:anything computername$ php artisan migrate -v

PDOException  : SQLSTATE[HY000] [2006] MySQL server has gone away

at /Users/computername/Sites/anything/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
64|         if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) {
65|             return new PDOConnection($dsn, $username, $password, $options);
66|         }
67| 
> 68|         return new PDO($dsn, $username, $password, $options);
69|     }
70| 
71|     /**
72|      * Determine if the connection is persistent.

Exception trace:

Created a router and view that connects to a table that I creates to see if I would be able to access the database variables and print them out. On return I got this error.

Exception message: PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109

Jonas Staudenmeir
  • 24,815
  • 6
  • 63
  • 109
whisk
  • 713
  • 1
  • 10
  • 34
  • What's in your migration? – Devon Bessemer Jul 22 '18 at 18:00
  • just the two migrations that come prepackaged with in an install. `create_users_table.php` and `create_password_resets_table.php` – whisk Jul 22 '18 at 18:08
  • Try increasing verbosity, `art migrate --verbose` and edit question with the output. What does `php --version` output, did you ran `composer install` with no errors? What is your MySQL version? (`mysql --version`). – Kyslik Jul 22 '18 at 18:18
  • the versions of everything is in the question above i added the mySql version as well. – whisk Jul 22 '18 at 18:27
  • Try running `DB::select('SHOW TABLES');` in artisan's tinker just to see if you get a response from the database. – Devon Bessemer Jul 22 '18 at 18:45
  • When I run that I dont get a response. – whisk Jul 22 '18 at 18:52
  • 1
    sounds like something is wrong with artisan. – poohbear Jul 23 '18 at 00:57
  • @whisk is `APP_DEBUG` set to `true` in your `.env`? – Quezler Jul 25 '18 at 08:15
  • Are u using any containers/VM? If yes, then make sure that database is connectable from the system which running the `php artisan migrate` command. – Jithin Jose Jul 25 '18 at 09:13
  • @Quezler `APP_DEBUG` is set to `true` in the `.env` file @JithinJose I'm not using any container/VM unless Homebrew is considered one. – whisk Jul 25 '18 at 12:24
  • can you share the `./storage/logs/laravel.log`? – Quezler Jul 25 '18 at 13:48
  • What does `which php` tell you? – miken32 Jul 25 '18 at 14:02
  • @miken32 running that gives me this `/usr/local/bin/php` – whisk Jul 25 '18 at 14:16
  • And is that the correct version of PHP that you expect to be running? Can you get any output from artisan? `php artisan list` or anything? – miken32 Jul 25 '18 at 14:17
  • How did you create the database? – Jonas Staudenmeir Jul 25 '18 at 14:32
  • @miken32 when I run the `artisan list` command it shows me the whole list. – whisk Jul 25 '18 at 14:53
  • do you have php-mysql or php7.2-mysql installed? – rüff0 Jul 25 '18 at 19:24
  • php7.2-mysql installed when I check the version in the database i get v8.0.11 – whisk Jul 25 '18 at 19:35
  • It appears to be mismatch in how password is verified. The fix **should** be changing the password for that particular user from MySQL terminal. Open the terminal, and set the password like this: `mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'add your password here';`. Seeing this is the classic test / dev setup, using `root` / `root` for MySQL user isn't uncommon. Try doing that, add the new password to `.env` and report back if it worked :) – N.B. Jul 25 '18 at 22:29

6 Answers6

10

I myself had this problem and getting the error Exception message: PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109

This is how i fixed it:

I logged into mysql as root user like so mysql –uroot –p and entered my password

You can get a list of the users that are on the server by typing this SELECT User, Host FROM mysql.user;

Make sure that you see the user you are trying to connect to the database from your .env file. You will need to altered the current user to use the caching_sha2_password that is required in the lasted version of mysql.

Here is that command.

ALTER USER `username`@`localhost` IDENTIFIED WITH caching_sha2_password BY 'password';

While still logged in as root user you need to run this command to allow for your user to do the needed tasks that are allowed for an php artisan migrate to happen. Ex: CREATE, DROP, ALTER, DELETE and such.

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';

If this doesn’t work you can also pick and choose what commands you want to allow instead of giving them complete access.

GRANT SELECT, INSERT ON *.* TO 'someuser'@'somehost';

Hope this helps~

poohbear
  • 442
  • 3
  • 15
  • This site helped me with understanding with the GRANT https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql – whisk Jul 27 '18 at 16:27
1

Server has gone away is a MySql error, check this link

Check that your mysql service is indeed running and afterwards, that you've got the right credentials on you .env file

About the 'initial error' on migrations, we need to see what's in the migration code.

Edit: Since the migrations are Laravel's default, then the issue probably lies upon the connection between Laravel and the database.

To confirm this:

  1. Create a database manually;
  2. Create a table and place a row in it;
  3. Create a route that returns DB::statement('select * from tablejustcreated');

Make the request to that route and if it freezes up, boom, it's the connection and most likely, .env file credentials (username and password, host, port).

abr
  • 2,071
  • 22
  • 38
  • You want a solution for the first problem? (hanging up on migration problem) then we need to see the migration class – abr Jul 25 '18 at 18:48
  • Im using the two migrations that come pre packaged with a fresh install of laravel. `create_users_table.php` and `create_password_resets_table.php`. I haven't done anything to them but i can still post them. – whisk Jul 25 '18 at 18:51
  • Have you added anything to config/app.php? – abr Jul 25 '18 at 18:55
  • I have not added anything to the config/app.php file. – whisk Jul 25 '18 at 18:56
  • Try adding --force to your migration command. It is possible that has something to do with valet, have you had any errors installing anything so far and did you follow the tutorial on laravel's page? – abr Jul 25 '18 at 18:59
  • I used everything form the Laravel page and from the Laracast website as well. I haven't had any problems with anything during the install. – whisk Jul 25 '18 at 19:01
  • You can check if it's the connection that Laravel has to the database by manually creating a table (just for the sake of it, then delete it) and create a route that returns something from that table (db::statement('select * from temptable')). The connection from Laravel to MySql is most likely the issue (check if your .env file is indeed correct). – abr Jul 25 '18 at 19:04
  • created a table and added some data, when i run it in the browser it times out and says : `Exception message: PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109`, im guessing it has to do with mysql and its connection. – whisk Jul 25 '18 at 19:31
  • Its php's connection to the database. Did you install something of this soft? Sudo apt-get install php7.2 mysql. At the very least, now you know exactly the error, something is missing – abr Jul 25 '18 at 19:41
  • I installed everything thought `homebrew` and `composer`, wondering if downgrading mysql version would make a difference. – whisk Jul 25 '18 at 19:43
  • Can you show me the tutorial that youve followed? Also, dont know If this help but teres a bug report 2 days ago of this similar thing with the solution being to down grade php's version. https://bugs.php.net/bug.php?id=76660 you can update this stackoverflow.com question with this error now that we know exactly whats the error – abr Jul 25 '18 at 19:49
  • Site is here https://laravel.com/docs/5.6/installation and i was watching the tut on here as well. laracast - https://laracasts.com/series/laravel-from-scratch-2017 – whisk Jul 25 '18 at 19:53
  • Did you setup config/database.php properly? https://laravel.com/docs/5.6/database#configuration – abr Jul 25 '18 at 19:54
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176753/discussion-between-whisk-and-abr). – whisk Jul 25 '18 at 20:51
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176875/discussion-between-whisk-and-abr). – whisk Jul 27 '18 at 12:54
0

It is a known bug in PHP 7.2.8. Downgrade to PHP 7.2.7 until it is fixed.

I hit the same problem when I upgraded from PHP 7.2.7 to PHP 7.2.8.

See https://bugs.php.net/bug.php?id=76651

fisharebest
  • 1,300
  • 10
  • 16
0

Many thanks to @poohhbear and everyone else for helping me get this fixed.

What actually worked for me was:

ALTER USER 'myusername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypassword';

...presumably because the new MySQL defaulted to caching_sha2_password and PHP didn't know how to handle that.

Brendan White
  • 435
  • 2
  • 8
  • 17
0

I had same problem, i fix it by flush privileges.

-1

try this php artisan migrate --force [https://laravel.com/docs/5.6/migrations] this a documentation of migrate i think could be useful