0

I got a small PHP website with some js and wanted to run it with docker. Because it's a gallery, it has images in a subfolder. The main index.php runs fine, except no images are found. I looked inside the folder with the normal docker CLI and an 'echo ls ...', but everything is in there. If I go to localhost:8080/images, I get the Error 403 (consol print bellow).

The Images are loaded via php, which generates paths like: '/var/www/html/images/2555-P160-05.jpg'. Are they maybe wrong?


Solution: I got the wrong paths. I'm now getting the pathname via

$link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 
                "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .  
                $_SERVER['REQUEST_URI']; 

instead of getcwd(). The comments reminded me to check the images directly and not the entire folder. I also edited the Dockerfile and removed the permission changes.


OS: Ubuntu 19.04 Docker -v: 19.03.6

Here are my latest edits:

docker-compose.yml:

version:  '3'
services:
  photography-website:
    build: 
      context: ./
      dockerfile: ./
    ports:
      - 8080:80
    volumes:
      - .:/var/www/html

Dockerfile:

FROM php:7.4.4-apache

Error 403:

172.18.0.1 - - [06/Apr/2020:23:19:48 +0000] "GET /images/ HTTP/1.1" 403 493 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0"

Thanks for reading.

MarkovIV
  • 11
  • 3
  • What OS are you using? And it is Docker tools or Native Docker? In windows, Docker Tools works only inside your user directory (%userprofile%) ... in Native Docker for WIndows 10... you need to mount the drive you are using... could be that the problem? Try to work inside your %userprofile% dir, for example, inside Documents – paulmartimx Apr 06 '20 at 23:45
  • 1
    1) Your `chown` syntax is incorrect. 2) 403 when viewing a *directory* (`GET /images/`) is possibly a separate problem to viewing the images individually, eg maybe due to `DirectorIndex` configuration [see](https://stackoverflow.com/questions/18447454/apache-giving-403-forbidden-errors) the many [duplicates](https://stackoverflow.com/questions/6959189/apache-virtualhost-403-forbidden) here for [some](https://stackoverflow.com/questions/21394871/apache-gives-me-403-error-when-trying-to-access-on-server) suggestions. – Don't Panic Apr 07 '20 at 00:03
  • 1
    3) The web server can read your `index.php` without changing its permissions, so changing perms on images is likely not necessary? You didn't actually describe what happens when you try to view an individual image? – Don't Panic Apr 07 '20 at 00:05

1 Answers1

1

Paths should be localhost:8080/images/[image].jpg not var/www/html/images/[image].jpg.

More info in my post above.

MarkovIV
  • 11
  • 3