expand_less

Configuration

Introduction

All configuration files for the Dreamfork framework are located in the config directory. Each option is extensively documented, providing you with the flexibility to explore and understand the available configuration settings.

These files allow you to configure crucial aspects such as your database connection details, and other settings like your application timezone. Feel free to navigate through these files to tailor your configuration according to your project's requirements.

Environment Configuration

Customizing configuration values based on the environment where your application runs is often essential. For instance, you might want different database settings for local development compared to your production server.

To simplify this process, Dreamfork relies on the DotEnv PHP library. In a new Dreamfork installation, the root directory of your application will include a .env.example file defining numerous common environment variables. During the installation, this file will be automatically copied to .env.

The default .env file in Dreamfork contains common configuration values that may vary depending on whether your application is running locally or on a production web server. These values are then fetched from various configuration files within the config directory using Dreamfork's env function.

Environment File Security

It is crucial not to include your .env file in your application's source control. This is because each developer or server using your application might necessitate a distinct environment configuration. Additionally, including it poses a security risk if an intruder gains access to your source control repository, as it may expose sensitive credentials.

Retrieving Environment Configuration

All the variables specified in the .env file will be automatically loaded into the $_ENV PHP super-global when your application receives a request. However, you can use the env function to fetch values from these variables in your configuration files. In fact, upon reviewing the Dreamfork configuration files, you'll observe that many options already employ this function:

                                
                                    
'env' => env('APP_ENV', 'production'),

The second parameter passed to the env function is the "default value." This value will be returned if no environment variable exists for the given key.

Accessing Configuration Values

You can conveniently retrieve your configuration values using the global config function from any part of your application. To access configuration values, utilize "dot" syntax, which involves specifying the name of the file and the option you want to access. If the configuration option does not exist, you can also provide a default value, which will be returned:

                                
                                    
$value = config('app.timezone');
 
// Retrieve a default value if the configuration value does not exist...
$value = config('app.timezone', 'Europe/Warsaw');

This feature allows, for instance, easy determination of the application environment. Based on this, you can create conditional blocks in your code, adjusting the behavior according to the detected environment:

                                
                                    
if (config('app.env') == 'local') {
// The environment is local
} else {
// The environment is production
}

Debug Mode

The debug option in your config/app.php configuration file governs the extent of error information displayed to the user. By default, this option is configured to respect the value of the APP_DEBUG environment variable, which is stored in your .env file.

During local development, it's advisable to set the APP_DEBUG environment variable to true. However, in a production environment, this value should always be set to false. Setting the variable to true in a production environment may pose a security risk by potentially exposing sensitive configuration values to end-users of your application.

Maintenance Mode

When your application is in maintenance mode, a custom view will be presented for all incoming requests. This allows you to effectively "disable" your application temporarily during updates or maintenance tasks.

To activate maintenance mode, run the following Dfork command:

                                
                                    
php dfork maintenance:enable

Upon activating maintenance mode, two files will be generated in the storage/framework directory, governing the functionality of the maintenance mode. One of them is maintenance_config, containing the settings for maintenance mode.

  • whitelist_ip allows you to define an array of authorized IP addresses that can bypass maintenance mode.
  • template specifies the file to be used as the maintenance mode view.
  • secret lets you set a secret key that, when appended to the browser's address as "?secret=your_secret_key," allows bypassing maintenance mode.
  • status defines the HTTP response status code.
  • redirect points to the location where the user will be redirected from maintenance mode.
  • refresh and retry determine the intervals for page refresh to check if the maintenance mode has concluded.

You can deactivate maintenance mode using the following command:

                                
                                    
php dfork maintenance:disable

You have the option to customize the default maintenance mode template by creating your own template at storage/framework/resources/maintenance_view.php. Please note that the maintenance mode doesn't support the Vision template engine.