This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Deploy Static View Files in Magento 2 Using CLI

Updated on June 16, 2022

3 Min Read

Static View is made with two different words, “static” and “view”. Here, static means that file data can be cached for a site for which files are not dynamically created. And the word view refers to the presentation layer from Model-View-Controller (MVC). In simple words, the deployment commands of static view files enable us to write static files to the Magento 2 file system when we set Magento 2 for production mode.

These static view files are located in Magento’s static directory (your Magento 2 install dir/pub/static) and some files are cached in your Magento 2 install dir/var/view_preprocessed directory. Deployment of static view files is affected by these Magento Modes: Production mode, Default mode, and Developer mode.

We need to write static view files to the Magento 2 file system manually using the CLI command. We can restrict permissions to limit our vulnerabilities and to overwrite files after using the commands I show in this article.

Scalable, Super Fast, & Secure Magento Hosting

Our Clients Love us because we never compromise on these features

Note: In only developer mode: When we install or enable a new module, it may load new CSS, JavaScript, Layouts, etc. To stay away from issues with static files, we must clean the old files to make sure we everything runs great on the new module.

In this way, you can easily clean generated static view files:

  1. By clearing pub/static and var/view_preprocessed directories and subdirectories except pub/static/.htaccess. To clear all the files under pub/static directory except .htaccess file use this command:
find . -depth -name .htaccess -prune -o -delete

This is the manual way to clean generated static view files.

  1. In the Magento 2 admin panel, go to System > Tools > Cache Management and click on the Flush Static Files Cache.

This is the automated way to clean generated static view files.

Let’s start with deployment of static view files in Magento 2.

Login to your Magento 2 server as a user who has permissions to write to the Magento 2 file system. If you are using bash shell, you can use the syntax mentioned below to switch to the Magneto file system owner.

su <Magento file system owner> -s /bin/bash -c <command>

To run Magento 2 command from any directory add /bin after your Magento 2 install directory path.

In Magento 2, we can also run the commands in the following ways:

cd <your Magento 2 install dir>/bin and run them as ./magento <command name>
php <your Magento install dir>/bin/magento <command name>

Deploy Static View Files Using CLI

For deployment of static view files, follow these steps:

  • Log in to your Magento 2 server as, or switch to, the Magento 2 file system owner.
  • Delete the content under <your Magento install dir>/pub/static.
  • Run the static view files deployment tool <your Magento install dir>/bin/magento setup:static-content:deploy.

Note: pub/static directory system must be writable when we enable merging static view file in the Magento admin.

For example, to deploy static view files for the pt_DE language, command must be like this:

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

After using this command, the following are some sample messages that display to indicate successful deployment:


Troubleshooting Deployment Tool of the Static View Files

After installation of Magento 2, if you try to run the static view files deployment tool and following error is displayed:

ERROR: You need to install the Magento application before running this utility.

To solve this error, follow these steps:

  1. Install Magento 2 using command line or setup wizard
  2. Login to Magento 2 system as file owner or switch ownership
  3. Delete contents of <your Magento 2 install dir>/pub/static
  4. And then run the static view files deployment tool I’ve shown above.


This is a short but useful tutorial through which you may easily deploy static view files. If you faced some issue in this process, feel free leave your comment below and I’ll get back to you.

Cloudways provides Magento store owners complete peace of mind by handling their server-level security issues. The Managed Magento Hosting Platform is built for launching servers on high-performance reliability. You can easily launch Google cloud, DigitalOcean, Vultr, and even Magento AWS hosting servers within minutes. Start your free trial today.


What is static content deploy in Magento 2?

The deployment command of static view files enables user to write static files to the Magento file system when it is set to the production mode.

What 3 are the static deployment strategies in Magento 2?

These are the 3 static deployment strategies in Magento 2

  • Standard: It’s a regular deployment process
  • Quick: Is a default and requires minimum deployment time when more than one locale are deployed.
  • Compact: Reduces the space taken by published view files.
Share your opinion in the comment section. COMMENT NOW

Share This Article

Customer Review at

“Great speed, features, knowledgebase, dashboard, UX and fast, expert support. Very happy!”

Stefan [Management Consultant]

Abdur Rahman

Abdur Rahman is the Magento whizz at Cloudways. He is growth ambitious, and aims to learn & share information about Ecommerce & Magento Development through practice and experimentation. He loves to travel and explore new ideas whenever he finds time. Get in touch with him at [email protected]


Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!


Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Unleash The Cloud.
Not Budgets.

For 4 Months +
Up To 30 Free Migrations

Cyber Week

Time Left In Offer
  • 0


  • 0


  • 0


  • 0


40% OFF

On All Plans