Question

I have installed Magento ver. 2.1.2, Admin menu is not working and some of the front end styles are not coming properly.

After I replace (app/etc/di.xml) as in the below code, everything is working fine. I have been facing this issue with all Magento 2 versions.

Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink

To

Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

I got followed Solution for Inactive Admin Links in Magento 2 (Windows)

Can anybody tell me

  1. Why the class replacement is necessary ?
  2. Is this an internal bug ?
  3. Am I missing something ?
Was it helpful?

Solution

Officially Magento 2, as well as many other web application, is supposed to be installed and run in the native environment. The native environment means LAMP or LEMP + Unix compatible filesystem. On Windows you can easily have LAMP or LEMP but not fully Unix compatible filesystem (sure, you can try to emulate it in different ways but the emulation does not guarantee the system will work properly).

You need to change the Symlink materialisation strategy to the Copy statagy (Magento 2 using both for different cases) because your XAMPP installation does not support UNIX symlinks properly. The symlinks in Windows (and XAMPP as well) are not the same as in the Unix based system. That's why you might have troubles using symlinks in Windows system.

No, it's not a bug since Magento is being developed and tested using the native (Unix) environment. Obviously, there's no reason to make the system compatible with different kinds of emulations. So, in order to be sure your system works correctly, it's strongly recommended to perform all development processes in the native environment as well (until you are going to run Magento 2 using Windows in production). It's achievable by using VirtualBox, Vagrant, Docker or other tools that allow you to run your web applications in Unix environment.

OTHER TIPS

When not in production mode Magento 2 will try to create symlinks for some static resources. You can change that behavior by doing the following.

Open up app/etc/di.xml and find the virtualType name="developerMaterialization" section. In that section you'll find an item name="view_preprocessed" that needs to be modified or deleted. You can modify it by changing the contents from

Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink

To

Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

Now if you look at Location
Your oot/vendor/magento/framework/App/View/Asset/MaterializationStrategy/

You will see both file and there is minor differnce here in function

public function isSupported(Asset\LocalInterface $asset)

Symlink.php contain this code

 public function isSupported(Asset\LocalInterface $asset)
    {
        $sourceParts = explode('/', $asset->getSourceFile());
        if (in_array(DirectoryList::TMP_MATERIALIZATION_DIR, $sourceParts)) {
            return false;
        }

        return true;
    }

And Copy.php contain this code for same function

public function isSupported(Asset\LocalInterface $asset)
        {
            return true;
        }

You can see here isSupported from copy.php is just passing value true see this comment above function @SuppressWarnings(PHPMD.UnusedFormalParameter) You can find detail here

so if you cahnge Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink to Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

so isSupported function will always return true.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top