All Magento CLI commands must be run by the file system owner.
The static view files deployment command enables you to write static files to the Commerce file system when the Commerce software is set for production mode.
The term static view file refers to the following:
Static view files are located in the
<magento_root>/pub/static directory, and some are cached in the
<magento_root>/var/view_preprocessed directory as well.
Static view files deployment is affected by application modes as follows:
You must write static view files to the Commerce 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.
To deploy static view files:
Log in to the Commerce server as, or switch to the file system owner.
Delete the contents of
<magento_root>/pub/static, except for the
.htaccess file. Do not delete this file.
Run the static view files deployment tool
If you enable static view file merging in the Admin, the
pub/static directory system must be writable.
The following table explains this command’s parameters and values.
||Space-separated list of ISO-639 language codes for which to output static view files. (Default is
Find the list by running:
||Generate files only for the specified languages. The default, with no option specified, is to generate files for all ISO-639 language codes. You can specify the name of one language code at a time. Default value is all.
||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. Default value is none.||No|
||Themes for which to deploy static content. Default value is all.
||Themes to exclude when deploying static content. Default value is none.
||Generate files only for the specified areas. The default, with no option specified, is to generate files for all areas. Valid values are
||Do not generate files for the specified areas. The default, with no option specified, is to exclude nothing. Default value is none.||No|
||Enable parallel processing using the specified number of jobs. The default is 0 (do not run in parallel processes). Default value is 0.||No|
||Create symlinks for the files of those locales, which are passed for deployment, but have no customizations.||No|
||Custom version of static content can be used if running deployment on multiple nodes to ensure that static content version is identical and caching works properly.||No|
||Do not deploy CSS files.||No|
||Do not deploy LESS files.||No|
||Do not deploy images.||No|
||Do not deploy font files.||No|
||Do not deploy HTML files.||No|
||Do not deploy other types of files: MD, JBF, CSV, JSON, TXT, HTC, SWF||No|
||Do not minify HTML files.||No|
||Define the deployment strategy. Use these options only if you have more than one local.||No|
||Do not generate files for the parent themes of the current theme. It is strongly recommended to use this flag if you do not explicitly use the parent theme of the current theme you are trying to deploy. This significantly increases the speed of the process. This flag is available in Commerce 2.4.2||No|
||Deploy files in any mode. (by default, the static 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
<languages> 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 Commerce, and does not minify HTML files.
bin/magento setup:static-content:deploy en_US --exclude-theme Magento/luma --no-html-minify
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 ---
bin/magento setup:static-content:deploy -s standard --no-misc --no-html --no-fonts --no-images --no-less --no-css -j 4
The following command deploys only CSS and LESS with 3 jobs, and a quick deployment strategy:
The following command generates static view files for all languages, the frontend area only, the Commerce Luma theme only, without generating fonts:
bin/magento setup:static-content:deploy --area frontend --no-fonts --theme Magento/luma
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
You might want to run the deployment process in a separate, non-production, environment, to avoid any build processes on sensitive production machines.
To do this, take the following steps:
bin/magento app:config:dumpto export the configuration from your production system.
Install the Commerce software first; otherwise, you cannot run the static view files deployment tool.
Symptom: The following error is displayed when you run the static view files deployment tool:
ERROR: You need to install the Commerce application before running this utility.
Use the following steps:
<app_root>/pub/staticdirectory, except for the
.htaccessfile. Do not delete this file.
When creating a custom implementation of the static content deployment tool, use only atomic file writing for files that should be available on the client. If you use non-atomic file writing, those files might be loaded on the client with partial content.
One of the options for making it atomic is to write to files stored in a temporary directory and copying or moving them to the destination directory (from where they are loaded to client) after writing is over. For details about writing to files, see php fwrite.