ddtcorex

28 Jun 2026 · 2 min read

Anatomy of Magento 2: boot, bin/magento, pub/ web root & env.php

Walk the Magento 2 request lifecycle and meet the files that matter most — the CLI entry point, the pub/ web root, and the auto-generated env.php.

Now that a real Magento 2 instance is running, let's map its anatomy. Understanding the boot path and the key files saves you hours of confused debugging later.

The web root: pub/

Magento 2 is not served from the project root. The document root is pub/, which contains index.php and the static-asset symlinks. Serving from the root would expose app/, etc/, and var/ — a serious security mistake. Govard configures Nginx to point at pub/ for exactly this reason.

The CLI: bin/magento

Almost everything administrative happens through the CLI:

bin/magento setup:upgrade      # apply database schema/data updates
bin/magento cache:flush         # clear the cache
bin/magento indexer:reindex    # rebuild search/price/stock indexes
bin/magento deploy:mode:set production

If you only remember one command, make it bin/magento. Run it inside the environment with govard shell.

The boot path (simplified)

  1. A request hits pub/index.php.
  2. Bootstrap initializes the autoloader and the application.
  3. The object manager (Magento's service container) is built from DI configuration.
  4. The front controller dispatches to a route → controller → layout → blocks → templates.
  5. Output is rendered, and eligible pages are cached by Varnish / the full-page cache.

app/etc/env.php — the auto-generated config

This file holds environment-specific configuration: database credentials, cache backends, and (importantly for multi-tenant setups) the table prefix. Govard generates and maintains env.php automatically as part of environment bring-up, including propagating the table prefix into the connection config so your modules and installers agree on the schema.

Tip: Never hand-edit env.php casually — bin/magento setup:config:set is the supported path, and tooling like Govard keeps it in sync with the environment.

What's next in this series

We know the skeleton. Next we get concrete about extending Magento: how modules compose, how the Dependency Injection container works, and the plugin/interceptor system that lets you change behavior without touching core.

Next in this series: Modules, Dependency Injection & Plugin/Interceptor — /blog/magento2-di-plugins

magento2architecturecli