Let's start with the little mind-reading magic trick.

1. Do you use Magento 2?

 - Yes, you definitely do.

2. Do you hate to see when your store is broken or is in maintenance mode while running Magento 2 deployment commands?

 - Yes, you do.

Was it a guess?

Yes? That's great. In the next 5 minutes, we'll help you with this pain. At Magefan we've created Linux bash script that allows you to run bin/magento setup commands without braking store, long downtime and losing sales.

Attention! This article includes technical information, you can forward it to your developers or contact us if you'll need any help or have questions.

1. Installing Magento 2 zero-downtime deploy script

To install Magento 2 zero-downtime deployment script run these CLI commands in the Magento root directory:

wget -O deploy.zip https://github.com/magefan/magento2-zero-downtime-deploy/archive/master.zip
unzip deploy.zip
rm -f deploy.zip
mv magento2-zero-downtime-deploy-master/ deploy
cp deploy/app/static-content-deploy.sh.sample deploy/app/static-content-deploy.sh
cp app/etc/env.php deploy/app/env.php
echo $'\n'deploy/app/env.php >> .gitignore chmod +x deploy/run

2. Configure zero-downtime script

1. If you use specific static-content deploy commands then edit the file


By default, it has commands to deploy all Magento 2 themes in en_US locale.

2. If you use Redis or other non-folder storage for session or cache, then edit the file


Make sure that cache and session are stored to a folder.

3. How to use M2 zero-downtime deploy script?

1. To deploy Magento static content (bin/magento setup:static-content:deploy) with NO downtime, use the CLI command:

deploy/run -s

2. To generated code and dependency injection configuration (bin/magento setup:di:compile) with NO downtime, use the CLI command:

deploy/run -d

You can also run the script with multiple parameters, e.g:

deploy/run -d -s

3. To update modules database data and schema (bin/magento setup:upgrade), use the CLI command:


If you install new extensions then run this command:

deploy/run -m Vendor_Module1 Vendor_Module2

Note that these commands will also run DI and static content generation and this is the only command that put Magento 2 store into maintenance mode for a few seconds while setup:upgrade is running.

5. Does it really work?

- Yes, it does. We already use it at magefan.com and in a few clients stores to deploy new design and business logic changes. We're happy to share it with you and get feedback.