Deployment
On a production server Magento builds nothing on the fly: classes, styles and scripts are prepared in advance. So a deployment is not copying files but a sequence of commands. A skipped step gives an empty page or a site without design.
Production mode
bin/magento deploy:mode:set production
bin/magento deploy:mode:showThe first command switches the mode and runs the build itself; the second prints the current mode.
| Mode | Behaviour |
|---|---|
developer | Errors on screen, everything is built on the fly, slow |
default | Intermediate, only for the first run |
production | Errors only in the log, everything is built in advance, fast |
Develop in developer, and enable only production on a live server.
The deployment order
Once the new code is on the server, run:
bin/magento maintenance:enable
composer install --no-dev --optimize-autoloader
bin/magento setup:upgrade --keep-generated
bin/magento setup:di:compile
bin/magento setup:static-content:deploy en_US de_DE -f
bin/magento cache:flush
bin/magento maintenance:disableWhile the commands run, visitors see a "Service unavailable" page, and after the last command the shop runs the new code.
What each command does
| Command | Action |
|---|---|
maintenance:enable | Closes the site to visitors |
composer install --no-dev | Installs packages without development tools |
setup:upgrade | Updates tables from db_schema.xml and applies new patches |
setup:di:compile | Generates classes and dependency information into the generated folder |
setup:static-content:deploy | Builds theme styles, scripts and images into pub/static |
cache:flush | Empties the whole cache |
maintenance:disable | Opens the site |
Static content
The setup:static-content:deploy command lists every language enabled on store views and used by staff in the admin panel. For a language missing from the list, a page opens without styles. The -f flag allows running outside production mode.
Maintenance mode
bin/magento maintenance:enable --ip=203.0.113.5
bin/magento maintenance:statusThe --ip option keeps the site open for the given address — this way a deployment is checked before visitors are let in.
Server settings
| File | What is in it | Keep with the code |
|---|---|---|
app/etc/env.php | Database, cache, admin address, encryption key | No, every server has its own |
app/etc/config.php | The list of modules | Yes |
The encryption key from env.php is needed to decrypt saved payment system passwords. When a shop moves to another server, the key moves together with the database.
Before launch
| What to check | How |
|---|---|
| Mode | deploy:mode:show shows production |
| Site root | The web server points at the pub folder |
| Scheduler | crontab -l contains Magento lines |
| Indexers | indexer:status — all are Ready |
| Cache | cache:status — all types enabled |
| Admin address | Not /admin but your own |
| Two-factor login | Enabled for staff |
Common mistake
The site opened without styles — setup:static-content:deploy was not run or was run for the wrong language. A page is empty after an update — setup:di:compile was not run, and old classes remain in the generated folder. A third cause of failures is running the commands as root: files in var, generated and pub/static belong to it, and the web server cannot change them. Run all commands as the user PHP runs under.