1

I have recently installed symfony 3 on a fresh Ubuntu server, I was previously using WAMP to run my symfony website but now I have migrated.

Everything is up and running except on one of my pages I have some .svg icons to show the weather. These icons are getting a 404 error.

I have made sure they are in the correct location and I havent changed any of the html that links to them from the windows version which works fine.

They are located in web>icons>weather

My img tag <img src="icons/weather/{{ item.icon }}.svg" /> item.icon is using twig to grab from my weather rss feed.

That outputs GET http://192.168.0.53/icons/weather/cloud.svg 404 (Not Found) in inspect and I cannot access it by going to that url manually.

Is there a .htaccess problem which causes my images to not be located correctly?

3 Answers 3

1

The /icons/ path is used by Apache's mod_autoindex and defined globally at /etc/apache2/mods-available/alias.conf or similar normal location.

So yes, you can just choose a different path name.

It is also possible to modify the conf files if desired.

0

I'm not sure if something like this might work:

<img src="{{ asset('icons/weather/'.{{ item.icon }}.'.svg') }}" />

Can you try it! You might need to modify slightly.

5
  • That gives me a 500 error. Which is basically a php error. I messed around with the syntax which didnt work and then i did <img src="{{ asset('icons/weather/cloud.svg') }}" /> which shows <img src="/icons/weather/cloud.svg"> in inspect but i still get my 404 error. :/
    – GiantJelly
    Commented Aug 3, 2016 at 11:08
  • And the icons folder is it directly under your web root folder? I'm thinking you get the 404 error because of the path, which probably should be icons/weather/cloud.svg. Try entering that URL directly in your browser to see that you can actually grab the file. If you don't have access to a browser, try curl or wget commands (from command line). You need to understand why the 404 error - because that also could be a permissions error (it's possible).
    – Alvin Bunk
    Commented Aug 3, 2016 at 14:40
  • I have tried searching the url {address}/icons/weather/cloud.svg on my ubuntu server and i get a "Not found" page. I then search the exact same thing on my windows server and it loads the .svg to me. Ive ran chmod across the whole www folder to rule out permissions. I still have no idea what this could be, Could symfony use a folder called "icons" and get confused or something? The icons are at www/web/icons/weather/cloud.svg
    – GiantJelly
    Commented Aug 6, 2016 at 10:34
  • Is "www" your Symfony project name? If so, that's probably the problem. The "web" folder under that folder is the one you need to use as the web folder config on your server. If it is ubuntu, it is probably "/var/www/html/www/web" that you would specify in your Apache DocumentRoot directive.
    – Alvin Bunk
    Commented Aug 7, 2016 at 0:12
  • Hey Alvin. Its resolved now as you can see in my answer below. The document root is /var/www/project/web i removed the html directory form document root as I wanted a clearer directory list. Thank you for all your help
    – GiantJelly
    Commented Aug 8, 2016 at 11:04
-1

Alright, I found the answer.

I had a thought (like the one in my comment) that Symfony might be looking for/use a folder named "icons" in the web folder in its own way.

Whether this is the case or not I don't know but I moved the icons into a vendor folder. The address is now vendor/icons/weather/cloud.svg and IT WORKS!

So I guess what we can learn from this is either its a stupid error from me which I still don't know about or you can't use a folder called "icons" in the web folder.

Thanks for you help Alvin

1
  • I'm having exactly the same problem today with Symfony 6.3 under Apache. But this needs a better answer. It would seem to be specific to the configuration somewhere. Commented Oct 12, 2023 at 16:25

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