1

Currently my magento 2 website is on production mode and the website traffic is very high 24/7 , when there's a code/module update i need to run the following command in the terminal:

php bin/magento setup:upgrade 
php bin/magento setup:di:compile 
php bin/magento setup:static-content:deploy 

when i run this bin shell in the terminal the website is temporary down, and it will live again after it finish run the shell, how to prevent website down when i run this shell command?

4

The short answer is that you cannot totally avoid having the site down while doing database updates.

The key though, is to have a process in place that minimizes the downtime.

The steps below are taken directly from Jisse Reitsma @ Yireo, you can read the full article here

1. Shadow environment

The first step would be to create a copy of the production environment, preferably in the same root folder as the production site. Next, you can update that copy, which might take minutes. Once you are done, you replace all of the files of the production site with the new files of the shadow environment and finalize the deployment to production. To run the changes on the files, the following steps are needed:

git pull

composer install

bin/magento setup:static-content:deploy

bin/magento setup:di:compile

Again, this might take minutes. It might even go wrong. However, if all of this takes place in a shadow environment, there is no risk to the production site. Only once all of the steps are completed succesfully, you can move to the second stage - putting these file updates actually in production.

2. Switching between shadow and production

Switching shadow and production could be done through simple folder operations (mv b c; mv a b; mv b a;) or symlinking. Actually, the procedure of working with symlinks is part of the approach of Capistrano, so if you are looking for a better tool to deploy Magento 2, opt for Capistrano.

3. Finalizing production

So now you can swap all of the files of the actual production site with the files that you gathered in the shadow environment. The only thing that remains is to run the database changes, which is done in Maintenance Mode.

bin/magento maintenance:enable

bin/magento setup:upgrade --keep-generated

bin/magento maintenance:disable

The previous code-gathering step might have taken minutes to complete. This database step usually takes 1 or 2 seconds. Meaning: With this procedure you never have more than a few seconds downtime, unless you mess up.

The important part here is when you run bin/magento setup:upgrade --keep-generated.

Because, by default the upgrade command will wipe out all of the generated DI files and the copied view-files. To prevent this from happening (because you already generated these files in the steps above), you add the flag --keep-generated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.