Should we set magento to maintenance mode before setup:upgrade and setup:di:compile?
-
13-04-2021 - |
سؤال
Does executing setup:upgrade
or setup:di:compile
cause any problems if I execute it in production? I fear that my customers will see errors after I call these commands.
المحلول
You should definitely set Magento to maintenance mode before running setup:upgrade
or setup:di:compile
in production.
setup:upgrade
clears both the generated/code
and pub/static
folders which will most likely result in your customers seeing an error page. Since they can't use the store anyways it is best to present them the maintenance page so they know the store will be available in a short time.
If you are concerned about downtime you can setup a build system where you can run setup:di:compile
and setup:static-content:deploy
while your production system is still running and only run setup:upgrade --keep-generated
while in maintenance mode.
You can read more about setting up a build system here: https://devdocs.magento.com/guides/v2.3/config-guide/deployment/pipeline/build-system.html
An easier, but more "hacky" way could be building your "new" production system in a different folder and then pointing your document root with a symlink to the new production system after you're done. This can be done with only a few seconds of downtime.
You can read more about that approach here: https://www.hypernode.com/blog/time-saving/how-to-choose-the-best-method-to-deploy-code#example
نصائح أخرى
In production mode setup:upgrade
will clear all static content, this could cause problems for any customers browsing the site who may end up with a nasty error message.
I always switch to maintenance mode before doing this and use a nice custom maintenance page to tell customers what is happening.
I find a deploy script useful to run all the compile and static content deploy commands that I need to get the site ready for production again.