Discover practical ways to fix any flaws & weaknesses in your website!
Get a free audit of your ecommerce store. Fix issues before they start costing you a fortune. 🛠️
So, 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.
If you’re not a Magento geek, you may have many questions to be answered:
What are the Magento modes?
How can I know the current mode?
How can I change the mode?
Let’s start with figuring out how the Magento modes differ.
NOTE: Any live Magento 2 site should be inProductionmode. This mode utilizes full page caching alongside a fully built pub folder to pull from. It is optimised to run smoothly and efficiently leading to the greatest customer experience. Production mode is 20-30% faster than Developer mode.
Magento 2 Modes
One major difference between the Magento 1 and Magento 2 platforms is the introduction of development Modes. Magento 2 modes were introduced with the release of Magento 2 that reflects varying configurations of the Magento codebase, affecting site operations and performance.
Magento 1 was operated with a single state for development and production, Magento 2 now boasts 3 separate Modes: Default, Developer, and Production.
Magento 2 modes overview
Magento has three modes of operationfor deployment in a development or production environment:
Default, Developer and Production modes. The fastest one is Production. Default and Developer modes are used for debugging purposes and should never be used for a live site.
Default – enables you to deploy the Magento application on a single server without changing any settings. However, the Default mode is not optimized for production.
Production – intended for deployment on a production system.
And one mode for maintenance:
Maintenance – intended to prevent access to a Magento Commerce site while it is being updated or reconfigured.
Here is a brief description of the 3 deployment modes in Magento 2. Let’s take a quick look at each of them!
Magento 2 Default mode
As the name suggests, the Default mode is when no other mode is specified. The Default mode is usually used when we launch the Magento 2 site for the first time.
This mode is a hybrid ofDeveloper and Production modes 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.
In the Default mode, there are no main characteristics for production, that is why you need to switch to Developer mode or Production mode.
Errors are never shown to the user. In the Default mode errors are logged in the file reports on the server. So while debugging is possible, it is not ideal for development.
After we switch out of theDefaultmode to another one, it is impossible to go back to this mode, because Default mode is not intended for the long-term use of Magento and site support, it was introduced only to help launch sites.
Static view files are first materialised and then cached. Hence, this mode is not ideal for the production environment.
For each requested file on the site, a symlink is created in the pub/staticdirectory. 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.
In the Default mode, you can deploy the Magento application on a single server without any changes in the settings.
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.
Magento 2 Development mode
The mode for the developers – to do all their development tasks! The Developer mode is intended only for development. This is the mode you should use to customise and expand Magento.
Caching can be utilised 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 on the frontend and Magento admin.
Developer mode automatically compiles code and offers more advanced logging (in verbose) and debugging capabilities than that of Default or Production modes. – Exceptions are seen in the error handler rather than being logged, it means that 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 results in faster debugging of extension conflicts.
Static view files are written to the Magento pub/static directory every time they’re called and are not cached.
Uncaught exceptions and errors are displayed in the browser.
NOTE: Use this mode whenever you are customising or extending the Magento 2’s default functionalities.
Production mode
Production mode is designed for deployment on a production system. All live sites must have Production mode since full caching of web pages is used in Production mode, which ensures smooth and efficient work for clients on the site.
Static files are stored in cache only. This mode utilises full page caching alongside a fully built pub folder to pull from and is optimised to run smoothly and efficiently leading to the greatest customer experience.
Debugging is more difficult in Production mode as the errors are logged at the server level and never shown to the user on the frontend.
Production mode uses full page caching with a fully built pub folder to pull from, which results in the smooth and efficient functioning of the store. If you are concerned about offering the best customer experience, you must switch your store to this mode.
In terms of security, the Production mode is the most secure as well due to the fact that there is no symlink created for the pub/static folder. If an unauthenticated user gets access to the pub/static to change the data, it would only be the duplicate versions of those files, overwritten during the next static deployment!
In terms of speed,
Anytime you switch from Developer toProductionmode two actions must first be taken:
1. Static Deploy – this populates everything in the pub/static folder which a Production M2 site will then build and serve content from.
2. Compilation – this takes your site’s code and merges it into bytecode which ultimately allows for the faster retrieval of classes and results in faster page load times on the frontend. 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 deployment.
How to check the current Magento 2 mode
You are not a tech person, but the business owner who wants to know the mode of his/her store? Following the steps below, you can easily check whether your site is in Productionmode or not.
If you have shared hosting, this is the user your provider gives you to log in to the server.
If you have a private server, it’s typically a local user account on the Magento server.
You need an SSH client on your computer.
On Mac, you can use Terminal which is included by default, or a third-party application like Termius.
On Windows-based computers, you can install a third-party application like PuTTY.
When connecting via SSH use this info:
Host: ssh.example.com Username: example.com Password: the one you chose for SSH in your Control Panel Port: 22
NOTE: Remember to replace example.com with your own domain.
Step 2.
Navigate to the root Magento directory. Typically it’s public_html, but not necessarily. You can always check with your hosting provider to find your site’s root.
Step 3.
Navigate to the /bin directory within the site root.
Step 4.
Run the following command: php bin/magento deploy:mode:show
A message similar to the following displays which mode your Magento 2 site is currently using:
Current application mode: {mode}. (Note: Environment variables may override this value.)
where: {mode} can be either Default, Developer or Production
OR
So, what is your website mode in the end?
If it’s a live site in the Developer mode, it might be an issue. So, let us know if you need any Magento help with your store!
How to change the Magento mode
NOTE: You should not change your site’s mode directly on the live site without first testing this fully in a development environment.
Step 1.
SSH into your site’s server.
Step 2.
Navigate to the site’s root- then to the /bin directory.
Step 3.
Run the following command: php bin/magento deploy:mode:set {mode} [-s/-skip-compilation]
where:
{mode} is a required parameter (Developer or Production);
[-s/-skip-compilation]is an optional parameter(it’s used for skipping the compilation when switching to the code>Developer mode).
In the command above you can use either the value Developer or Productionmode to switch to the corresponding mode. Once you switch the site’s mode and everything works out well, you will see the following line in the console:
Enabled developer mode. or Enabled production mode.
Now with this being so easy to do in theory, one would wonder why his/her site is not even in Productionmode. One common issue is that there is a fault somewhere in the system that breaks the site when running this command and may take some time for a developer to identify the root cause of this.
Therefore it’s common that we see that developers tend to leave it in Developermode, as not to have the headache of fixing the issue as it may be a deep-rooted problem that’s not so easy to solve.
Switching modes: tips to follow
The things you should consider when attempting to convert into Productionmode:
Under no circumstances attempt to do it in the middle of a transactional day as it may completely ruin your site for a period of time.
Take a full backup of the Magento files and database before attempting to convert so you have a fallback if things go wrong.
Ideally, you would try to do it on staging first, so you can see the probability of it succeeding or failing in a live environment – obviously, there are always small variables that can be different on each server environment.
When switching to the Developer or Productionmode, we recommend clearing the contents of the following folders (be careful not to delete the .htaccess files, they register configuration changes for each directory):
var/cache
var/di
pub/static
var/generation
var/view_preprocessed
Sometimes, while switching modes you will encounter errors that prevent the mode change. These errors must be tracked down and resolved before the mode can be changed.
Why you should enable Production mode on live environment
Developer mode optimises the website for the developer to quickly work on and deploy new changes with minimal time to see new changes on the site frontend – for example, there is no static content deployed in the cache which would allow the developer to make changes without having to run lengthy/time-consuming commands to flush the files out the browser reads, e.g. updating the website.
However, this means that the actual page load is also increased by around 20-30% due to exactly what makes it easier for a developer to see new changes: There is no static content which essentially would work as a cache for browsers not to have to load many files on the fly.
This is a huge disadvantage as we know the website is already slow and will be affecting your conversions due to users on slow connections exiting the site with it being so slow.
It must be clear that the live Magento 2 site must be in Production mode. The earlier you switch, the better! It is easier to switch a Magento 2 site to Productionmode with less customisation.
Recap
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 offers greater performance and functionality for the platform now and for the future.
Magento 2 comes equipped with various performance optimisation features. Your job is to configure them properly.
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!