Deploy A Theme In Magento 2: Static Content Deployment

Deploy A Theme In Magento 2: Static Content Deployment

Looking to enhance your online store with a new theme? Magento 2 deploy theme creates an engaging shopping experience and ensures your site looks professional.

This tutorial will cover the steps for deploying a theme and setting up the necessary files using the admin panel.

Key Takeaways

  • Steps to install a theme in Magento using Composer.
  • Insights into troubleshooting issues with static files for all languages.
  • Configure Magento theme installation.
  • Overview to use Magento extensions for the specified number of jobs.
  • Working procedure of identical caching using an SFTP client for the file manually.

Prerequisites Of Using Static View Files Deployment Command

prerequisites of using static view files deployment command in Magento 2

The static view files deployment command allows you to write static files to the Commerce file system. This gets done when the software is:

  • In default and developer modes, generating files on demand facilitates faster development and testing of changes.
  • In production mode, pre-generating all files enhances performance for end-users by reducing server load and response times.

Static view file refers to:

  • Static: These files can be cached for the site (e.g., images and CSS generated from LESS).
  • View: This pertains to the presentation layer (MVC).

Static view files are located in the <magento_root>/pub/static directory. This is done with some cached in the <magento_root>/var/view_preprocessed directory.

Static view files deployment varies by application mode:

  • Default and developer modes: Commerce generates them on demand and caches the rest for faster access.
  • Production mode: Static files are not generated or cached.

You must manually write these commands. Afterward, restrict permissions to limit vulnerabilities. Also, prevent accidental or malicious file overwriting.

Specific languages help create multi-lingual stores efficiently. Deploying specific themes is useful, such as A/B testing or gradual rollouts.

Note: In developer mode, when installing or enabling a new module, it may load new JavaScript, CSS, layouts, etc. Clean the old files to ensure all changes for the new module are applied. Refer to the Clean Static Files Cache documentation for further assistance.

3 Steps To Deploy Static Content Using View Files Deployment Tool

  1. Log in to the Commerce server as the file system owner or switch to that user.

  2. Delete the contents of the <magento_root>/pub/static directory.

Note: Remember not to delete the .htaccess file.

  1. Run the static view files deployment tool with the following command:

<magento_root>/bin/magento setup:static-content:deploy

Note: If you have enabled static view file merging in the Admin panel, ensure that the pub/static directory is writable.

Static Content Deploy Command Options

Option Description
[<languages>] Specify language code(s)
```[-t --theme ]```
[--exclude-theme <theme>] Exclude specific theme(s)
```[-l --language ]```
--exclude-language <lang>] Exclude specific language(s)
```[-a --area ]```
[--exclude-area <area>] Exclude specific area(s)
```-j --jobs ]```
[--no-javascript] Skip JavaScript deployment
[--no-css] Skip CSS deployment
[--no-less] Skip LESS deployment
--no-images] Skip image deployment
[--no-fonts] Skip font deployment
[--no-html] Skip HTML deployment
[--no-misc] Skip miscellaneous file deployment
[--no-html-minify] Skip HTML minification
[--no-parent] Skip parent theme deployment
```[-f --force] ```

Check the list of parameters and values for this command:

Option Description Required?
<languages> Specify ISO-639 language codes for static view files. Default: en_US. Use bin/magento info:language:list to see available codes. No
--language (-l) Generate files for the parent-specific languages. Default: all. Example: --language en_US --language es_ES No
--exclude-language Exclude specific language codes. Default: none. No
--theme <theme> Deploy for specific themes. Default: all. Example: --theme Magento/blank --theme Magento/luma No
--exclude-theme <theme> Exclude specific themes. Default: none. No
--area (-a) Generate files for specific areas (adminhtml/frontend). Default: all. No
--exclude-area Exclude specific areas. Default: none. No
--jobs (-j) Enable parallel processing. Default: 0 (no parallel processing). No
--symlink-locale Create symlinks for locales without customizations. No
--content-version Set custom version for static content. Useful for multi-node deployments. No
--no-javascript Skip JavaScript file deployment. No
--no-css Skip CSS file deployment. No
--no-less Skip LESS file deployment. No
--no-images Skip image file deployment. No
--no-fonts Skip font file deployment. No
--no-html Skip HTML file deployment. No
--no-misc Skip deployment of MD, JBF, CSV, JSON, TXT, HTC, and SWF files. No
--no-html-minify Skip HTML file minification. No
```-s <quick standard compact>```
--no-parent Skip parent theme file generation. Recommended for speed if not using parent theme. Available in Commerce 2.4.2+. No
--force (-f) Deploy in any mode (default is production mode only). No

Note: If you provide values for both <languages> and --languages, the <languages> parameter will take precedence.

How To Exclude The Current Theme & HTML Minification?

The following command deploys static content for the US English (en_US) language. It excludes the Luma theme provided with Commerce. Also, it does not minify HTML files:

