Home >Deploy in Magento 2 from A to Z

Deploy in Magento 2 from A to Z

Deployment is a required step in Magento 2, which is new to users who were able to change the code of a webshop on a fly, as in Magento 1. As usual, improvements and modifications take place frequently to adjust websites to the demand of the shop owners and more importantly, elements of website performance are the elevating concern to customers online. New changes that are made to the interface should be evermore promptly updated and that’s why Magento 2 deployment has become common to merchants. 

The command to set mode in Magento 2 

When you want to set one mode Magento, use this following command. 

bin/magento deploy:mode:set {mode} [-s|--skip-compilation]

To explain the contained elements: 

  • {mode}: required term; can be either default, developer or production
  • –skip-compilation: optional parameter that you can use to skip code compilation when you switch to production mode

Above is the main command for deployment. However, Magento allows the system to run in different modes. Let’s see how actions differ from each other among modes.   

The 3 modes in Magento 2

In this section, you will find how Magento system behaves in each mode and the suitable usage of each mode in different conditions.

Default mode

  • Errors are logged at the server level (at report files), these errors are not displayed to users
  • A symlink to a static view file is published to the pub/static directory for each requested file

Developer mode

Use this command

bin/magento deploy:mode:set developer
  • A symlink to a static view file is published to the pub/static directory for each requested file
  • An exception is thrown in the error handler, rather than being logged
  • An exception is thrown when an event subscriber cannot be invoked

Production mode

Use this command

bin/magento deploy:mode:set production
  • Users can enable/disable Cache memory via command lines
  • Static view files are not generated or cached and their URL s are promptly generated without going through the fallback mechanism

An example command in production mode

Let’s take an example command in Production mode. In this case, we try to deploy static content. This action will create static content files (static view files), which can be seen in <your Magento 2 install dir>/pub/static

Step 1: We set the mode as “Production”. Use this command

bin/magento deploy:mode:set production

Step 2: Deploy static content. To complete this action, run this command

magento setup:static-content:deploy <lang> ... <lang> [-options]

The following table will explain this command’s parameters and values

Deploy magento 2
Parameters and values in the command (Magento 2 deploy)

More commands of Magento 2 deployment

Next, we give you an additional sample of commands. Merchants can use these commands for different purposes. 

Actions Commands
Deploy in adminhtml area php bin/magento setup:static-content:deploy –area adminhtml –language en_US
Deploy in frontend area php bin/magento setup:static-content:deploy –area frontend –language en_US
Deploy with themes php bin/magento setup:static-content:deploy –theme Bss/mytheme
Deploy while excluding themes php bin/magento setup:static-content:deploy –exclude-theme Magento/luma

When to deploy in Magento 2

Commonly, there are many cases that you need to deploy in Magento. To be concise, there are two main cases to run Magento deployment:

  • Install new modules
  • Change Magento theme ( including CSS, LESS files, etc.)

Notices for developers when deploying in Magento 2Lastly, to smoothly run deployment in Magento, just check out these following notices.

  • Remove all old files in pub/static/frontend to assure that the system has been totally refreshed when you enable a new module
  • To delete the cache file, use this command:
rm -rf var/di/* var/generation/* var/cache/* var/page_cache/* var/view_preprocessed/*

This is the end of our knowledge sharing. Hope that you can use it wisely for your business. Don’t forget that we always have broad classes of Magento sources here. Sure! you will find useful information that you need at any time!

< Previous Post
Next Post >
+ posts