Deployment Pipeline
Production Deployment Steps
# 1. Enable module
bin/magento module:enable Amazon_Prep
# 2. Run setup upgrade
bin/magento setup:upgrade
# 3. Compile dependency injection
bin/magento setup:di:compile
# 4. Deploy static content
bin/magento setup:static-content:deploy -f
# 5. Clean and flush cache
bin/magento cache:clean
bin/magento cache:flush
# 6. Set production mode
bin/magento deploy:mode:set production
Development vs Production
| Aspect | Development | Production |
|---|---|---|
| Mode | default | production |
| Static files | Symlinked | Compiled/deployed |
| Caching | Disabled/limited | Full caching |
| Errors | Displayed | Logged only |
| Compilation | Not required | Required |
Check Current Mode
bin/magento deploy:mode:show
# Output: Current application mode: production
Switch Modes
# To production
bin/magento deploy:mode:set production
# To developer
bin/magento deploy:mode:set developer
# To default
bin/magento deploy:mode:set default
Static Content Deployment
Deploy Static Content
# Basic deployment
bin/magento setup:static-content:deploy -f
# Deploy for specific theme and locale
bin/magento setup:static-content:deploy -f Magento/luma en_US
# Deploy for multiple locales
bin/magento setup:static-content:deploy -f en_US de_DE fr_FR
# With language pack
bin/magento setup:static-content:deploy -f -a Magento/luma
What Gets Deployed
pub/static/
├── frontend/
│ └── Magento/
│ └── luma/
│ └── en_US/
│ ├── css/ (compiled Less)
│ ├── js/ (bundled JS)
│ ├── fonts/
│ └── images/
└── adminhtml/
└── Magento/
└── backend/
└── en_US/
Remove Old Static Files
# Remove compiled frontend files
rm -rf pub/static/frontend/
# Remove compiled admin files
rm -rf pub/static/adminhtml/
# Re-deploy
bin/magento setup:static-content:deploy -f
Symlinks in Developer Mode
In developer mode, static files are symlinked instead of copied:
# Enable symlinks
bin/magento setup:static-content:deploy --symlink-locale
# Or set in configuration
bin/magento config:set dev/static/sign 1
Cache and Indexer Management
Cache Management
# List all cache types
bin/magento cache:status
# Clean cache (removes all cache entries)
bin/magento cache:clean
# Flush cache storage (removes everything)
bin/magento cache:flush
# Enable specific cache type
bin/magento cache:enable config
# Disable specific cache type
bin/magento cache:disable full_page
# Check cache status
bin/magento cache:info
Cache Types
| Type | What It Stores |
|---|---|
| config | Compiled configuration |
| layout | Layout XML compilation |
| block_html | Rendered block HTML |
| collections | Database collection queries |
| reflection | Compiled classes |
| db | Database queries |
| eav | EAV attribute data |
| full_page | Full page cache |
| compiled | DI compilation output |
| config_integration | Integration config |
| config_integration_api | Integration API config |
| translate | Translation dictionaries |
Indexer Management
# List all indexers
bin/magento indexer:status
# Reindex all
bin/magento indexer:reindex
# Reindex specific
bin/magento indexer:reindex catalog_product_flat
bin/magento indexer:reindex cataloginventory_stock
# Set indexer mode
bin/magento indexer:set-mode realtime catalog_product_flat
bin/magento indexer:set-mode schedule catalog_product_flat
Common Indexers
| Indexer | Description |
|---|---|
| catalog_product_flat | Product flat table |
| catalog_product_price | Product price |
| cataloginventory_stock | Stock status |
| catalog_category_flat | Category flat table |
| catalogsearch_fulltext | Search index |
| customer_grid | Customer grid |
Production Checklist
Pre-Deployment
# 1. Backup database
mysqldump -u root -p magento_db > backup_$(date +%Y%m%d).sql
# 2. Enable maintenance mode
bin/magento maintenance:enable
# 3. Pull latest code
git pull origin main
# 4. Install dependencies
composer install --no-dev --optimize-autoloader
# 5. Enable module
bin/magento module:enable Amazon_Prep
# 6. Run setup upgrade
bin/magento setup:upgrade
# 7. Compile DI
bin/magento setup:di:compile
# 8. Deploy static content
bin/magento setup:static-content:deploy -f
# 9. Set permissions
chmod -R 777 var/ pub/static pub/media generated
# 10. Clean cache
bin/magento cache:clean
bin/magento cache:flush
# 11. Disable maintenance mode
bin/magento maintenance:disable
Post-Deployment Verification
# Check module status
bin/magento module:status Amazon_Prep
# Check deployment mode
bin/magento deploy:mode:show
# Check indexer status
bin/magento indexer:status
# Check cache status
bin/magento cache:status
# Test site
curl -I https://your-site.com
# Check error logs
tail -f var/log/exception.log
tail -f var/log/system.log
Zero-Downtime Deployment
# 1. Deploy to non-production server
# 2. Run all commands on non-production
# 3. Swap traffic to new server
# 4. Keep old server as backup
# 5. Monitor for errors
# 6. Decommission old server
Deployment Script Example
#!/bin/bash
set -e
echo "Starting deployment..."
bin/magento maintenance:enable
composer install --no-dev --optimize-autoloader
bin/magento module:enable --clear-static-content Amazon_Prep
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:clean
bin/magento cache:flush
bin/magento maintenance:disable
echo "Deployment complete!"
Troubleshooting
# White screen: check error logs
tail -f var/log/exception.log
# Static files not loading: redeploy
bin/magento setup:static-content:deploy -f
# DI errors: recompile
bin/magento setup:di:compile
# Stale config: clean cache
bin/magento cache:clean
# Module not found: check enable status
bin/magento module:status | grep Amazon_Prep
Quiz
1. What is the complete production deployment sequence?
2. What does bin/magento setup:di:compile do?
3. What command enables maintenance mode?
Flashcards
Question
What is the full production deployment sequence?
Click to reveal answer
Answer
enable → upgrade → di:compile → static-content:deploy → cache:clean
Question
What does static-content:deploy do?
Click to reveal answer
Answer
Compiles Less to CSS, bundles JS, and deploys to pub/static/
Question
How do you enable maintenance mode?
Click to reveal answer
Answer
bin/magento maintenance:enable
Question
What does setup:di:compile generate?
Click to reveal answer
Answer
Proxy classes, factory classes, and DI-generated code
Question
How do you check deployment mode?
Click to reveal answer
Answer
bin/magento deploy:mode:show
Revision Notes
Key Takeaways
- 1. Production sequence: enable → upgrade → compile → deploy → cache
- 2. Static content deployment compiles Less and bundles JS
- 3. Always enable maintenance mode during deployment
- 4. Verify module status, cache, and indexers after deployment
- 5. Keep backups and test deployments in staging first
Interview Tips
- • Know the complete deployment sequence from memory
- • Explain what each deployment command does
- • Discuss zero-downtime deployment strategies
- • Be ready to troubleshoot common deployment issues
Cheat Sheet
Production deploy:
bin/magento maintenance:enable
bin/magento module:enable Module
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:clean
bin/magento maintenance:disable
Verify:
bin/magento module:status
bin/magento deploy:mode:show
bin/magento cache:status