Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

soniyakukreja's avatar

while running php artisan migrate command do laravel run provider before or later

Hello Team, I'm storing my database connectivity details at AWS secret manager and retrieve the same in my custom service provider stored as path App\Providers\AWSserviceManagerProvider.php This works fine on all requests, but when I run PHP artisan migrate it throws the error that "Unknown storage engine 'mysql' "

the error I'm getting is "SQLSTATE[42000]: Syntax error or access violation: 1286 Unknown storage engine 'mysql' (SQL: create table coupon_templates..........."

when I set my database details in the .env file and run the migration command it works fine. Do laravel run provider later on while we run migration? Or should I set database details in some another file so that the project always gets connected to the specified database before anything else? anybody helps me to solve this error, please?

I appreciate any help you can provide.

0 likes
2 replies
LaryAI's avatar
Level 58

The issue is that the AWSserviceManagerProvider.php file is being loaded before the database connection is established during the migration process. To solve this, you can move the code that retrieves the database connectivity details from AWS secret manager to the database.php configuration file.

Here's an example of how you can do this:

  1. Open the config/database.php file.
  2. Replace the database configuration values with placeholders. For example:
'mysql' => [
    'driver' => 'mysql',
    'host' => '{DB_HOST}',
    'port' => '{DB_PORT}',
    'database' => '{DB_DATABASE}',
    'username' => '{DB_USERNAME}',
    'password' => '{DB_PASSWORD}',
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'strict' => true,
    'engine' => null,
],
  1. In the AWSserviceManagerProvider.php file, retrieve the database connectivity details from AWS secret manager and replace the placeholders in the database configuration array with the actual values. For example:
use Illuminate\Support\Facades\Config;

// Retrieve the database connectivity details from AWS secret manager
$databaseDetails = getDatabaseDetailsFromAwsSecretManager();

// Replace the placeholders in the database configuration array with the actual values
Config::set('database.connections.mysql.host', $databaseDetails['host']);
Config::set('database.connections.mysql.port', $databaseDetails['port']);
Config::set('database.connections.mysql.database', $databaseDetails['database']);
Config::set('database.connections.mysql.username', $databaseDetails['username']);
Config::set('database.connections.mysql.password', $databaseDetails['password']);
  1. Now, when you run the migration command, Laravel will first load the database configuration file and replace the placeholders with the actual values before establishing the database connection.

Note: Make sure to handle any errors that may occur when retrieving the database connectivity details from AWS secret manager.

soniyakukreja's avatar

@LaryAI

'mysql' => [ 'driver' => 'mysql', 'host' => '{DB_HOST}', 'port' => '{DB_PORT}', 'database' => '{DB_DATABASE}', 'username' => '{DB_USERNAME}', 'password' => '{DB_PASSWORD}', 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ], changing the code of the database file as you mentioned above throws the following error

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for {DB_HOST} failed: Name or service not known

Please or to participate in this conversation.