How to Set Production Mode in Magento 2
[Updated: March 18, 2026]
Running a Magento store in the wrong mode tanks performance and exposes sensitive data. Production mode pre-compiles code, caches static files, and hides error details from visitors.
This tutorial explains each Magento 2 mode and walks you through enabling production mode step by step.
Key Takeaways
- Magento 2 supports three operational modes (default, developer, production) plus maintenance mode
- Production mode pre-compiles code and caches static files for faster page loads
- Switch with
php bin/magento deploy:mode:set production - Mode configuration lives in
app/etc/env.php - Adobe Commerce Cloud supports production and maintenance modes only
What is Production Mode in Magento 2?
Production mode = The deployment mode for live Magento stores. Code is pre-compiled, static files are cached, and errors log to files instead of the screen.
Perfect for: Live production stores, staging environments, high-traffic sites
Not ideal for: Active development, debugging, initial Magento setup
Production mode is the recommended setting for all live Magento 2 stores. It serves pre-compiled static assets from the pub/static directory. Error messages go to log files in var/log/ instead of appearing on screen, which protects sensitive information from visitors.
In production mode, administrators can refresh the cache but cannot enable or disable cache types through the admin panel. Static view files must be deployed through the Magento CLI before they become available.

Magento 2 Modes Compared
Magento 2 supports three operational modes plus a maintenance mode. Each serves a different stage in the development lifecycle.
| Feature | Default | Developer | Production | Maintenance |
|---|---|---|---|---|
| Static files | Generated, then cached | On demand, not cached | Pre-compiled, cached | N/A |
| Error display | Logged to files | Detailed with stack traces | Logged to var/log/ |
Maintenance page |
| Code compilation | None | None | Pre-compiled | N/A |
| Performance | Moderate | Low | Optimized | N/A |
| Cache control | Full | Full | Refresh only | N/A |
| Best for | Initial setup | Development | Live stores | Updates |
For the full specification of each mode, see the official Adobe Commerce application modes documentation.
Default Mode
Default mode activates after a fresh Magento installation. Static files generate on the first request and are then cached. Errors write to log files rather than displaying on screen. This mode is not designed for continued use after initial setup.
Switch to developer or production mode once configuration is complete. You can return to default mode with php bin/magento deploy:mode:set default or by editing app/etc/env.php, but there is no practical reason to do so.
Developer Mode
Developer mode is built for active development. Error messages display on screen with full stack traces. Static files regenerate on every request without caching, so code changes appear right away.
Key behaviors in developer mode:
- Errors display in the browser with detailed stack traces
- Verbose logs write to
var/report/ - No code compilation needed after changes
- Run
setup:upgradeafter modifications
Developer mode is ideal for debugging, extension installation, and customization. Never use it on a live store.
Maintenance Mode
Maintenance mode takes the storefront offline while allowing backend access. Magento creates a .maintenance.flag file in the var/ directory. Visitors see a maintenance page while administrators continue working.
You can whitelist specific IP addresses to access the store during maintenance. This lets you verify changes before reopening to the public.
Where Magento Stores the Mode Configuration
Magento writes the current mode to app/etc/env.php. The relevant entry looks like this:
'MAGE_MODE' => 'production',
You can verify the mode by reading this file or using the CLI command. If the MAGE_MODE key is missing, Magento defaults to default mode.
The MAGE_MODE environment variable can also override this setting. On managed Magento hosting environments, the hosting provider often sets this at the server level.
How to Set Production Mode in Magento 2
Step 1: Connect to Your Server
Access your Magento server through SSH. All CLI commands must run as the file system owner (the user that owns the Magento files).
ssh user@your-server.com
Step 2: Navigate to the Magento Root Directory
Change to the directory containing your Magento installation. This is where composer.json and bin/magento are located.
cd /var/www/html/magento2
Step 3: Check the Current Mode
Verify which mode is active before making changes:
php bin/magento deploy:mode:show
Output: Current application mode: {mode}
Step 4: Switch to Production Mode
Run the deployment command:
php bin/magento deploy:mode:set production
This command triggers three actions:
- Compiles dependency injection configuration
- Generates static view files for all registered themes and locales
- Writes
'MAGE_MODE' => 'production'toapp/etc/env.php
To skip compilation (useful when deploying to a build server):
php bin/magento deploy:mode:set production --skip-compilation
Step 5: Clear the Cache
After switching modes, clear the cache to load fresh configurations:
php bin/magento cache:clean
Step 6: Deploy Static Content
If you used --skip-compilation or need to regenerate static files, deploy static content with this command:
php bin/magento setup:static-content:deploy
For specific locales:
php bin/magento setup:static-content:deploy en_US de_DE
Step 7: Verify the Switch
Confirm production mode is active:
php bin/magento deploy:mode:show
Visit your storefront to verify pages load and no errors display on screen.
Directories Cleared When Switching Modes
When you switch between modes, Magento clears these directories:
| Directory | Contents |
|---|---|
var/cache |
Application cache |
generated/metadata |
Compiled metadata |
generated/code |
Generated code (interceptors, proxies) |
var/view_preprocessed |
Preprocessed view files |
pub/static |
Static view files (CSS, JS, images) |
Two exceptions survive the cleanup: .htaccess files in pub/static and the static content version file.
Tip: When switching from production to developer mode, delete generated/code and generated/metadata before the switch to prevent compilation errors.
Common Issues When Switching Modes
Permission Errors
The most common issue. The CLI user and web server user must match, or file permissions will conflict. Run all Magento commands as the file system owner.
Missing Static Files After Switch
If pages appear unstyled after switching to production mode, deploy static content:
php bin/magento setup:static-content:deploy -f
The -f flag forces deployment even in developer mode.
Compilation Errors
If dependency injection compilation fails, clear generated files first:
rm -rf generated/code generated/metadata
php bin/magento setup:di:compile
Production Mode on Adobe Commerce Cloud
Adobe Commerce Cloud supports production and maintenance modes only. Developer and default modes are not available. The cloud platform handles static content deployment and code compilation as part of its build and deploy pipeline.
Why Production Mode Matters for Performance
Production mode delivers concrete performance improvements for live stores:
Faster page loads: Static files serve from cache instead of generating per request. CSS and JavaScript files are minified and bundled, which reduces HTTP requests and improves load times.
Better security: Error messages and stack traces log to var/log/ files instead of displaying on screen. Visitors never see sensitive server paths, database details, or code structures.

