layout | group | subgroup | title | menu_title | menu_node | menu_order | version | github_link | redirect_from |
---|---|---|---|---|---|---|---|---|---|
default |
config-guide |
04_CLI |
Deploy static view files |
Deploy static view files |
300 |
2.0 |
config-guide/cli/config-cli-subcommands-static-view.md |
/guides/v1.0/config-guide/cli/config-cli-subcommands-static-view.html |
- Overview of static view files deployment
- First steps
- Deploy static view files
- Troubleshooting the static view files deployment tool
The term static view file refers to the following:
- "Static" means it can be cached for a site (that is, the file is not dynamically generated). Examples include images and CSS generated from LESS.
- "View" refers to presentation layer (from MVC).
Static view files are located in the <your Magento install dir>/pub/static
directory, and some are cached in the <your Magento install dir>/var/view_preprocessed
directory as well.
Static view files deployment is affected by Magento modes as follows:
-
The default and developer mode: Magento generates them on demand, but the rest are cached in a file for speed of access.
-
The production mode: Static files are not generated or cached.
You must write static view files to the Magento file system manually using the command discussed in this topic; after that, you can restrict permissions to limit your vulnerabilities and to prevent accidental or malicious overwriting of files.
Developer mode only: When you install or enable a new module, it might load new JavaScript, CSS, layouts, and so on. To avoid issues with static files, you must clean the old files to make sure you get all the changes for the new module.
You can clean generated static view files in any of the following ways:
- Manually by clearing the
pub/static
andvar/view_preprocessed
directories and subdirectories. except forpub/static/.htaccess
.
To clear thepub/static
directory of all files except.htaccess
(which is a hidden file), enter the following command:
rm -R pub/static/*
- Using the Magento command line. Several commands support an optional parameter
--clear-static-content
, which cleans generated static view files. For example, see Enable or disable modules. - In the Magento Admin. Go to System > Tools > Cache Management and click Flush Static Files Cache.
- Log in to the Magento server as, or switch to, the Magento file system owner.
- Delete the contents of
<your Magento install dir>/pub/static
. - Run the static view files deployment tool
<your Magento install dir>/bin/magento setup:static-content:deploy
.
<div class="bs-callout bs-callout-info" id="info">
<span class="glyphicon-class">
<p>If you enable static view file merging in the Magento Admin, the <code>pub/static</code> directory system must be writable.</p></span>
</div>
Command options:
magento setup:static-content:deploy [<list of locales>] [-t|--theme[="<theme>"]] [--exclude-theme[="<theme>"]] [-l|--language[="<language>"]] [--exclude-language[="<language>"]] [-a|--area[="<area>"]] [--exclude-area[="<area>"]] [-j|--jobs[="<number>"]] [--no-javascript] [--no-css] [--no-less] [--no-images] [--no-fonts] [--no-html] [--no-misc] [--no-html-minify] [-d|--dry-run] [-f|--force]
The following table discusses the meanings of this command's parameters and values.
</tbody>
Option | Description | Required? |
---|---|---|
<lang> | List of ISO-636 language codes for which to output static view files. (Default is You can find the list by running |
No |
--language (-l) | Generate files only for the specified languages. The default, with no option specified, is to generate files for all ISO-636 language codes. You can specify the name of one language code at a time. For example, |
No |
--exclude-language | Generate files for the specified language codes. The default, with no option specified, is to exclude nothing. You can specify the name of one language code or a comma-separated list of language codes. |
No |
--theme <theme> | Themes for which to deploy static content. For example, |
No |
--exclude-theme <theme> | Themes to exclude when deploying static content. For example, |
No |
--area (-a) | Generate files only for the specified areas. The default, with no option specified, is to generate files for all areas. Valid values are For example, |
No |
--exclude-area | Do not generate files for the specified areas. The default, with no option specified, is to exclude nothing. |
No |
--jobs (-j) | Enable parallel processing using the specified number of jobs. The default is 4. To cause the task to run in one process (for example, if your system does not support process forking), use |
No |
--no-javascript | Do not deploy JavaScript files |
No |
--no-css | Do not deploy CSS files. |
No |
--no-less | Do not deploy LESS files. |
No |
--no-images | Do not deploy images. | No |
--no-fonts | Do not deploy font files. |
No |
--no-html |
Do not deploy HTML files. |
No |
--no-misc | Do not deploy other types of files (that is |
No |
--no-html-minify | Do not minify HTML files. |
No |
--dry-run (-d) | Include to view the files output by the tool without outputting anything. |
No |
--force (-f) | Deploy files in any mode. (by default, static content content deployment tool can be run only in production mode. Use this option to run it in default or developer mode). |
No |
If you specify values for both <lang>
and --language
, <lang>
takes precedence.
Following are some example commands.
The following command deploys static content for the US English (en_US
) language, excludes the Luma theme provided with Magento, and does not minify HTML files.
magento setup:static-content:deploy en_US --exclude-theme Magento/luma --no-html-minify
Sample output:
Requested languages: en_US
Requested areas: frontend, adminhtml
Requested themes: Magento/blank, Magento/backend
=== frontend -> Magento/blank -> en_US ===
=== adminhtml -> Magento/backend -> en_US ===
...........................................................
... more ...
Successful: 2055 files; errors: 0
---
New version of deployed files: 1466710645
............
Successful: 1993 files; errors: 0
---
The following command generates static view files for all languages, the frontend area only, the Magento Luma theme only, without generating fonts:
magento setup:static-content:deploy --area frontend --no-fonts --theme Magento/luma
Sample output:
Requested languages: en_US
Requested areas: frontend
Requested themes: Magento/luma
=== frontend -> Magento/luma -> en_US ===
...........................................................
... more ...
........................................................................
Successful: 2092 files; errors: 0
---
New version of deployed files: 1466711110
Symptom: The following error is displayed when you run the static view files deployment tool:
ERROR: You need to install the Magento application before running this utility.
Solution:
Use the following steps:
-
Install the Magento software in any of the following ways:
-
Log in to the Magento server as, or switch to, the Magento file system owner.
-
Delete the contents of
<your Magento install dir>/pub/static
directory.
<!-- <div class="bs-callout bs-callout-info" id="info">
<span class="glyphicon-class">
<p>If you enable static view file merging in the Magento Admin, the <code>pub/static</code> directory system must be writable.</p></span>
</div> -->
When creating a custom implementation of the static content deployment tool, do not use non atomic writing to files that should be available on the client side. Otherwise, those files might be loaded on the client side with partial content.
One of the options for making it atomic, is writing to files stored in a temporary directory and coping or moving them to the destination directory (from where they are actually loaded to client side) once writing is over. For details about writing to files see http://php.net/manual/en/function.fwrite.php.
Please note, that the default Magento implementation of \Magento\Framework\Filesystem\Directory\WriteInterface::writeFile
uses non-atomic write to file.