Magento 2 – install module (production)
A very difficult task in Magento 2 is to install modules in production mode. If you run a successful store, this may be a task for you to do. The problem is: you can’t just install all module files to your server, the extension has to be enabled. For this you need to make an upgrade and compile you store. I show you all details.
Magento 2 – install module (production)
Magento 2 deployment is more advanced than you may know from Magento 1. In the previous version it was enough to copy the current code and replace the old one. If there are new modules, they are enabled automatically. This means, the create their database structure automatically and are ready to use. You only need to configure it in backend (adminhtml) if needed.
For you Magento 2 shop you have to upload your modules source code too. The main difference is, that this module is by default disabled. You need to enable it. Enabling a module is not enough, because Magento 2 does not create modules database tables automatically. You need to run setup:upgrade. If you use dependency injection (which you really need to, if you want to create good modules), you need to compile with setup:di:compile.
Setps to do
If you install a new module in production mode, you should do the following steps. The same steps should be done if you have a deployment (for example from you git master branch).
- set maintenance mode
during the next steps it is possible, that users may generate error sites. During static-content:deploy the design may display ugly pages. It is ok to show a maintenance page for some minutes. That is more professional than error pages. To reduce pain, do nightly deployments.1php bin/magento maintenance:enable - enable module
this has to be done once for each new module. You can do this manually or you can include it into your deployment script. For automatically enabling or disabling modules you may need module:status command to get current state. Basically you need to call1php bin/magento module:enable MyCompany_MyModule
but you can also mass change module status, for example for different staging environments. - upgrade database
the most important step is to update you database. If you have new modules or new module version, this is the step for creating and updating database tables. If you miss it, you will run into “base table not found” or “column not found” error sites on frontend.1php bin/magento setup:upgrade - compile your code
to update var/generated and var/di folder you need to do a compile. In this steps all dependency injections are updated. This is an important step for accelerate your shop frontend.1php bin/magento setup:di:compile - static content deploy (optional)
in this step your frontend files (*.phtml, *.html, *.css, …) are generated. If your module has changes of updates for this, you need to do it. If you use more than one language stores, you need to set each language.1php bin/magento setup:static-content:deploy en_US de_DE - reindex (optional)
not needed, but recommended. Update your index tables:1php bin/magento indexer:reindex - clear cache (optional)
to avoid some cache conflicts from old caches, you should clean up and flush your cache:1php bin/magento cache:flush - If you enable maintenance mode on first step, you also should disable it now:1php bin/magento maintenance:disable
Conclusion
I showed you all steps you need to consider if you want to install and enable a new module on your production system. All these steps can also be used by a deployment script, to automatically create a current version based on a git master branch.