Contents
Overview of setting Magento modes
To improve security and ease-of-use, we added a command that switches Magento modes from developer to production and vice versa. When doing so, we set file permissions and ownership appropriately.
Production mode also has better performance because static view files are populated in the pub/static
directory and because of code compilation.
Developer mode uses a less restrictive set of permissions than does production mode for the following reasons:
- Developer mode is intended for internal development on a system already secured behind a firewall; also, the system doesn鈥檛 need to handle internet traffic
-
Production mode servers handle internet traffic, process payments, and so on
As the name implies, you change to production mode before you deploy your Magento storefront to production and start taking orders.
Unlike other Magento modes, developer and production modes are set in env.php
.
Cleared directories
When you change to developer or production mode, we clear the contents of following directories when you change modes:
var/cache
var/di
var/generation
var/view_preprocessed
pub/static
Exceptions:
.htaccess
files are not removedpub/static
contains a file that specifies the version of static content; this file is not removed
By default, Magento uses the var
directories to store the cache, logs, and compiled code. You can customize this directory but in this guide, it's assumed to be var
.
Permissions and ownership for developer mode
When you change to developer mode, we clear directories only; we don鈥檛 set specific permissions on existing files.
However, we set the following permissions on these directories and subdirectories:
-
Directories: 770
770 permissions give full control to the owner and to the group, and no permissions to anyone else.
-
Files: 660
660 permissions give read-write permissions to the owner and to the group, and no permissions to anyone else.
Permissions and ownership for production mode
Changing modes affects permissions and ownership the following subdirectories in your Magento installation:
var/view_preprocessed
var/generation
var/di
Permissions for production mode
When you change to production mode, we set the following permissions on these directories and subdirectories:
-
Directories: 750
750 permissions give full control to the owner, read and execute permissions to the group, and no permissions to anyone else.
-
Files: 640
640 permissions give read-write permissions to the owner, read-only permissions to the group, and no permissions to anyone else.
For more information about UNIX permissions, see:
Ownership for production mode
We recommend the following:
-
The directories and files in the Magento file system should be owned by a user other than the web server user but must be writable by the web server user.
We refer to this other user as the Magento file system owner.
Exceptions:
var/di
,var/generation
, andvar/view_preprocessed
-
The directories and files under
pub/static
should have 770 permissions, which give the owner and the group full control.
The easiest way to do that is to run this command as a user in the same group as the web server user. For details, see Create the Magento file system owner.
Display the current mode
Command usage:
magento deploy:mode:show
A message similar to the following displays:
Current application mode: developer.
Change modes
Command usage:
magento deploy:mode:set {mode} [-s|--skip-compilation]
where
{mode}
is required; it can be either developer
or production
--skip-compilation
is an optional parameter you can use to skip code compilation when you change to production mode.
Examples follow.
Change to production mode
magento deploy:mode:set production
Following is a summary of messages that display:
Enabled maintenance mode
Requested languages: en_US
=== frontend -> Magento/luma -> en_US ===
... more ...
Successful: 1884 files; errors: 0
---
=== frontend -> Magento/blank -> en_US ===
... more ...
Successful: 1828 files; errors: 0
---
=== adminhtml -> Magento/backend -> en_US ===
... more ...
---
=== Minify templates ===
... more ...
Successful: 897 files modified
---
New version of deployed files: 1440461332
Static content deployment complete Gathering css/styles-m.less sources. Successfully processed LESS and/or SASS files CSS deployment complete Generated classes:
Magento\Sales\Api\Data\CreditmemoCommentInterfacePersistor
Magento\Sales\Api\Data\CreditmemoCommentInterfaceFactory
Magento\Sales\Api\Data\CreditmemoCommentSearchResultInterfaceFactory
Magento\Sales\Api\Data\CreditmemoComment\Repository
Magento\Sales\Api\Data\CreditmemoItemInterfacePersistor
... more ...
Compilation complete
Disabled maintenance mode
Enabled production mode.
Change to developer mode
When you change from production to developer mode, you should clear generated classes and Object Manager entities like proxies to prevent unexpected errors. After doing so, you can change modes. Use the following steps:
-
If you鈥檙e changing from production mode to developer mode, delete the contents of the
var/generation
andvar/di
directories:rm -rf <your Magento install dir>/var/di/* <your Magento install dir>/var/generation/*
-
Set the mode:
magento deploy:mode:set developer
The following message displays:
Switched to developer mode.
Find us on