Deployment Commands
Basic Deployment
# Deploy all static content
bin/magento setup:static-content:deploy
# Force deployment (overwrite existing)
bin/magento setup:static-content:deploy -f
# Deploy specific theme
bin/magento setup:static-content:deploy --theme=Amazon/Prep
# Deploy specific area
bin/magento setup:static-content:deploy --area=frontend
bin/magento setup:static-content:deploy --area=adminhtml
Language Deployment
# Deploy for specific language
bin/magento setup:static-content:deploy en_US
bin/magento setup:static-content:deploy en_US fr_FR de_DE
# Deploy all languages
bin/magento setup:static-content:deploy --all-languages
Deployment with Jobs
# Run deployment with multiple processes
bin/magento setup:static-content:deploy -j4
# -j4 = 4 parallel processes
Dry Run
# Check what would be deployed
bin/magento setup:static-content:deploy --dry-run
Compilation Modes
Deployment Modes
| Mode | Description | LESS Compilation |
|---|---|---|
| production | Optimized, compiled | On deploy |
| developer | Debugging, preprocessed | On page load |
| default | Default mode | On page load |
Switching Modes
# Set production mode
bin/magento deploy:mode:set production
# Set developer mode
bin/magento deploy:mode:set developer
# Check current mode
bin/magento deploy:mode:show
Production Mode
# 1. Set production mode
bin/magento deploy:mode:set production
# 2. Compile code
bin/magento setup:di:compile
# 3. Deploy static content
bin/magento setup:static-content:deploy -f
# 4. Enable all caches
bin/magento cache:enable
Developer Mode
# Set developer mode
bin/magento deploy:mode:set developer
# Static files served from source
# LESS compiled on page load
# Better for debugging
Performance Optimization
Deployment Optimization
# Use parallel processing
bin/magento setup:static-content:deploy -f -j8
# Deploy only needed themes
bin/magento setup:static-content:deploy --theme=Amazon/Prep
# Deploy only needed languages
bin/magento setup:static-content:deploy en_US
File Optimization
# Minify CSS/JS
bin/magento config:set dev/css/minify_files 1
bin/magento config:set dev/js/minify_files 1
# Merge CSS/JS
bin/magento config:set dev/css/merge_css_files 1
bin/magento config:set dev/js/merge_js_files 1
# Enable bundling
bin/magento config:set dev/js/bundle 1
Cache Optimization
# Enable all caches
bin/magento cache:enable
# Clean cache after deployment
bin/magento cache:clean
bin/magento cache:flush
# Check cache status
bin/magento cache:status
Deployment Scripts
#!/bin/bash
echo "Starting deployment..."
bin/magento maintenance:enable
bin/magento deploy:mode:set production
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f -j4
bin/magento cache:clean
bin/magento cache:flush
bin/magento maintenance:disable
echo "Deployment complete!"
Troubleshooting
Common Issues
Permission Errors
# Fix permissions
chmod -R 777 pub/static/
chmod -R 777 var/
chmod -R 777 generated/
# Or use proper ownership
chown -R www-data:www-data pub/static/
Missing Files
# Clear and redeploy
rm -rf pub/static/frontend/
rm -rf pub/static/adminhtml/
bin/magento setup:static-content:deploy -f
Compilation Errors
# Check for errors
bin/magento setup:di:compile 2>&1 | grep ERROR
# Fix and retry
bin/magento setup:di:compile
Memory Issues
# Increase memory limit
php -d memory_limit=4G bin/magento setup:static-content:deploy -f
Debug Deployment
# Verbose output
bin/magento setup:static-content:deploy -v
# Check logs
tail -f var/log/system.log
tail -f var/log/exception.log
# Enable maintenance mode during deploy
bin/magento maintenance:enable
bin/magento setup:static-content:deploy -f
bin/magento maintenance:disable
Quiz
1. Which command deploys static content?
2. What does the -f flag do?
3. Which mode compiles LESS on page load?
Flashcards
Question
What command deploys static content?
Click to reveal answer
Answer
bin/magento setup:static-content:deploy -f
Question
What does -f flag do?
Click to reveal answer
Answer
Force deployment (overwrite existing files)
Question
What does -j4 do?
Click to reveal answer
Answer
Run deployment with 4 parallel processes
Question
Which mode is for production?
Click to reveal answer
Answer
bin/magento deploy:mode:set production
Question
How to fix permission errors?
Click to reveal answer
Answer
chmod -R 777 pub/static/ var/ generated/
Revision Notes
Key Takeaways
- 1. setup:static-content:deploy compiles and deploys static files
- 2. -f forces deployment, -j enables parallel processing
- 3. Production mode compiles on deploy, developer on page load
- 4. Enable maintenance mode during deployment
- 5. Fix permissions before deployment
Interview Tips
- • Know the deployment command and flags
- • Understand production vs developer mode
- • Discuss deployment optimization strategies
- • Be ready to troubleshoot common issues
Cheat Sheet
Deploy: bin/magento setup:static-content:deploy -f
Theme: --theme=Vendor/Theme
Language: en_US fr_FR
Parallel: -j4
Modes:
production: Compiled on deploy
developer: Preprocessed on load
Optimize:
Minify: dev/css/minify_files 1
Merge: dev/css/merge_css_files 1