Magento 2 Modes and how to change between them

#1

Explanation of Magento 2 Modes

Default

Default Mode is how Magento comes straight out-the-box. It’s a mixture of both Developer and Production mode, where it doesn’t have the debugging capability as Developer Mode or the speed of Production Mode. Therefore Default Mode serves no real purpose other than allowing you to quickly become familiar with Magento and quickly launch the store online.

If you attempt to do any development in Default Mode - whilst possible - you’ll find your workflow quite difficult. That’s because all error logs are stored in various log files within the Magento directory. So, debugging issues takes longer whilst you sift through files.

And if you were to make your online store public, you would be hindered by the speed of the site. This is because Default Mode does not have the complete caching potential as Production Mode because pages are still generated on-the-fly, as opposed to being prebuilt. Launching the store in Default Mode also poses a security issue based on how the file structured is set out.

Personally, I don’t use Default Mode. As soon as I install a clean copy of Magento I switch it straight into Developer Mode.

Developer

Speaking of Developer Mode, this is the ideal Mode you would set Magento 2 when developing your store. You’ll find that all of the settings and capabilities are set to aid you for developing your online store - All at the sacrifice of speed.

Whilst in Developer Mode you’ll notice that a majority of error message are displayed directly on the web page. Therefore you are aware of an immediate issue or cause, without the need to sift through any log files.

As I mentioned, this is the slowest of the Modes. And that’s because none of the code gets cached (albeit you can turn on some limited caching options). The reason for the lack of caching is so you can view your code changes in real-time. Therefore if you’re making cosmetic amendments to your website, then you don’t have to keep flushing the cache or recompling code every time you want to view your changes.

Production

Next we have Production Mode. This Mode is built for speed and optimisation and is the ideal Mode to have your store in when you go live to the public. Whilst in this Mode, all page content is cached to decrease page-load times. And a large chunk of the code is compiled to increase overall system performance of your web server.

Production Mode is also the most secure. In that the file structure is not vulnerable (unlike Default and Developer Mode) and some of the backend settings are disabled to minimise the risk of breaking something. On top of that, no error messages will ever be displayed in the web browser. Due to some error messages containing sensitive information.

This ultimately means that Production Mode is the hardest of all modes to Debug issues or make new development changes.

Maintenance

Finally we have Maintenance Mode, although this technically isn’t a mode you’d use like the last 3. Instead, it’s more of a protective option you can use in conjunction with a mode you’re already in.

The purpose of this Mode is to prevent unwanted access to your online store whilst you carry out maintenance tasks like system upgrades. Checkout the links in the Video Description below, where you’ll find other Maintenance Mode videos I’ve published in the past.

How to switch between Magento 2 Modes

In the second part of this video, I’ll show you how to cycle between Default, Developer and Production Modes in Magento 2. If you want to know how to use Maintenance Mode, checkout the Video Description or wait until the end of the video where is will display as the recommended video to watch next.

Also, from this point onwards you’ll need to be logged into your server via SSH so that you can carry out the following instructions via the Command Line Interface. Once logged in, you’ll want to make sure you’re using the “magento user” and sitting in the Magento root directory.

All of these commands can be copied directly from the supporting article to help you follow along more easily. You’ll find a link to that article in the Video Description below.

Displaying the current set Mode

So, the first trick I want to show you is displaying what Mode you are currently in. This is easily achieved by running:

bin/magento deploy:mode:show

Switching between Default and Developer Modes

Next, I’ll show you how to switch between Default and Developer Modes.

Because I’m already in Default Mode I’ll start by switching to Developer Mode first. This is achieved by running:

bin/magento deploy:mode:set developer

And then to switch back to Default Mode, I’d run:

bin/magento deploy:mode:set default

As you can see by the command, I’m simply changing the last word of the command to either “default” or “developer”. Switching to either of these Modes is super-quick.

Switching to Production Mode

Next, I’ll show you how to switch to Production Mode. This one normally takes a couple of minutes as it needs to compile all of its code in order to make it fast and efficient for public use. To switch to this mode run:

bin/magento deploy:mode:set production

As you can see, the screen starts to fill with a progress of report. For the sake of this video, I’ll speed this up.

Changing from Production to Developer Mode

There’s one last thing I want to cover. And that’s switching from Production to Developer Mode. When you do this, you’ll be require to run one extra step. The step is required to clear some of the folders that contain some of the pre-compiled code that Production Mode creates.

Right now I’m still in Production Mode. So to switch to Developer Mode, I’ll run the same command as earlier, which was:

bin/magento deploy:mode:set developer

And the only other step is to run the command which deletes some of those files I mentioned. That’s done by running:

rm -rf generated/metadata/* generated/code/*
0 Likes