Laravel Migration stalls and doesn't do anything
Asked Answered
S

6

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

Strawser answered 22/7, 2018 at 17:45 Comment(19)
What's in your migration?Meara
just the two migrations that come prepackaged with in an install. create_users_table.php and create_password_resets_table.phpStrawser
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).Grey
the versions of everything is in the question above i added the mySql version as well.Strawser
Try running DB::select('SHOW TABLES'); in artisan's tinker just to see if you get a response from the database.Meara
When I run that I dont get a response.Strawser
sounds like something is wrong with artisan.Actuate
@Strawser is APP_DEBUG set to true in your .env?Subphylum
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.Peru
@Subphylum APP_DEBUG is set to true in the .env file @JithinJose I'm not using any container/VM unless Homebrew is considered one.Strawser
can you share the ./storage/logs/laravel.log?Subphylum
What does which php tell you?Seneca
@Seneca running that gives me this /usr/local/bin/phpStrawser
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?Seneca
How did you create the database?Babb
@Seneca when I run the artisan list command it shows me the whole list.Strawser
do you have php-mysql or php7.2-mysql installed?Mohenjodaro
php7.2-mysql installed when I check the version in the database i get v8.0.11Strawser
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 :)Clair
A
11

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~

Actuate answered 27/7, 2018 at 16:4 Comment(1)
This site helped me with understanding with the GRANT digitalocean.com/community/tutorials/…Strawser
B
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).

Bergson answered 25/7, 2018 at 18:46 Comment(15)
You want a solution for the first problem? (hanging up on migration problem) then we need to see the migration classBergson
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.Strawser
Have you added anything to config/app.php?Bergson
I have not added anything to the config/app.php file.Strawser
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?Bergson
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.Strawser
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).Bergson
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.Strawser
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 missingBergson
I installed everything thought homebrew and composer, wondering if downgrading mysql version would make a difference.Strawser
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. bugs.php.net/bug.php?id=76660 you can update this stackoverflow.com question with this error now that we know exactly whats the errorBergson
Site is here laravel.com/docs/5.6/installation and i was watching the tut on here as well. laracast - laracasts.com/series/laravel-from-scratch-2017Strawser
Did you setup config/database.php properly? laravel.com/docs/5.6/database#configurationBergson
Let us continue this discussion in chat.Strawser
Let us continue this discussion in chat.Strawser
P
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

Penal answered 27/7, 2018 at 15:18 Comment(2)
did the down grade and it didn't change anything.Strawser
I upgraded to 7.2.8 and got the exact same error message as you. I read the PHP bug report, downgraded, and it solved it for me.Penal
W
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.

Waly answered 24/9, 2018 at 12:7 Comment(0)
V
0

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

Varices answered 21/7, 2020 at 3:56 Comment(0)
L
-2

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

Lloyd answered 26/7, 2018 at 11:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.