Chapters Close

Symlinks in Magento 2

In this post, I will be guiding you about symlink in Magento 2.

A symlink or a Symbolic Link is simply enough a shortcut to another file. It is a file that points to another file.

I have attached the below two images for identifying symlinks.

Symlinks are generated in the pub static folder of Magento 2 in developer mode.

Symlinks are generated in the pub/static folder of Magento 2 in developer mode.

Common issues faced by developers when working with Knockout.js

In the development stage, when you are working with JS, KnockoutJS js and Knockout templates, the developer faces below issues

  • The changes in Knockout.js and knockout templates are not affecting on frontend when the page loads.
  • The developer has to delete the pub static folder or run the static content deploy command every time when changes in the JS and the knockout template file.

If you are facing this kind of issue in development, please verify the steps below.

  1. Is the developer mode enabled?
  2. When doing development, open the Inspect Element in the browser and in the network tab, and select the Disable cache checkbox.

1. Is the developer mode enabled?

  • Open the SSH Console and go to the root directory of Magento 2 and run the command below.
bin/magento deploy:mode:show
  • If it is not a developer mode, then run the below command to enable developer mode.
bin/magento deploy:mode:set developer

In development mode, symlinks are generated automatically when the page loads.

If you can’t see symlinks in the pub static folder even after developer mode is enabled. There might be the following reasons.

Notes: When we run the static content deploy command in developer mode, it generates copies instead of symlinks in the pub static folder. So we have to remove that file every time when do development because symlinks are not created.

Originally, there was no need to run the static content deploy command in developer mode. Because on page load, it automatically creates symlinks.

No,w if copies are generated in the pub static folder, perform below steps to generate symlinks.

  • Remove pub static frontend and adminhtml folder(Don’t delete .htaccess file)
rm -rf pub/static/frontend/
rm -rf pub/static/adminhtml/

WeareJH / m2-module-symlink-assets

I hope this comprehensive post was helpful. Please leave your comments below, and don’t hesitate to reach out if you require assistance with customizing your Magento store

FAQs

What are symlinks used for?


Symlinks are used to redirect to a different file or folder on your device. Symlink stands for symbolic link which is used in LINUX or UNIX. There are two types of symlinks. Soft links work like shortcuts to a file and directly point to it. Hard links direct you to the file storage.

Is symlink secure?


No, symlinks aren’t secure as they can be manipulated to expose data. Symlinks are prone to attacks that can steal data, change permissions, and corrupt files from unwarranted access. These breaches can be controlled by assigning “create symbolic links” only to trusted admins.

What are the advantages of using a symlink?


The advantages of using symlinks are that they can link to both directories and across file systems. They are preferred over hard links as they create links at a namespace level. You can use symlinks to point to any files even if they differ in filesystem, permissions, configurations, and other parameters.

Can you symlink a directory?


Yes, you can symlink a directory. The process is similar to creating a symlink for a file. To create a symlink to a directory, choose a directory to create the link and select a link name. Then, run the command ln -s <target_directory> <link_name>

Speak your Mind

Post a Comment

Got a question? Have a feedback? Please feel free to leave your ideas, opinions, and questions in the comments section of our post! ❤️

* This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Grow your online business like 3,838 subscribers

    * This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
    envelope

    Thank You!

    We are reviewing your submission, and will be in touch shortly.