40

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.

1
  • 1
    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. Commented Jun 30, 2019 at 21:42

9 Answers 9

91

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.

10
  • 3
    Just deleting the pub/static folder worked for me.
    – Adam Moss
    Commented Aug 18, 2015 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
    Commented Sep 11, 2015 at 14:26
  • 2
    Worked like a charm...!!!! Commented Nov 25, 2015 at 14:01
  • 2
    This did not work for me, not even deleting the /pub/static folder. Any other ideas? Commented Feb 9, 2016 at 13:35
  • 2
    Not working for me :-( Commented Aug 16, 2017 at 11:35
8

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

  1. Open app/etc/di.xml and search Symlink. Check it is in the 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 an administrator. Run the command line as an 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 fewer 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.

1
  • Actually we don't need first step.
    – cha
    Commented Aug 19, 2016 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.

1
  • You could also chmod -R 777 /path/to/magento2/pub/static /path/to/magento2/var Commented Sep 12, 2017 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.

0

You must run Xampp (apache, nginx) etc as Administrator to allow it to make Symlinks under Windows (tested with Windows 10).

0

If you are working on local with XAMPP, First check if your Static and media URL is correct or not.

like: <base_url>/pub/static/frontend/Magento/luma/en_US/css/print.css

If pub directory is missing, then manually add update the base secure and unsecure URL in database

Go to magento 2 database which you recently created and find the table core_config_data

In this table you need to insert/update below rows

Path => Value

a) web/secure/base_url => https://xyz.abc/**pub/**

b) web/unsecure/base_url => https://xyz.abc/**pub/**


if pub directory is there in the CSS and Media URL then

add/update the below row:

Path => Value

a) dev/static/sign => 0

It will resolve your issue.

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