Images not appearing on page – Opening in new tab displays index.php

I have placed a few images in my index.php file and bizarrely it’s just not showing up, never had this issue before.

Here’s some code I used for displaying images

<img class="lozad" alt="Twitter" data-src="public/resources/images/twitter.svg" src="public/resources/images/twitter.svg" data-loaded="true">

<img src="public/resources/images/twitter.svg"  height="100" width="80"/>

<img src="resourcesimagesyoutube.svg" height="100" width="80"/>

My style.less works and it is in the same folder

<style type="text/less"><?php echo file_get_contents('resources/style.less'); ?></style>
<script src="https//i.stack.imgur.com//cdnjs.cloudflare.com/ajax/libs/less.js/3.9.0/less.min.js" ></script>

Broken images

I’ve written the following code to show me what’s in the directory.

foreach(glob(__DIR__.'/resources/images/*.*') as $file) {
    echo $file;
}
die;

this returns:

/var/www/html/public/resources/images/twitter.svg

/var/www/html/public/resources/images/youtube.svg

Additionally, I’m not sure if it’s important but I am using docker as well and here are some related files:

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Dockerfile

ARG APACHE_VERSION=""
FROM httpd:${APACHE_VERSION:+${APACHE_VERSION}-}alpine

RUN apk update; 
    apk upgrade;

# Copy apache vhost file to proxy php requests to php-fpm container
COPY demo.apache.conf /usr/local/apache2/conf/demo.apache.conf
RUN echo "Include /usr/local/apache2/conf/demo.apache.conf" 
    >> /usr/local/apache2/conf/httpd.conf

demo.apache.conf

ServerName localhost

LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so

<VirtualHost *:80>
    DocumentRoot "/var/www/html/public"
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE application/json
        AddOutputFilterByType DEFLATE application/vnd.api+json
    </IfModule>
    <IfModule mod_headers.c>
        Header always set Access-Control-Allow-Headers "authorization, content-type"
        Header always set Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE"
        Header always set Access-Control-Allow-Origin "*"
        Header always set Access-Control-Expose-Headers "authorization"
    </IfModule>
    <Directory "/var/www/html/public">
        <IfModule mod_rewrite.c>
            RewriteEngine On
            # Handle options requests...
            RewriteCond %{REQUEST_METHOD} OPTIONS
            RewriteRule ^ - [R=204,L]
            # Handle Authorization Header
            RewriteCond %{HTTP:Authorization} .
            RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
            # Handle Front Controller...
            RewriteRule ^ index.php [L]
        </IfModule>
    </Directory>
</VirtualHost>

nginx.conf

events {}
http {
    server {
        access_log /dev/stdout;
        error_log stderr;
        gzip        on;
        gzip_types  application/vnd.api+json;
        location / {
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, PATCH, DELETE' always;
            add_header 'Access-Control-Allow-Headers' 'authorization, content-type' always;
            add_header 'Access-Control-Expose-Headers' 'authorization' always;
            if ($request_method = 'OPTIONS') {
                return 204;
            }
            fastcgi_pass php:9000;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php;
        }
    }
}

docker-compose.yml

version: "3.2"
services:
    nginx:
      ports:
      - 80:80
      image: nginx:1.17
      volumes:
        - ./docker/nginx.conf:/etc/nginx/nginx.conf:ro

    php:
        image: php:7.4-fpm
        volumes:
          - .:/var/www/html
    database:
        image: mysql:5.7.26
        command: --explicit_defaults_for_timestamp
        volumes:
            - mysql-data:/var/lib/mysql
        environment:
            MYSQL_DATABASE: 'db'
            MYSQL_USER: 'user'
            MYSQL_PASSWORD: *********************
            MYSQL_ROOT_PASSWORD: *********************
volumes:
  mysql-data:

Source: StackOverflow