8

A while ago when I was working on a project with Magento 2, I noticed that my CSS and JavaScript files in pub/static of my theme were actually symbolic links to the actual files. This was also when I ran a setup:static-content:deploy action from the shell.

However, I recently migrated to a new system and checked out the code and the database of the project, but now when I deploy my static content, they are copies rather than Symbolic links.

Is something changed? Or am I missing some configuration setting here? It's not very productive to have to re-compile the static content every time I make a change to the JS or CSS.

I'm using Magento 2.0.6

2
  • Is your store set to developer mode?
    – Ryan Hoerr
    May 23, 2016 at 17:25
  • Yes, my store is set to developer mode. I also tried switching to production, delete the pub/static-folder, and re-enable developer mode, but without success. All files are copied instead of symlinked. May 25, 2016 at 9:28

2 Answers 2

12

Most likely you deleted all of your files in pub folder at some point in past, including:

  1. /pub/static.php
  2. /pub/static/.htaccess

When static file that you are looking for is not found, it redirects request to one folder above to static.php file, which initiates the fallback mechanism and pulls down that file as a symlink.

To resolve the issue copy down fresh copy of Magento 2.x that you are running and copy over those files to your pub folder.

11

Open your di.xml (app/etc/di.xml) and check around line 580 you should find something like this (I am using 2.0.6 and mode is set to the developer): As you can see view_preproccessed are symlinked and the default is set to copy.

<virtualType name="developerMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory">
    <arguments>
        <argument name="strategiesList" xsi:type="array">
            <item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>
            <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
        </argument>
    </arguments>
</virtualType>

Also, take a look here Magento 2 404 error for scripts and css especially the answer from Chris O'Toole.

1
  • Actually I had the same problem After my hosting company migrated my hosting account to a new server. I forced them to fix the issue based on the fact that it used to work before the migration. So they did the exact same change you did right now. My question is Is there any drawback to doing this? What will I have to keep in Mind in the future? Will I be able to update Magento 2 after this? Thanks!
    – rawraj
    Mar 18, 2021 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.