Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

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:show

The first command switches the mode and runs the build itself; the second prints the current mode.

ModeBehaviour
developerErrors on screen, everything is built on the fly, slow
defaultIntermediate, only for the first run
productionErrors 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:disable

While the commands run, visitors see a "Service unavailable" page, and after the last command the shop runs the new code.

What each command does

CommandAction
maintenance:enableCloses the site to visitors
composer install --no-devInstalls packages without development tools
setup:upgradeUpdates tables from db_schema.xml and applies new patches
setup:di:compileGenerates classes and dependency information into the generated folder
setup:static-content:deployBuilds theme styles, scripts and images into pub/static
cache:flushEmpties the whole cache
maintenance:disableOpens 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:status

The --ip option keeps the site open for the given address — this way a deployment is checked before visitors are let in.

Server settings

FileWhat is in itKeep with the code
app/etc/env.phpDatabase, cache, admin address, encryption keyNo, every server has its own
app/etc/config.phpThe list of modulesYes

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 checkHow
Modedeploy:mode:show shows production
Site rootThe web server points at the pub folder
Schedulercrontab -l contains Magento lines
Indexersindexer:status — all are Ready
Cachecache:status — all types enabled
Admin addressNot /admin but your own
Two-factor loginEnabled 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.

Thanks for reading!

Donate to the site — we work hard for you.