Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{{MEDIA_URL}} in source code #2816

Closed
ci2014 opened this Issue Dec 25, 2015 · 30 comments

Comments

@ci2014
Copy link

ci2014 commented Dec 25, 2015

Hello everyone,

after a fresh installation of Magento 2, i see this one in my source code:

How may I fix this?

Thank you very much.

@srenon

This comment has been minimized.

Copy link
Member

srenon commented Dec 26, 2015

@ci2014 ... on which page?

@ci2014

This comment has been minimized.

Copy link
Author

ci2014 commented Dec 28, 2015

@srenon on every page

<link  rel="stylesheet" type="text/css"  media="all" href="{{MEDIA_URL}}styles.css" />
@moderncodes

This comment has been minimized.

Copy link

moderncodes commented Dec 28, 2015

I having same issue. I have two Magento 2 installations, one installed with sample data for testing, and other one without it.
One installation that contains sample data, I have no issues with it.
But, another installation without sample data throws that 404 message
http://example.com/%7B%7BMEDIA_URL%7D%7Dstyles.css.

I think it have something to do with STORE > Configuration > [GENERAL] Design > HTML Head > Miscellaneous Scripts.

Any help is appreciated, thank you.

@Khaleel

This comment has been minimized.

Copy link

Khaleel commented Dec 30, 2015

Try running the Magento Minification tool in the admin panel. Then check your front end. Then if it works then turn off the minification tool as this will and should insert the correct URL inside the variable and all pages will have the new URL. Sounds loopy I know!

@moderncodes

This comment has been minimized.

Copy link

moderncodes commented Dec 30, 2015

Khaleel - Thank you for your suggestion.
If I understand this correctly, you are talking about STORES > Configuration > Advanced > Developer > CSS Settings > Minify CSS Files set to YES. I did that, saved it, and it did not fix the issues. I did that back and forward, it does no changes. I also flushed the cache.

I not sure how helpful this is, but in "Magento 2 (with) sample data" /pub/media/styles.css contains styling for the sample data.
"Magento 2 (without) sample data" doesn't have styles.css file in that folder at all. And for testing purposes even if i put styles.css in to that folder, I still get this annoying 404 message.
So, my question is what is this file for and how it is being generated

href="{{MEDIA_URL}}styles.css"

@Khaleel

This comment has been minimized.

Copy link

Khaleel commented Dec 31, 2015

Sorry it did not help. Strange one this. I have also updated to the latest M2 build and I am using (EE) and I am having issues with other plugins and customization. Sorry could not help

@toddwolaver

This comment has been minimized.

Copy link

toddwolaver commented Jan 4, 2016

I saw this as well. I found it was due to the use of sample data without the sample data modules installed.

It is a poor implementation in the sample data to swap out the MEDIA_URL, and only works if the correct module is installed. As a quick fix, I added the ThemeSampleData module to my composer.json. (i.e. under require... "magento/module-theme-sample-data": "*")

See: https://github.com/magento/magento2-sample-data/blob/develop/app/code/Magento/ThemeSampleData/Plugin/View/Page/Config.php

@tomislavsantek

This comment has been minimized.

Copy link
Collaborator

tomislavsantek commented Jan 27, 2016

@moderncodes,

as you have pointed out, in STORE > Configuration > [GENERAL] Design > HTML Head > Miscellaneous Scripts, there is

<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}styles.css" />

I've looked in the pub/media directory, and styles.css was there.

Although this is not an actual solution, I've bypassed the problem by editing the configuration to include correct css:

Just FYI, this problem occured to me on a Magento instance which was installed via composer. On my other instance installed via zip package, this error did not occur.

@Vinai

This comment has been minimized.

Copy link
Contributor

Vinai commented Feb 15, 2016

This issue still exists. Steps to reproduce:

$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition mage2ee
$ bin/magento setup:install --backend-frontname=admin --db-host=localhost --db-name=m2_training --db-user=m2_training --db-password="algla904.-were-eioio0=" --base-url=http://example.dev/ --use-rewrites=1 --admin-user=admin --admin-password=password123 --admin-email=admin@example.com --admin-firstname=Admin --admin-lastname=Admin --use-sample-data

Access the home page shows the sample data products without media.
So as @toddwolaver said, using the sample data without them being installed causes the issue.

Trying to fix this by running

