Deployment Commands and Options
Basic Commands
# Deploy all static content
bin/magento setup:static-content:deploy
# Force deployment (overwrite existing)
bin/magento setup:static-content:deploy -f
# Deploy with parallel processes
bin/magento setup:static-content:deploy -j4
bin/magento setup:static-content:deploy -j8
# Dry run (check what would be deployed)
bin/magento setup:static-content:deploy --dry-run
# Verbose output
bin/magento setup:static-content:deploy -v
Theme and Language Options
# Deploy specific theme
bin/magento setup:static-content:deploy --theme=Amazon/Prep
bin/magento setup:static-content:deploy --theme=Magento/luma
# Deploy specific area
bin/magento setup:static-content:deploy --area=frontend
bin/magento setup:static-content:deploy --area=adminhtml
# Deploy 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
Complete Deployment Script
#!/bin/bash
# deploy-static.sh
THEME="Amazon/Prep"
LANGUAGES="en_US"
JOBS=4
echo "Deploying static content..."
echo "Theme: $THEME"
echo "Languages: $LANGUAGES"
echo "Jobs: $JOBS"
# Clean previous deployment
rm -rf pub/static/frontend/
rm -rf pub/static/adminhtml/
# Deploy
bin/magento setup:static-content:deploy \
--theme=$THEME \
--area=frontend \
-j$JOBS \
-f
echo "Static content deployment complete!"
Key Takeaway
Static content deployment compiles LESS/JS and places files in pub/static/. Use -f to force, -j for parallel, and --theme/--area for targeted deployment.
Deployment Modes
Mode Comparison
| Mode | LESS Compilation | Static Files | Use Case |
|---|---|---|---|
| production | On deploy | Compiled | Live stores |
| developer | On page load | Source files | Development |
| default | On page load | Source files | Default setup |
Switching Modes
# Check current mode
bin/magento deploy:mode:show
# Set production mode
bin/magento deploy:mode:set production
# Set developer mode
bin/magento deploy:mode:set developer
Production Mode Deployment
# Full production deployment
bin/magento deploy:mode:set production
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f -j4
bin/magento cache:enable
bin/magento cache:clean
Developer Mode
# Switch to developer mode
bin/magento deploy:mode:set developer
# Static files served from source
# LESS compiled on page load
# No need to run static-content:deploy
Mode Effects on Static Files
# Production: compiled files in pub/static/
pub/static/frontend/Amazon/Prep/en_US/
css/styles-l.css
css/styles-m.css
js/requirejs/require.js
# Developer: symlinks to source
pub/static/frontend/Amazon/Prep/en_US/ -> app/design/frontend/Amazon/Prep/web/
Key Takeaway
Production mode compiles static files on deploy for performance. Developer mode serves source files for debugging. Always use production mode for live stores.
Performance Optimization
Parallel Processing
# Use multiple processes
bin/magento setup:static-content:deploy -j8
# CPU cores guide
# 2 cores: -j2
# 4 cores: -j4
# 8 cores: -j8
Selective Deployment
# Deploy only needed theme
bin/magento setup:static-content:deploy --theme=Amazon/Prep
# Deploy only needed languages
bin/magento setup:static-content:deploy en_US
# Deploy only frontend
bin/magento setup:static-content:deploy --area=frontend
CSS/JS Optimization
# Minify CSS
bin/magento config:set dev/css/minify_files 1
# Minify JS
bin/magento config:set dev/js/minify_files 1
# Merge CSS
bin/magento config:set dev/css/merge_css_files 1
# Merge JS
bin/magento config:set dev/js/merge_js_files 1
# Enable JS bundling
bin/magento config:set dev/js/bundle 1
File Optimization
# Enable HTML minification
bin/magento config:set dev/template/allow_symlink 0
# Enable JavaScript bundling strategy
bin/magento config:set dev/js/bundle_strategy 1
Deployment Timing
# Measure deployment time
time bin/magento setup:static-content:deploy -f -j4
# Typical results:
# -j1: 15-30 minutes
# -j4: 5-10 minutes
# -j8: 3-6 minutes
Key Takeaway
Optimize with parallel processes (-j), selective deployment (--theme, --area), and CSS/JS minification/merging. Parallel processing provides the biggest speed improvement.
Troubleshooting Deployment Issues
Common Errors and Fixes
Permission Errors
# Fix permissions
chmod -R 777 pub/static/
chmod -R 777 var/
chmod -R 777 generated/
# Proper ownership
chown -R www-data:www-data pub/static/
chown -R www-data:www-data var/
chown -R www-data:www-data generated/
Missing Files
# Clear and redeploy
rm -rf pub/static/frontend/
rm -rf pub/static/adminhtml/
rm -rf var/view_preprocessed/
bin/magento setup:static-content:deploy -f
Compilation Errors
# Check for errors
bin/magento setup:di:compile 2>&1 | grep -i error
# Check generated code
ls generated/code/
# Regenerate
rm -rf generated/code/
rm -rf generated/metadata/
bin/magento setup:di:compile
Memory Issues
# Increase memory limit
php -d memory_limit=4G bin/magento setup:static-content:deploy -f
# Or in php.ini
memory_limit = 4G
LESS Compilation Errors
# Clear preprocessed files
rm -rf var/view_preprocessed/
# Clear pub/static
rm -rf pub/static/frontend/
rm -rf pub/static/adminhtml/
# Redeploy
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 during deploy
bin/magento maintenance:enable
bin/magento setup:static-content:deploy -f
bin/magento maintenance:disable
Deployment Verification
# Check deployed files
ls -la pub/static/frontend/Amazon/Prep/en_US/
# Verify file sizes
find pub/static/frontend/ -name "*.css" -exec ls -la {} \;
# Check for empty files
find pub/static/frontend/ -empty -type f
Key Takeaway
Common issues: permissions, missing files, memory limits. Fix with proper permissions, clear directories, increase memory. Use verbose output and logs for debugging.
Quiz
1. What does -f flag do in static-content:deploy?
2. Which mode compiles LESS on page load?
3. What does -j8 do?
4. Why clear var/view_preprocessed/ before deployment?
5. What is the typical deployment time with -j4?
Flashcards
Question
What command deploys static content?
Click to reveal answer
Answer
bin/magento setup:static-content:deploy -f
Question
What does -j4 do?
Click to reveal answer
Answer
Run deployment with 4 parallel processes for faster execution
Question
Which mode is for production?
Click to reveal answer
Answer
bin/magento deploy:mode:set production - compiles on deploy
Question
How to fix permission errors?
Click to reveal answer
Answer
chmod -R 777 pub/static/ var/ generated/ and chown to www-data
Question
Why clear var/view_preprocessed/?
Click to reveal answer
Answer
Remove cached preprocessed files to ensure fresh compilation
Question
What does --theme do?
Click to reveal answer
Answer
Deploy only the specified theme instead of all themes
Question
How to deploy specific language?
Click to reveal answer
Answer
bin/magento setup:static-content:deploy en_US
Question
What does --dry-run do?
Click to reveal answer
Answer
Check what would be deployed without actually deploying
Revision Notes
Key Takeaways
- 1. setup:static-content:deploy compiles and deploys static files
- 2. -f forces, -j enables parallel processing
- 3. Production mode compiles on deploy, developer on page load
- 4. Enable maintenance mode during deployment
- 5. Clear var/view_preprocessed/ 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
Static Content Deploy
Commands:
Deploy: bin/magento setup:static-content:deploy -f
Theme: --theme=Vendor/Theme
Area: --area=frontend
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
Bundle: dev/js/bundle 1
Troubleshoot:
Permissions: chmod 777 pub/static/
Memory: php -d memory_limit=4G
Clear: rm -rf var/view_preprocessed/