Magento Deployment — Deployment Modes, Pipeline, CI/CD
In this tutorial, you'll learn how to deploy Magento using deployment modes, pipeline deployment with configuration files, and CI/CD integration for automated production releases.
What You'll Learn
- The three deployment modes and when to use each
- How to configure pipeline deployment with config.php and env.php
- How to build a CI/CD pipeline for Magento
- How to use blue-green deployment for zero-downtime releases
- Deployment best practices for production
Why It Matters
Deploying Magento is more complex than deploying a typical web application. Static content deployment, DI compilation, database upgrades, and cache management must happen in the correct order. A bad deployment can take your store offline for hours.
Real-World Use
An e-commerce team deploys code changes twice per week. They use a CI/CD pipeline that runs tests, builds static content, compiles DI, and deploys to a production environment behind a load balancer. The pipeline executes maintenance:enable, runs updates, then maintenance:disable — all within 5 minutes with zero customer downtime.
Learning Path
flowchart LR
A[Multi-Store] --> B[Deployment]
B --> C[Maintenance & Upgrades]
B --> D[All Topics]
C --> E[Professional Magento Developer]
style B fill:#3b82f6,color:#fff
Deployment Modes
Magento has three deployment modes that control error handling, static content behavior, and performance.
Developer Mode
For development environments only:
bin/magento deploy:mode:set developer
Characteristics:
- Full error reporting with stack traces
- Static content generated on demand
- Slower page loads (each block compiled at runtime)
- Symlinks enabled for theme debugging
Default Mode
For limited testing environments:
bin/magento deploy:mode:set default
Characteristics:
- Limited error display
- Static content must be deployed
- Exceptions are logged but not displayed
Production Mode
For live stores:
bin/magento deploy:mode:set production
Characteristics:
- No error display (uses exception handling)
- Static content pre-deployed and minified
- DI compiled for maximum performance
- View files pre-processed
Switching Modes with Options
# Skip static content deployment
bin/magento deploy:mode:set production --skip-compilation
# Force static content deployment
bin/magento deploy:mode:set production -s
Pipeline Deployment
Pipeline deployment separates configuration into two files: config.php and env.php.
Config.php
app/etc/config.php contains system-specific configuration that is shared across environments:
<?php
return [
'modules' => [
'Magento_AdminAnalytics' => 1,
'Magento_AdminNotification' => 1,
'MyCompany_MyModule' => 1,
],
'scopes' => [
'websites' => [
'base' => [
'website_id' => 1,
'code' => 'base',
'name' => 'Main Website',
],
],
],
];
Export configuration from current environment:
bin/magento app:config:dump
Env.php
app/etc/env.php contains environment-specific configuration like database credentials, cache backends, and encryption keys:
<?php
return [
'backend' => [
'frontName' => 'admin',
],
'db' => [
'connection' => [
'default' => [
'host' => 'database.internal',
'dbname' => 'magento_production',
'username' => 'magento_user',
'password' => 'secure_password',
'active' => '1',
],
],
],
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => 'redis.internal',
'port' => '6379',
'database' => '0',
],
],
],
],
'session' => [
'save' => 'redis',
'redis' => [
'host' => 'redis.internal',
'port' => '6379',
'database' => '2',
],
],
'encryption_key' => '...',
];
Pipeline Deployment Steps
- Developer environment: develop code, export config
- Commit
config.phpto version control - Build environment: run
composer install,setup:di:compile,setup:static-content:deploy - Production environment: deploy built code, copy
env.php, runsetup:upgrade, enable maintenance mode during upgrade
CI/CD Integration
Jenkins Pipeline
pipeline {
agent any
stages {
stage('Checkout') {
steps { git 'https://github.com/company/magento-store.git' }
}
stage('Composer Install') {
steps { sh 'composer install --no-dev' }
}
stage('Build') {
steps {
sh 'bin/magento setup:di:compile'
sh 'bin/magento setup:static-content:deploy -f'
}
}
stage('Deploy to Production') {
steps {
sh '''
ssh deploy@production "bin/magento maintenance:enable"
rsync -avz --delete build/ deploy@production:/var/www/magento/
ssh deploy@production "bin/magento setup:upgrade"
ssh deploy@production "bin/magento cache:flush"
ssh deploy@production "bin/magento maintenance:disable"
'''
}
}
}
}
GitHub Actions
name: Deploy Magento
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Install dependencies
run: composer install --no-dev
- name: Build
run: |
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
- name: Deploy
run: |
ssh ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} "bin/magento maintenance:enable"
rsync -avz --exclude=app/etc/env.php ./ ${{ secrets.DEPLOY_PATH }}/
ssh ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} "cd ${{ secrets.DEPLOY_PATH }} && bin/magento setup:upgrade && bin/magento cache:flush && bin/magento maintenance:disable"
Deployment Checklist
Before every production deployment:
- Backup database and files
- Code freeze (no one pushes during deployment)
- Enable maintenance mode
- Clear cache
- Export configuration (if changed)
- Set up env.php for production
- Deploy static content
- Run DI compile
- Run setup:upgrade
- Test critical pages (homepage, product, cart, checkout)
- Disable maintenance mode
Blue-Green Deployment
Blue-green deployment maintains two identical production environments:
- Blue — current live environment
- Green — new version deployed but not live
Switch traffic from blue to green after verifying the green environment works. This allows instant rollback by switching traffic back to blue.
Load Balancer Configuration
upstream magento_backend {
server blue.internal:8080 weight=100;
# server green.internal:8080 weight=0; # Switch weights for deployment
}
Config Management
Export Configuration
After making configuration changes in the admin panel, export them:
# Export all configuration
bin/magento app:config:dump
# Export only sensitive configuration (values hidden)
bin/magento app:config:dump sensitive
This updates app/etc/config.php with all scope configuration, making it deployable across environments.
Common Mistakes
- Deploying static content and DI compilation on the production server instead of in the build pipeline, wasting CPU time and increasing deployment duration
- Forgetting to export configuration before committing, causing the production environment to miss admin panel changes
- Not testing on a staging environment before production deployment, discovering errors only after customers are affected
- Skipping maintenance mode during setup:upgrade, causing database errors when customers access the site during upgrade
- Missing the env.php encryption key, causing all encrypted data (API keys, passwords) to be unreadable
Practice Questions
- What is the difference between config.php and env.php in pipeline deployment?
- Why should static content deployment happen in the build pipeline instead of on the production server?
- How does blue-green deployment enable zero-downtime releases?
Challenge: Create a complete CI/CD pipeline script for Magento that checks out code, runs composer install, compiles DI, deploys static content, copies config files, runs setup:upgrade in maintenance mode, tests the site, and switches a load balancer to the new version.
FAQ
Mini Project
Set up a complete CI/CD pipeline for a Magento store: create a GitHub Actions workflow that builds the project on every push to main, deploys static content and compiled DI to a production server, runs setup:upgrade under maintenance mode, tests the homepage and a product page, then disables maintenance mode. Include a rollback step that restores the previous version if tests fail.
What's Next
Now that deployment is automated, explore Magento Maintenance and Upgrades for ongoing store management. This is the final tutorial in the core Magento series.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro