How to Set Production Mode in Magento 2

In this tutorial, we will talk about How to Set Production Mode in Magento 2 via Command Line Series. As you know, from Magento 2, they add many commands in bin/magento. This may be difficult to approach, let me explain in more detail about it.

An overview of Magento 2 modes

Magento 2 Default mode

This mode is when you see how Magento works without any custom settings. It lacks a lot of necessary features used for production, so you will need to switch to another mode.

Below are some details about how this mode operates:

  • Error details stay hidden from customers. Server saves these in a “reports” file.
  • Important files get linked to the “pub/static” folder for easy access.
  • Use the static file creation tool for a smoother way to make and update static files.

Hence, when establishing the platform across multiple servers or deploying it for production purposes, you should select one of the listed modes.

Magento 2 Developer mode

This mode is usually used when you need to customize your Magento 2 store or install extensions to expand Magento 2 Default’s functionalities. With Developer mode, you can do all development tasks.

In this mode, static view files will be written in the Magento pub/static directory every time they are called and are not cached.

Below are some details about how this mode operates:

  • A symlink for each necessary file is placed in the pub/static directory.

  • Uncaught exceptions will be visible in the browser.

  • System logging in var/report is in verbal form, with the exception being placed into the error handler.

  • An exception is triggered when an event subscriber cannot be enforced

Magento 2 Production mode

In Magento 2, you will need to add a command that switches Magento modes from developers to production mode. This action improves the security of your Magento 2 system and makes it easier for you to use.

Below are some details about how this mode operates:

  • Static view file URLs are generated all at once, as long as the files are not materialized.”
  • Errors are stored in the file system, remaining invisible to customers.

Now let’s dig into the tutorial of changing to Production mode in Magento 2.

How to set Product Mode

Show current Magento 2 Mode

php bin/magento deploy:mode:show

Result:

$ php bin/magento deploy:mode:show
Current application mode: default. (Note: Environment variables may override this value.)

Currently, we are in default mode. We can set to Production mode

Set Production Mode

You are a merchant or just want to change to production mode, just run the following command line in Magento root folder:

php bin/magento deploy:mode:set production

Result:

$ php bin/magento deploy:mode:set production
Enabled production mode.

Congrats! Now your store is running in production mode.

Image Description
With over a decade of experience crafting innovative tech solutions for ecommerce businesses built on Magento, Jacker is the mastermind behind our secure and well-functioned extensions. With his expertise in building user-friendly interfaces and robust back-end systems, Mageplaza was able to deliver exceptional Magento solutions and services for over 122K+ customers around the world.
x