38

I have downloaded and installed Magento 2 from https://github.com/magento/magento2

But I am getting 404 error for scripts and cs located in http://localhost/magento2/pub/static/

I have checked, Apache rewrite engine is on. But still, css and js file are not loading.

When I try to access a file directly from the browser it gives following exception.

Cannot create a symlink for "D:/xampp/htdocs/magento2/lib/web/mage/calendar.css" and place it to "D:/xampp/htdocs/magento2/pub/static/frontend/Magento/blank/en_US/mage/calendar.css" Warning!symlink(): Cannot create symlink, error code(1314)
#0 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\Filesystem\Directory\Write.php(155): Magento\Framework\Filesystem\Driver\File->symlink('D:/xampp/htdocs...', 'D:/xampp/htdocs...', Object(Magento\Framework\Filesystem\Driver\File))
#1 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink.php(30): Magento\Framework\Filesystem\Directory\Write->createSymlink('lib/web/mage/ca...', 'frontend/Magent...', Object(Magento\Framework\Filesystem\Directory\Write))
#2 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\App\View\Asset\Publisher.php(65): Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink->publishFile(Object(Magento\Framework\Filesystem\Directory\Write), Object(Magento\Framework\Filesystem\Directory\Write), 'lib/web/mage/ca...', 'frontend/Magent...')
#3 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\App\View\Asset\Publisher.php(49): Magento\Framework\App\View\Asset\Publisher->publishAsset(Object(Magento\Framework\View\Asset\File))
#4 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\App\StaticResource.php(118): Magento\Framework\App\View\Asset\Publisher->publish(Object(Magento\Framework\View\Asset\File))
#5 D:\xampp\htdocs\magento2\lib\internal\Magento\Framework\App\Bootstrap.php(245): Magento\Framework\App\StaticResource->launch()
#6 D:\xampp\htdocs\magento2\pub\static.php(13): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\StaticResource))
#7 {main}

My operating system is Windows 7 and I am running xampp server.

  • Realise this was asked in 2015 but in case others still look at this post you should not be getting magento from git. You only do this if you are submitting a pull request. Magento should be downloaded from download section of site or installed via composer. – Dominic Xigen Jun 30 at 21:42
82

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.

  1. 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

  2. Delete the files under pub/static to get rid of any existing symlinks. You may want to be careful not to delete the .htaccess file.

This should solve your error with the symlink.

  • 2
    Just deleting the pub/static folder worked for me. – Adam Moss Aug 18 '15 at 16:08
  • 4
    Deleting the pub/static contents are not enough in my case. I had to change the Symlink to Copy as mentioned in the answer above.to get the skin loading fine ! – Haijerome Sep 11 '15 at 14:26
  • 2
    Worked like a charm...!!!! – Neeraj Garg Nov 25 '15 at 14:01
  • 1
    This did not work for me, not even deleting the /pub/static folder. Any other ideas? – goncalotomas Feb 9 '16 at 13:35
  • 1
    Not working for me :-( – Alaa M. Jaddou Aug 16 '17 at 11:35
6

I faced this problem and try to figure out. I agree with Chris O'Toole. I will add extra step. My steps are,

  1. Open app/etc/di.xml and search Symlink. Check it is in following section.
<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\Copy</item>
                        <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>
                    </argument>
                </arguments>
            </virtualType>

Replace Symlink with Copy word. Save.

  1. Delete all folders in pub/static. Don't delete .htaccess and other files.

  2. Run xampp as administrator. Run command line as administrator. Run grunt exec:<theme name>.

enter image description here

You will see it is running fine.

Then you can run grunt less:<theme name>

enter image description here

Finally you can run grunt watch

enter image description here

When you do any changes in less files(_theme.less or _extend.less) it will automatically create style-l and style-m css files in pub/static folder.

I'm running magento 2.1 in windows 10.

  • Actually we don't need first step. – cha Aug 19 '16 at 3:57
2

Remember to update file permissions after Magento creates these new static files. They are not owned by www-data, so they will give 404.

1

In my case it was not because my app/etc/di.xml had Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink as mentioned by @Chrish. It was because one of my module had script error in my .phtml file. I would recommend to check your code in .phtml file. In my case it was solved by making correction in my script file initialize.phtml.

0

I found important to use the correct permission for the apache with mod_php for the pub/static and var/ folders. From the Alan Storm article http://alanstorm.com/magento_2_adding_frontend_files_to_your_module

find /path/to/magento2/pub/static -exec chmod 777 '{}' +
find /path/to/magento2/var/ -exec chmod 777 '{}' + 

You should execute that in server terminal. That fixed me 404 error for the scripts and images.

p.s. But that's for the Linux.

  • You could also chmod -R 777 /path/to/magento2/pub/static /path/to/magento2/var – nick.graziano Sep 12 '17 at 16:56
0

I think the proper way for doing this is from command line: cd to your magento directory and run the following command:

php bin/magento setup:static-content:deploy

Empty var/cache directory and check.

0

Just deleted all files under pub/static/*. Magento will auto generate the static files for you when you load a page.

protected by Community May 19 '16 at 9:20

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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