At first let’s make clear what is Magento application? Magento it’s a CMS (content management system) specially designed and developed for web stores creating, in other words it’s an e-commerce platform. And Magento application it is a component of this system that processes user request and returns the final result.
Look at the following types of Magento applications that are used by web server:
Magento has special entry point for each application launch, and it can be used by web server.
Http. Index.php and pub/index.php entry point
- It runs at http query and determines query zone (frontend, admin, soap, rest). Basically it processes queries and returns http response.
StaticResource. Pub/static.php entry point.
- This application runs when non-existing static content is being requested (for example CSS, JavaSript and images)
It returns and generate static content to pub/static folder.
MediaResource. Pub/get.php entry point.
- This application runs when media resources are being requested from database. It extracts media out of the database, generates static content, etc.
Let’s consider HTTP application launch example. It happens as follows:
In order of query processing:
- Class object of Magento\Framework\App\Bootstrap loader is created.
- Loader creates application type object.
- Loader launches application.
So it is possible to configure Magento application using the following ways:
-Using command string utility.
-If specify parameters of manual application load.
In order of loader creation you can specify some application parameters by establishing environment values $_SERVER, that is transferred into loader as a parameter.
Configurable parameters names are specified in loader class as constants.
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
BP – root dir
$_SERVER – server environment values. It is possible to specify the following parameters for loader:
Bootstrap::PARAM_REQUIRE_MAINTENANCE – default value is false
This parameter determines the way how loader processes maintenance mode. And it could have the following values:
– false (default value) – at this value, in case /var/.maintenance.flag file is exist, all ip addresses that are not listed in /var/.maintenance.ip are blocked.
– true – in case /var/.maintenance.flag file is exist, all ip addresses that are listed in var/.maintenance.ip are blocked.
– null – maintenance check is skipped.
Bootstrap::PARAM_REQUIRE_IS_INSTALLED – checks whether Magento is installed.
Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS – paths to system directories.
You can override directories that are defined by default in getDefaultConfig() method of
Bootstrap::INIT_PARAM_FILESYSTEM_DRIVERS – file system driver. It should have ‘\Magento\Framework\Filesystem\DriverInterface’ type.
All these parameters you can specify right before loader creating or in .htaccess file by setEnv.
– maintenance mode
require __DIR__ . '/app/bootstrap.php';
$_SERVER[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = true;
$_SERVER[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = ['cache' => ['path' => 'app/code']];
$_SERVER[Bootstrap::INIT_PARAM_FILESYSTEM_DRIVERS] = ['my_driver' => 'app\code\MyDriver'];
$bootstrap = Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
Well, let’s take a look how we can configure an application by command string utility.
Executive file is located in magento/bin directory. Let’s go to this directory and run the following commands:
- php magento deploy:mode:show
(result : Current application mode: developer. (Note: Environment variables may override this value.))
Example of how to enable maintenance mode using command string:
- php magento maintenance:enable
- php magento maintenance:enable –ip=192.0.2.10 –ip=192.0.2.11
To apply maintenance to all ip addresses, except of listed or to specified, in case $_SERVER[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = true;
Set Magento mode (developer/production)
- php magento deploy:mode:set developer – It sets up developer mode.
Developer mode is used for development, generates static files during every request and output information about errors exceptions.
Command string utility is a very useful tool. It can be used for managing of caching, sessions, tests launch, cron job, database updating. etc.
Here is the list of other commands: