Magento application configuration (app/etc/config.php), and environment config (app/etc/env.php)
Magento is a popular open-source e-commerce platform that empowers businesses to create robust and customizable online stores. It provides a flexible architecture and a wide range of features that enable merchants to tailor their online shopping experiences to meet specific business requirements.
To effectively configure a Magento application, two crucial files come into play: app/etc/config.php and app/etc/env.php. These files govern different aspects of the application’s configuration and environment settings.
The config.php file holds essential configuration settings for the Magento application. It includes parameters such as database connection details, cache configuration, encryption keys, and module dependencies. This file is automatically generated during the Magento installation process and should not be manually modified. Instead, it is typically updated by Magento’s command-line interface (CLI) commands or installation/upgrade scripts.
On the other hand, the env.php file is responsible for environment-specific settings and sensitive configuration options. It contains information like database credentials, encryption keys, and configuration overrides. Like config.php the env.php file is generated during the installation process and should not be modified manually. Magento CLI commands or additional configuration files can be used to make environment-specific changes.
Both files are crucial for the proper functioning of a Magento application, as they define important settings and parameters required by the system. Modifying these files incorrectly can lead to issues, so it’s important to follow Magento’s recommended practices and consult documentation or experienced developers when making changes.
By leveraging the power of these configuration files, Magento offers a flexible and customizable e-commerce solution that can be tailored to meet specific business needs.
config.php reference
The config.php file contains the following sections:
- i18n:All inline translation data. Reading from this section is not supported.
- modules:The list of enabled and disabled modules.
- scopes:The list of stores, store groups, and websites with related information.
- system:The system configurations required for static content deployment.
- themes: The configuration of installed themes.
modules
Contains an array of modules and their states. If module is enabled, value is 1. Otherwise, the value is 0.
'modules' => [ 'Magento_Store' => 1, 'Magento_Theme' => 0, 'Magento_Backend' => 0, 'Magento_Eav' => 1 ]
scopes
Contains an array of scope configuration values. It has the following subnodes:
- websites:Website configuration
- groups:Stores configuration
- stores:Store views configuration
'scopes' => [
'websites' => [
'admin' => [
'website_id' => '0',
'code' => 'admin',
'name' => 'Admin',
'sort_order' => '0',
'default_group_id' => '0',
'is_default' => '0'
]
],
'groups' => [
0 => [
'group_id' => '0',
'website_id' => '0',
'code' => 'default',
'name' => 'Default',
'root_category_id' => '0',
'default_store_id' => '0'
]
],
'stores' => [
'admin' => [
'store_id' => '0',
'code' => 'admin',
'website_id' => '0',
'group_id' => '0',
'name' => 'Admin',
'sort_order' => '0',
'is_active' => '1'
]
]
]
system
Contains an array of system field configuration values.
'system'=> [ 'default' =>[ 'checkout' => [ 'cart' => [ 'delete_quote_after' => 31 ] ] ] ]
themes
Contains an array of values for theme configuration.
'themes' => [ 'frontend/Magento/luma' => [ 'parent_id' => 'Magento/blank', 'theme_path' => 'Magento/luma', 'theme_title' => 'Magento Luma', 'is_featured' => '0', 'area' => 'frontend', 'type' => '0', 'code' => 'Magento/luma' ] ]
env.php reference
The env.php file contains the following sections:
- backend:Settings for the Admin area
- cache_types:Cache storage settings
- consumers_wait_for_messages: Configure how consumers process messages from the message queue
- cron: Enable or disable the cron jobs
- crypt: The encryption key for cryptographic functions
- db: Database connection settings
- directories: Magento directories mapping settings
- downloadable_domains: List of downloadable domains
- install: The installation date
- lock: Lock provider settings
- MAGE_MODE:The Magento mode
- queue: Message queues settings
- resource:Mapping of resource name to a connection
- session:Session storage data
- x-frame-options:Setting for x-frame-options
- system:Configuration values that cannot be edited in the Admin
backend
Configure the frontName for the Magento admin url using the backend node in env.php.
'backend' => [ 'frontName' => 'admin' ]
cache_types
All the Magento cache types configuration are available from this node.
'cache_types' => [ 'config' => 1, 'layout' => 1, 'block_html' => 1, 'collections' => 1, 'reflection' => 1, 'db_ddl' => 1, 'compiled_config' => 1, 'eav' => 1, 'customer_notification' => 1, 'config_integration' => 1, 'config_integration_api' => 1, 'full_page' => 1, 'config_webservice' => 1, 'translate' => 1, 'vertex' => 1 ]
consumers_wait_for_messages
Specify whether consumers should continue polling for messages if the number of processed messages is less than the max_messages value. The default value is 1.
'queue' => [ 'consumers_wait_for_messages' => 1 ]
The following options are available:
- 1—Consumers continue to process messages from the message queue until reaching the max_messages value specified in the env.php file before closing the TCP connection and terminating the consumer process. If the queue empties before reaching the max_messages value, the consumer waits for more messages to arrive.
- We recommend this setting for large merchants because a constant message flow is expected and delays in processing are undesirable.
- 0—Consumers process available messages in the queue, close the TCP connection, and terminate. Consumers do not wait for additional messages to enter the queue, even if the number of processed messages is less than the max_messages value specified in the env.php file. This can help prevent issues with cron jobs caused by long delays in message queue processing.
- We recommend this setting for smaller merchants that do not expect a constant message flow and prefer to conserve computing resources in exchange for minor processing delays when there could be no messages for days.
cron
Enable or disable cron jobs for the Magento application. By default, cron jobs are enabled. To disable them, add the cron configuration to the env.php file and set the value to 0.
'cron' => [ 'enabled' => 0 ]
crypt
Magento uses an encryption key to protect passwords and other sensitive data. This key is generated during the Magento installation process.
'crypt' => [ 'key' => '63d409380ccb1182bfb27c231b732f05' ]
db
All database configurations are available in this node.
'db' => [ 'table_prefix' => '', 'connection' => [ 'default' => [ 'host' => 'localhost', 'dbname' => 'magento_db', 'username' => 'root', 'password' => 'admin123', 'model' => 'mysql4', 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1' ] ] ]
default_connection
Defines the default connection for message queues. The value can be db, amqp, or a custom queue system like redismq. If you specify any value other than db, the message queue software must be installed and configured first. Otherwise, messages will not be processed correctly.
'queue' => [ 'default_connection' => 'amqp' ]
If queue/default_connection is specified in the system env.php file, this connection is used for all message queues through the system, unless a specific connection is defined in a queue_topology.xml, queue_publisher.xml or queue_consumer.xml file.
For example, if queue/default_connection is amqp in env.php but a db connection is specified in the queue configuration XML files of a module, the module will use MySQL as a message broker.
directories
Optional directory mapping options that need to be set when the web server is configured to serve Commerce app from the /pub directory for improved security.
'directories' => [ 'document_root_is_pub' => true ]
downloadable_domains
A list of downloadable domains available in this node. Additional domains can be added, removed, or listed using CLI commands.
'downloadable_domains' => [ 'local.vanilla.com' ]
install
The installation date of Commerce application.
'install' => [ 'date' => 'Tue, 23 Apr 2019 09:31:07 +0000' ]
lock
Lock provider settings are configured using the lock node
MAGE_MODE
The deploy mode can be configured in this node.
'MAGE_MODE' => 'developer'
queue
Message queue configurations are available in this node.
'queue' => [ 'topics' => [ 'customer.created' => [publisher="default-rabitmq"], 'order.created' => [publisher="default-rabitmq"], ] ]
resource
Resource configuration settings are available in this node.
'resource' => [ 'default_setup' => [ 'connection' => 'default' ] ]
session
Session configurations are stored in the session node.
'session' => [ 'save' => 'files' ],
x-frame-options
x-frame-options header can be configured using this node.
'x-frame-options' => 'SAMEORIGIN'
system
Using this node, Commerce locks the configuration values in the env.php file and then disables the field in the admin.
'system' => [ 'default' => [ 'web' => [ 'secure' => [ 'base_url' => 'https://magento.test/' ] ] ]
Final Words
Both files are crucial for the proper functioning and customization of a Magento application. They allow for the management of key parameters and environment-specific configurations, ensuring the application operates smoothly and securely. It is essential to follow Magento’s recommended practices and seek guidance from documentation or experienced developers when making changes to these files to avoid any potential issues. By leveraging the power of config.php and env.php, Magento provides a flexible and customizable e-commerce platform that can be tailored to meet the specific requirements of businesses.