Lower server load: Pre-compiled code eliminates runtime compilation overhead. The application handles traffic spikes better on stores with auto-scaling enabled.
Resource efficiency: Reduced CPU usage from caching and pre-compilation means lower server costs and better response times under load.
FAQ
What command switches Magento 2 to production mode?
Run php bin/magento deploy:mode:set production from the Magento root directory. This compiles code, deploys static files, and updates the mode in app/etc/env.php.
Can I switch back from production mode to developer mode?
Yes. Run php bin/magento deploy:mode:set developer. Before switching, delete the generated/code and generated/metadata directories to prevent compilation errors. You can also switch to default mode with php bin/magento deploy:mode:set default.
Does switching to production mode affect my extensions?
No. Production mode changes how Magento handles caching, error display, and code compilation. Your extensions, configurations, and data remain unchanged. Back up your files before switching as a precaution.
What is the difference between production mode and developer mode?
Production mode pre-compiles code, caches static files, and logs errors to files. Developer mode skips compilation, regenerates static files per request, and displays errors on screen. Use developer mode for coding, production mode for live stores.
How do I check which mode Magento 2 is running?
Run php bin/magento deploy:mode:show. The output displays the current mode. You can also check the MAGE_MODE value in app/etc/env.php.
Why are my pages unstyled after switching to production mode?
Static content needs deployment. Run php bin/magento setup:static-content:deploy to generate CSS, JavaScript, and image files for all themes and locales.
Can I use production mode during development?
Not recommended. Production mode caches all static files and hides errors. Every change requires cache clearing and static content redeployment, which slows down development work.
Does Adobe Commerce Cloud support all Magento modes?
No. Adobe Commerce Cloud supports production and maintenance modes only. The platform handles code compilation and static content deployment through its build pipeline.
Summary
Production mode is the correct setting for every live Magento 2 store. It pre-compiles code, caches static assets, and logs errors to files instead of the screen. Switch modes with php bin/magento deploy:mode:set production and verify with deploy:mode:show.
For production stores handling real traffic, pair production mode with managed Magento hosting that handles server optimization, auto-scaling, and security updates.
