Images not showing after moving to LocalHost

2019-06-10 21:19发布

问题:

I recently switched to developing on local host rather than on my desktop. My website works fine on the desktop but now when i run it on local host none of my images work.

<a class="navbar-brand" href="#"><img src="logo.png" alt="logo" /></a>

That is how I'm including my images.

My localhost url is:

http://michaels-macbook-pro.local

Im getting the following error in the console:

[Error] Failed to load resource: the server responded with a status of 403 (Forbidden) (logo.png, line 0)

回答1:

It seems to be a permissions issue.

View your file permissions in the command line with:

ls -l

You want your image files to have read access for all users. Change your permissions to something like 644 for the folder and 711 for the images:

chmod 644 images
chmod 711 images/logo.png

For info about permissions see http://www.computerhope.com/unix/uchmod.htm

You probably have the issue because you are not the 'owner' of the files on your localhost (you can also view the owner of a file using ls -l). So if your image files have permissions of say, 700, then only the 'owner' has read access. Whereas on your desktop you will be the owner of the files so you have read permission.