Trouble with MySQL on Lumen php

Then I try to migrate artisan, I have a message MySQL server has gone away and “in connector.php in line 68” it’s lumen db file.

Line: “return new PDO($dsn, $username, $password, $options);”


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This line creates the connection between your php script and your MySQL server. The two most common reasons for this error are:

  • The MySQL service is not running or crashed. You can restart it with service mysql restart and check the logs in /var/log/mysql/error.log

  • Your MySQL server configuration that was migrated does not match with what is configured on the server. Make sure to use localhost or for the local MySQL service. If you configure this with your public IP address it will not work since MySQL does not listen publicly by default for security reasons.

  • Your code is opening and reusing a connection without checking it’s status. If you create a connection to a MySQL server and leave it open it may eventually time out. When the PHP script attempts to use it again it will return this error.

Because you are seeing this error on a new PDO() call I would guess that it is one of the first two possibilities and since you are migrating I would check your configuration first to make sure it specifies the correct db information.