2.8.4.2.3. Configure database connection in Laravel

Attention!

The connection will not work with the localhost host. The host address must be taken from the database connection credentials.

Database connection details in Laravel are specified in the database configuration file:

  • If you are using an .env file, you need to change the following lines:
    DB_HOST=host
    DB_PORT=3306
    DB_DATABASE=database
    DB_USERNAME=username
    DB_PASSWORD=password
  • If you are using the config/database.php file, you need to modify the following lines:
    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'host'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'database'),
        'username' => env('DB_USERNAME', 'username'),
        'password' => env('DB_PASSWORD', 'password'),
        'unix_socket' => env('DB_SOCKET', ''),

Please note that after editing the configuration files, you may need to refresh the cache. Use the following commands to refresh the cache:

php artisan config:clear
php artisan config:cache

You can select the desired PHP version by following the instruction.

You can edit files using the file manager or any FTP client.

Content