$ bin/magento sampledata:deploy
$ bin/magento cache:flush
$ bin/magento setup:static-content:deploy

made no difference.
However, reinstalling (with the --cleanup-database switch) worked. So basically an install with the sample data already installed.
Can't test right now, but I assume running bin/magento setup:upgrade after bin/magento sampledata:deploy would also have done the trick.

So to summarize, to get a fully working installation currently the following order of steps is required:

$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition mage2ee
$ bin/magento sampledata:deploy
$ bin/magento setup:install --backend-frontname=admin --db-host=localhost --db-name=m2_training --db-user=m2_training --db-password="algla904.-were-eioio0=" --base-url=http://example.dev/ --use-rewrites=1 --admin-user=admin --admin-password=password123 --admin-email=admin@example.com --admin-firstname=Admin --admin-lastname=Admin --use-sample-data

Or, to fix the issue on an existing installation, I assume the following works:

$ bin/magento sampledata:deploy
$ bin/magento setup:upgrade

Suggestion: maybe a notice that setup:upgrade needs to be run should be added after sampledata:deploy?

@YugiHoang

This comment has been minimized.

Copy link

YugiHoang commented Feb 25, 2016

in my case i just need to enable module-theme-sample-data module, open file app/etc/config.php you add this line
'Magento_ThemeSampleData' => 1,

@slackerzz

This comment has been minimized.

Copy link
Member

slackerzz commented Jul 5, 2016

same problem after upgrading from 2.0.7 to 2.1 (EE), following @YugiHoang suggestion fixed it

maybe a real FIX is needed

@BaDos

This comment has been minimized.

Copy link
Contributor

BaDos commented Sep 16, 2016

Hi!

@Vinai Did you execute only this commands to reproducing?

$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition mage2ee
$ bin/magento setup:install --backend-frontname=admin --db-host=localhost --db-name=m2_training --db-user=m2_training --db-password="algla904.-were-eioio0=" --base-url=http://example.dev/ --use-rewrites=1 --admin-user=admin --admin-password=password123 --admin-email=admin@example.com --admin-firstname=Admin --admin-lastname=Admin --use-sample-data

Access the home page shows the sample data products without media.

How did you get sample products without installation of sample data packages?
What version of Magento were you using?

I reproduced it after I had set manually Magento_ThemeSampleData to 0.
Before it, I had installed Magento with Sample Data packages.

@Vinai

This comment has been minimized.

Copy link
Contributor

Vinai commented Sep 21, 2016

@BaDos Thanks for picking up the issue. I don't remember which version was current when I commented on the issue.
I think yes, those where the only two commands I had run. Right now, whenever I'm setting up a new project, I run bin/magento sampledata:deploy and setup:upgrade after the installation and it's fine.

@Sanfam

This comment has been minimized.

Copy link

Sanfam commented Oct 26, 2016

For those troubleshooting this issue on Magento 2.1 and ahead, it appears that this field was relocated to CONTENT > Design > Configuration > Edit > HTML Head, moved from its previous home under Store Configuration

@rbostan

This comment has been minimized.

Copy link

rbostan commented Dec 11, 2016

Quickfix :

  • after removing sample data module, set 'design/head/includes' value to NULL in 'core_config_data' table.
  • clean cache
@kirkmadera

This comment has been minimized.

Copy link

kirkmadera commented Jul 10, 2017

I ran into a similar issue, but different root cause. My page source was correctly rendering the {{MEDIA_URL}} directive, but my pub/media/styles.css file did not exist. I believe this happened because I ran setup:upgrade at a point in time where pub/media either didn't exist or wasn't writable. Running sampledata:deploy and setup:upgrade doesn't do anything at this point because the upgrade scripts have already run and won't run again. Even removing the sample data with sampledata:remove did not seem to reset the state.

To fix this, I needed to run sampledata:reset, then setup:upgrade, then cache:flush.

I confirmed that the setup:upgrade command is what actually deploys the pub/media/styles.css file into place by deleting the file and running the process again.

@magento-engcom-team

This comment has been minimized.

Copy link
Contributor

magento-engcom-team commented Sep 18, 2017

@ci2014 thank you for your report.
Please use the issue reporting guidelines to report an issue. Please, edit issue description and include the preconditions, the steps required to reproduce, the actual result, and the expected result.
Please, add the following information:

  • Preconditions: Magento version
  • Steps to reproduce
  • Expected result
  • Actual result
