Do you hate to see when your Magento 2 store is broken or is in maintenance mode while running Magento 2 deployment commands? Yes? That's great. In the next 5 minutes, we'll help you with this pain. At Magefan we've created a Linux bash script that allows you to run bin/magento setup commands without braking store, long downtime, and losing sales.
Attention! This script is deprecated, we strongly recommend to use Magento 2 Zero Downtime Deployment Extension.
To use Magento 2 zero downtime deployment please follow the steps bellow:
1. 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
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
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.
If you use Redis or other non-folder storage for session or cache, then edit the file
Make sure that the cache and session are stored in a folder.
3. Use M2 zero-downtime deploy script
To deploy Magento static content (bin/magento setup:static-content:deploy) with NO downtime, use the CLI command:
To generated code and dependency injection configuration (bin/magento setup:di:compile) with NO downtime, use the CLI command:
You can also run the script with multiple parameters, e.g:
deploy/run -d -s
To update Magento 2 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.
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.