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.
- 
 1Realise 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 Pixie– Dominic Pixie2019年06月30日 21:42:09 +00:00Commented Jun 30, 2019 at 21:42
 
9 Answers 9
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.xmland find thevirtualType name="developerMaterialization"section. In that section you'll find an itemname="view_preprocessed"that needs to be modified or deleted. You can modify it by changing the contents fromMagento\Framework\App\View\Asset\MaterializationStrategy\SymlinktoMagento\Framework\App\View\Asset\MaterializationStrategy\CopyDelete the files under pub/static to get rid of any existing symlinks. You may want to be careful not to delete the
.htaccessfile.
This should solve your error with the symlink.
- 
 3Just deleting the pub/static folder worked for me.Adam Moss– Adam Moss2015年08月18日 16:08:16 +00:00Commented Aug 18, 2015 at 16:08
 - 
 4Deleting 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– Haijerome2015年09月11日 14:26:37 +00:00Commented Sep 11, 2015 at 14:26
 - 
 2Worked like a charm...!!!!Neeraj Garg– Neeraj Garg2015年11月25日 14:01:24 +00:00Commented Nov 25, 2015 at 14:01
 - 
 2This did not work for me, not even deleting the /pub/static folder. Any other ideas?goncalotomas– goncalotomas2016年02月09日 13:35:39 +00:00Commented Feb 9, 2016 at 13:35
 - 
 2Not working for me :-(Alaa M. Jaddou– Alaa M. Jaddou2017年08月16日 11:35:19 +00:00Commented Aug 16, 2017 at 11:35
 
I faced this problem and try to figure out. I agree with Chris O'Toole. I will add an extra step. My steps are,
- 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.
Delete all folders in pub/static. Don't delete .htaccess and other files.
Run XAMPP as an administrator. Run the command line as an administrator. Run
grunt exec:<theme name>.
You will see it is running fine.
Then you can run grunt less:<theme name>
Finally, you can run grunt watch
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.
- 
 Actually we don't need first step.cha– cha2016年08月19日 03:57:56 +00:00Commented Aug 19, 2016 at 3:57
 
Remember to update file permissions after Magento creates these new static files. They are not owned by www-data, so they will give 404.
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.
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/varnick.graziano– nick.graziano2017年09月12日 16:56:29 +00:00Commented Sep 12, 2017 at 16:56 
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.
Just deleted all files under pub/static/*. Magento will auto generate the static files for you when you load a page. 
You must run Xampp (apache, nginx) etc as Administrator to allow it to make Symlinks under Windows (tested with Windows 10).
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.