One major difference between the Magento 1 and Magento 2 platforms is the introduction of development Modes(1), these reflect varying configurations of the Magento codebase which affect site operations and performance. Magento 1 had a single state for development and production, Magento 2 now boasts 3 separate Modes: Default, Developer, and Production.
Magento 2 Modes Overview
Magento 2’s “out-of-the-box” mode. When you initially launch a Magento 2 site it is typically in Default mode(2). This mode is a hybrid of Developer and Production and appears to be intended to ramp up the time-to-launch for base Magento 2 sites due to the ability to develop without compiling code as well as a standardized set of configurations. While this can lead to a quicker time-to-launch, new modifications and maintenance will ultimately save you time in Developer mode due to the more advanced development functionality outlined in the next section.
In Default mode errors are logged at the server level so while debugging is possible, it is not ideal for development. For each requested file on the site a symlink is created in the pub/static directory. This means that in Default mode full page cache is not being fully utilized as the site still serves content dynamically for each request rather than drawing from the cache.
The existence of a symlink(3) to the pub/static directory when a live site is in Default mode poses a potential security risk as well because it opens the possibility of modifying the actual files on the server, whereas when no symlink exists a modification to the files in the pub folder would be wiped away any time a static deploy is executed.
It is important to note that once a Magento 2 site is switched out of Default mode it is impossible to go back to this mode. This is because Default mode was not intended for long term use, it was introduced to help launch sites but not to maintain and grow stores moving forward.
The mode in which all development should* be done. This mode is much slower on the frontend and within the site admin, with the tradeoff that it automatically compiles code and offers more advanced logging and debugging capabilities than Default or Production modes. Caching can be utilized while in developer mode it is typically disabled to speed up development testing. This in combination with the lack of a populated and utilized /pub folder leads to exceptionally slow load times.
The tradeoff for the load times comes in the substantially more comprehensive logging and debugging capabilities Default mode offers which include:
- Exceptions appear in the error handler rather than being logged, meaning the actual errors are displayed in the browser rather than displaying just the error number which then has to be tracked down in the file reports at the server.
- Exceptions are also thrown in the browser when event subscribers cannot be invoked which leads to faster debugging of extension conflicts.
All live Magento 2 sites should be in Production mode. This mode utilizes full page caching alongside a fully built pub folder to pull from, and is optimized to run smoothly and efficiently leading to the greatest customer experience. Debugging is more difficult in Production mode as they are logged at the server level and not displayed to the user on the frontend.
Anytime you switch from Developer to Production mode two actions must first be taken:
- Static Deploy- this populates everything in the pub/static folder which a Production M2 site will then build and serve content from.
- Compilation- this takes your site’s code and merges it into bytecode which ultimately allows for faster retrieval of classes and results in faster page load times on the frontend.
Production mode is more secure than Default or Developer mode as well due to the fact that there is no symlink created for the pub/static folder. This means if a malicious user were to gain access to pub/static and make changes they would only be changing duplicate versions of those files which would be overwritten during the next static deploy.
The Unfortunate Reality
Is that just about every client running Magento 2 that has come to us for work has been operating an M2 site in Default mode because there isn’t enough awareness about this new feature. The good news is that most sites in Default mode can easily be switched to Production mode as long as there aren’t an intensive number of customizations to the site.
On the other hand, we have encountered more than a handful of Magento 2 sites in Default mode that have required a significant number of hours to transfer to Production mode. We are finding that the longer a site sits in Default mode and continues to be modified the more involved switching to Production mode becomes because errors and conflicts become more likely.
Therefore, if you operate a Magento 2 store and are uncertain what mode your site is in, we recommend you check and verify that your live site is in Production mode as intended. To do so, follow the steps outlined in the following section.
How to Check Which Magento Mode Your Site is Using in 4 Simple Steps
SSH into your site’s server using an application like Putty.
Navigate to the site’s root- typically public_html but not necessarily. You can always check with your hosting provider to find your site’s root.
Navigate to the /bin directory within the site root.
Run the following command: php magento deploy:mode:show
Your terminal will then display which mode your Magento 2 site is currently using:
How to Change Your Site’s Mode
*Note that you should not change your site’s mode directly on the live site without first testing this fully in a development environment.
SSH into your site’s server using an application like Putty.
Navigate to the site’s root- then to the /bin directory.
Run the following command: php magento deploy:mode:set production
In the command above you can use either the value “production” or “developer” to switch to the corresponding mode. Once you switch the site’s mode you will see a series of processes and outputs like this:
As you can see, it is possible that while switching modes you will encounter errors which prevent the mode change. These errors must be tracked down and resolved before the mode can be changed.
You should now have a better understanding of the differences between the three modes for Magento 2, as well as how to verify which mode your site is using and how to change modes. Using the different modes for Magento 2 presents new opportunities during development and ultimately offer greater performance and functionality for the platform now and for the future.
We are always looking for ways that we can help the Magento community grow, so please let us know any questions or feedback you have!
- Modes: Varying configurations of the platform codebase which affect site operations and performance.
- Default Mode: Allows quicker time to launch due to the lack of need to compile code and a standardized set of configurations.
- Symlink: Symbolic link. Like a desktop shortcut- not the actual application, but a shortcut that makes it easier to access information pulled from different locations without affecting the information itself.
About Jared Sheilds
Jared is a Senior Project Manager at Customer Paradigm. He is focused on every aspect of providing the most customer-centric experience possible and loves helping his clients get the most of the e-commerce experience. Outside of the office, Jared can be found throwing around a frisbee or on one of Colorados many hiking trails.
View all posts by Jared | LinkedIn