...
/Comprehensive Guide to Laravel Migrations Setup and Implementation
Comprehensive Guide to Laravel Migrations Setup and Implementation
Learn about Laravel database setup, configuration, migrations, and modification.
Introduction to database setup in phpMyAdmin
Laravel supports multiple database management system (DBMS) connections. phpMyAdmin is a popular web-based administration tool used for managing and administering MySQL or MariaDB databases. It comes with a built-in installation of MySQL libraries. Both CLI and phpMyAdmin can opt to create a database.
Overview of Laravel environment variables setup
In the Laravel framework, configuration settings are saved using environment variables in the .env
file. These settings can change depending on where the application is being hosted. This allows developers to store sensitive information (such as email passwords), host database credentials, and other required configuration options. These configurations can be reused without writing them into our code. Laravel provides an .env
file in the root directory. This file uses a format with KEY=VALUE
syntax to assign values to global configuration-based variables. Here’s an example of a basic .env
file:
LOG_CHANNEL=stackLOG_DEPRECATIONS_CHANNEL=nullLOG_LEVEL=debugDB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=laravelDB_USERNAME=rootDB_PASSWORD=............................
After creating the database, the next step is to set up database configuration variables in the Laravel app. Laravel provides six environment variables to manage database-related configuration. The variables, along with their definitions, are given below:
DB_CONNECTION
: This variable specifies the type of database we want to connect to. In this case, it’s set to MySQL, indicating that the application will connect to a MySQL database.DB_HOST
: This variable defines the host or IP address of the database server. The value127.0.0.1
refers to the local machine, indicating that the database server is running on the same machine as the Laravel application.DB_PORT
: This variable specifies the port number on which the database server is listening. The value3306
is the default port for MySQL.DB_DATABASE
: This variable specifies the name of the database we want to connect to. In this case, it’s set to Laravel.DB_USERNAME
: This variable represents the username used to authenticate and access the database ...