bin/magento setup:static-content:deploy en_US --exclude-theme Magento/luma --no-html-minify

Check the sample output below:

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 deploys only CSS and LESS with 3 jobs. It uses a quick deployment strategy:

bin/magento setup:static-content:deploy -s standard --no-misc --no-html --no-fonts --no-images --no-less --no-css -j 4

How To Generate Static View Files?

The following command generates static view files without generating fonts for:

  • All languages
  • Frontend area
  • Commerce Luma theme only

bin/magento setup:static-content:deploy --area frontend --no-fonts --theme Magento/luma

Check the sample output below:

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

3 Steps To Write Static View Files Without Installing Commerce

You can execute the deployment process in a separate, non-production environment. This prevents building processes on sensitive production machines.

Follow these steps to do so:

  1. Run bin/magento app:config:dump to export the configuration from your production system.

  2. Copy the exported files to the non-production code base.

  3. Deploy static view files using the command:

bin/magento setup:static-content:deploy

Troubleshooting The Static View Files Directory Of Your Magento 2

Issue Symptom Solution
Magento 2 not installed "ERROR: You need to install the Commerce application before running this utility." 1. Install Magento 2 via the command line or setup wizard
2. Log in as file system owner
3. Clear <app_root>/pub/static (keep .htaccess)
4. Run bin/magento setup:static-content:deploy
Permission issues 403 errors in the pub folder for assets and templates 1. Check file permissions
2. Set directories to 0755 instead of 0770
3. Set files to 0644
4. Redeploy static content
Broken layout or styling Theme looks messed up after deployment 1. Clear Magento cache
2. Remove generated files
3. Redeploy static content
New module not working Static files not updated for new module 1. Clear static files cache
2. R unsetup:static-content:deploy for new files
Multi-language issues Static content not showing for all languages 1. Verify static content deployed for all store views
2. If in doubt, delete and redeploy static content
deployed_version.txt error "deployed_version.txt is not writable" 1. Remove symlinks in the pub/static directory
2. Run setup:static-content:deploy again

FAQs

1. How to install a Magento theme using Composer?

To install the theme, open your command line. Then, navigate to your Magento root directory. Run composer require <theme-vendor>/<theme-name>. Then, follow the installation guide to apply the theme in your Magento 2 store.

2. Can I use FileZilla to upload a theme to my Magento file system?

Yes, you can use FileZilla or any SFTP client to upload theme files manually. Connect to your server and upload the files to app/design/frontend/<Vendor>/<theme> in the root directory of your Magento.

3. How to check if a free theme is properly applied in my Magento 2 store?

Log in to your Magento admin panel. Go to Content > Design > Configuration. Check if your applied free Magento theme is selected for the correct store view. Then, clear the cache and verify the frontend appearance.

4. How can I create a child theme in Magento 2?

Set up a new theme directory in app/design/frontend/<Vendor>/<child-theme>. Then, create a theme.xml file specifying the parent theme. Next, add your custom files to override or extend files to the Magento store.

5. What is the best strategy for deploying static content in Magento 2.3.6 and later versions?

For Magento 2.3.6 and later, run php bin/magento setup:static-content:deploy -f. This quick strategy deploys static content more efficiently. You can also specify the number of jobs to run the custom version of static content.

6. How does theme compatibility differ between Magento 2.0, 2.2, and newer versions?

Theme compatibility across Magento versions (2.0, 2.2, and newer) can vary. It can especially occur when using Magento 2 extensions. When applying a single theme to different Magento installations, check the theme's compatibility with both your Magento version and installed extensions. The applied theme vendor may need to provide version-specific files or updates. Also, some theme settings that work in newer versions might not be available. Its default value is "0" in older versions. Thoroughly test your theme across all intended Magento versions. Check Magento forums to install theme for PHP and the file system manually.

CTA

Summary

Magento 2 deploy theme involves verifying requirements for activating the theme in the admin panel. It helps users to:

  • Ensure your Magento installation meets the necessary PHP version, database, and server specifications.
  • Remove contents of var/cache, var/page_cache, and var/view_preprocessed directories before deployment.
  • Execute php bin/magento setup:upgrade to register the new theme in the Magento system.
  • Use php bin/magento setup:static-content:deploy to generate and deploy static files.
  • Ensure proper read/write permissions for theme files and directories.
  • Switch to developer mode using php bin/magento deploy:mode:set developer for debugging during theme development.
  • Verify the theme's appearance and functionality across different devices and screen sizes.
  • Ensure the new theme doesn't conflict with installed extensions or custom modules.
  • Minify CSS/JS files and optimize images to improve page load times with the new theme.

Optimize your store's performance and user experience by deploying a custom theme with an optimized Magento server.

Dikshya Shaw
Dikshya Shaw
Technical Writer

Dikshya leverages her content marketing and writing proficiency to deliver fresh, insightful content. Her meticulous research ensures industry expertise and emerging trends within the Magento landscape.


Get the fastest Magento Hosting! Get Started