Skip to content

Latest commit

 

History

History
159 lines (122 loc) · 9.13 KB

config-cli-subcommands-static-view.md

File metadata and controls

159 lines (122 loc) · 9.13 KB
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

The static view files deployment command enables you to write static files to the Magento file system when the Magento software is set for production mode.

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:

  • Developer mode: Magento generates them on demand, but the rest are cached in a file for speed of access.

  • Default and production modes: 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 and var/view_preprocessed directories and subdirectories. except for pub/static/.htaccess.

    To clear the pub/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.

First steps

{% include install/first-steps-cli.html %} In addition to the command arguments discussed here, see Common arguments.

Deploy static view files

To deploy static view files:
  1. Log in to the Magento server as, or switch to, the Magento file system owner.
  2. Delete the contents of <your Magento install dir>/pub/static.
  3. 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 <lang> ... <lang> [--dry-run] 

The following table discusses the meanings of this command's parameters and values.

Option Description Required?
<lang>

Space-separated list of ISO-636 language codes for which to output static view files. (Default is en_US.)

You can find the list by running magento info:language:list.

No

--dry-run

Include to view the files output by the tool without outputting anything.

No

For example, to deploy static view files for the pt_BR language, enter

magento --ansi setup:static-content:deploy pt_BR

Following are some sample messages that display to indicate successful deployment:

Requested languages: pt_BR
=== frontend -> Magento/luma -> pt_BR ===
... progress indicator ...
Successful: 1613 files; errors: 0

=== frontend -> Magento/blank -> pt_BR ===
... progress indicator ...
Successful: 1620 files; errors: 0

=== adminhtml -> Magento/backend -> pt_BR ===
... progress indicator ...
Successful: 1626 files; errors: 0

=== Minify templates ===
... progress indicator ...
Successful: 858 files modified
---
New version of deployed files: 1430773903

Troubleshooting the static view files deployment tool

Install the Magento 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 Magento application before running this utility.

Solution:

Use the following steps:

  1. Install the Magento software in any of the following ways:

  2. Log in to the Magento server as, or switch to, the Magento file system owner.

  3. Delete the contents of <your Magento install dir>/pub/static directory.

  4. Run the static view files deployment tool.

<!-- <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> -->

Tips for developers customizing the static content deployment tool

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 copying 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.

Related topics