@qbo-tech

This comment has been minimized.

Copy link

qbo-tech commented Sep 26, 2017

Solution is quite simple:

Comment the HTML line within the backoffice (CONTENT > Design > Configuration > Edit > HTML Head):

<!--<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}styles.css" />-->

@magento-engcom-team

This comment has been minimized.

Copy link
Contributor

magento-engcom-team commented Oct 5, 2017

@ci2014 we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.

@gerrybarron

This comment has been minimized.

Copy link

gerrybarron commented Dec 11, 2017

Preconditions

  1. Magento 2.1.8 without sample data is installed.

Steps to reproduce

  1. I follow the guide for installing sample data : http://devdocs.magento.com/guides/v2.1/install-gde/install/cli/install-cli-sample-data-composer.html
  2. Run bin/magento sampledata:deploy
  3. After installing the sample data I ran the setup:upgrade and setup:di:compile
  4. I clean and flush the cache using this command cache:clean and cache:flush

Expected result

  1. Successful installation of Sample Data and without an error

Actual result

  1. I encountered an error
    GET http://192.168.0.55:8010/%7B%7BMEDIA_URL%7D%7Dstyles.css net::ERR_ABORTED (index):24
    image
@devamitbera

This comment has been minimized.

Copy link
Collaborator

devamitbera commented Dec 11, 2017

@gerrybarron using xampp?

If you using xampp then you may be facing this issue?it may happen for symbolic link

@gerrybarron

This comment has been minimized.

Copy link

gerrybarron commented Dec 11, 2017

nope im not using xampp I installed it on our staging server. OS is ubuntu server 16.04
I have extra test magento 2.1.10 with sample data but it works fine. I dont know why it has an error on magento 2.1.8

@devamitbera

This comment has been minimized.

Copy link
Collaborator

devamitbera commented Dec 11, 2017

have you done reindex. Maybe in design flat table's designs is not assigned?

@gerrybarron

This comment has been minimized.

Copy link

gerrybarron commented Dec 11, 2017

yup did that too. but nothing changes

@likemusic

This comment has been minimized.

Copy link
Contributor

likemusic commented Dec 14, 2017

I have the same issue after php bin/magento setup:di:compile. But php bin/magento setup:upgrade fix it (in my case).

@treestonemedia

This comment has been minimized.

Copy link

treestonemedia commented Jan 22, 2018

I just replaced
<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}styles.css" />
with
<link rel="stylesheet" type="text/css" media="all" href="http://mysite.com/pub/media/styles.css" />
In CONTENT > Design > Configuration > Edit > HTML Head

@adamsimonini

This comment has been minimized.

Copy link

adamsimonini commented Apr 10, 2018

@Vinai Solution worked! Thank you.

Initially, I ran into this issue after performing a Flush Cache from magento backened.
Running bin/magento sampledata:deploy and then bin/magento setup:upgrade fixed it.

Be aware, you need to setup your composer keys for this to work. Follow this link to learn more: http://devdocs.magento.com/guides/v2.0/install-gde/prereq/connect-auth.html

You'll have to find composer.json in your project root, Instructions on where to place these keys can be found here: (https://community.magento.com/t5/Magento-2-x-Version-Upgrades/Invalid-credentials-for-https-repo-magento-com-packages-json/td-p/22287/page/3)

@michael-sauerwald

This comment has been minimized.

Copy link

michael-sauerwald commented Jul 9, 2018

I just replaced <link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}styles.css" />
in CONTENT > Design > Configuration > Edit > HTML Head
with nothing - saved it - put it back - working...

magento-engcom-team pushed a commit that referenced this issue Jul 20, 2018

Merge pull request #2816 from magento-honey-badgers/MAGETWO-8709
[honey] MAGETWO-8709: [GITHUB] Child product image should be shown in Wishist if options are selected for configurable product #8168
@tigerofasia

This comment has been minimized.

Copy link

tigerofasia commented Sep 18, 2018

in my case i just need to enable module-theme-sample-data module, open file app/etc/config.php you add this line
'Magento_ThemeSampleData' => 1,

I wouldn't suggest this fix especially if you're installing with no sample data.

Setup version for module 'Magento_ThemeSampleData' is not specified

@kazimnoorani

This comment has been minimized.

Copy link

kazimnoorani commented Dec 5, 2018

Try removing from global scope. It should work then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.