Search code examples
htmlpermissionsraspberry-pifilepathlamp

Display picture from different dir(than index.html) on my website


I have set up a website on a LAMP(MP not important for now) stack on a raspberry pi. The website should show pictures which are located in a directory that differs from the dir in which the index.html is in. The index.html is on the same card the system is on whilst the pictures are on a usb thats connected to the server.

This is the structure: The structure for INDEX: /var/www/newdir1/newdir2/index.html The structure for PICTURE: /disk/newdir3/newdir4/picture.png

the filepath I use is: img src="../../../../disk/newdir3/newdir4/picture.png" alt="picture" id="someid" /

I tried adding or removing "../" even though I am certain the above mentioned path is correct.

I added the user I work with (lets say "demo") to the www-data group and changed permissions for the newdir2 and newdir4 to demo:www-data. But this seems also not to be the solution.

I am still convinced it has to do with permissions.

The two questions I have are: Is it really permission related? If so, how do I have to change the permissions to make it work? If not, what is it related to? (I know it is three questions but answered must be only two)

Greetings and thanks in advance,

Falk


Solution

  • Apache only allows one "root" directory (called DocumentRoot) per host. Yours is probably set to /var/www/ so attempting to access anything outside that is not going to work, regardless of permissions.

    The best way around this for your use case is probably to add an Alias to your Apache config. Something like this in your httpd.conf file:

    Alias "/img" "/disk/newdir3/newdir4"
    

    That way your html can just contain img src="/img/picture.png".

    The alternate is to symlink your pictures directory into your /var/www directory. See this section of the Apache manual for more information.