In this chapter we discuss about categories included in the configuration.
environment variables are variables which declared in the .env file and which have parameter required for configuration.
Environment Configuration
In environment variable all the list of web services for your web application are provided. In .env file all the environment variable are declared which include the parameters need for initializing the configuration.
.env file have following parameters by default -
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:lWhUcswVYue03KJhhQ1gfRuTFUHIJ1xGVSESoa8fazQ=
APP_DEBUG=true
APP_URL=http://laravel_tutorial.test
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_tutorial
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
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}"
Note : A file with file name '.env.example' is present there ,which is nothing but it is a copy of .env file .
Retrieval of Environment Variables
environment variables declared in the .env file are accessed by env-helper functions which use to call the respective parameter. when application receives a request from the user end then all these variables are listed into $_ENV global variable. You can access the environment variable as shown below −
'env' => env('APP_ENV', 'production'),
In app.php file env-helper function are called which is included in the config folder.
In config folder we have many default file for different purpose :
- app.php
- auth.php
- broadcasting.php
- cache.php
- cors.php
- database.php
- filesystem.php
- hashing.php
- logging.php
- mail.php
- queue.php
- sanctum.php
- services.php
- session.php
- view.php
For example -
Database Configuration
The database of your application can be configured from config/database.php file. You can set configuration parameters that can be used by different databases and you can also set the default one to use.
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],