m3thodm4n's avatar

Next Issue fonts and images arent visible

Hi Guys,

well my Laravel Project is running now on server. but it is only reachable over testprojekt/public url. if i just use /testprojekt i get

Forbidden You don't have permission to access /testprojekt/ on this server.

and also my fonts and my background image are not working if i use testprojekt/public

it says

Failed to load resource: the server responded with a status of 404 (Not Found)

the link is :

bla.it/public/images/betonboden.jpg

but it has to be:

bla.it/testprojekt/public/images/betonboden.jpg

anyone can help me to solve that?

Thx in advance

Tom

0 likes
21 replies
Cronix's avatar

For whatever webserver you are using, you need to make the /public dir of laravel be the DocumentRoot for the site. Right now, the testprojekt dir is the DocumentRoot. It needs to be /path/to/testprojekt/public

1 like
m3thodm4n's avatar

where i have to set that DocumentRoot? sry i didnt worked with laravel for some months. need to get in again. i just want a live demo of a project i did last year.

Cronix's avatar

I don't know. This has to do with setting up your webserver, whatever that is. Laravel really doesn't have to do with this part. We don't know anything about your server/hosting situation, only that you haven't set the DocumentRoot correctly.

m3thodm4n's avatar

im using a sftp server. no shared server hosting. so what i need to do is change something in .htaccess? thx jlrdw i googled a lot already but i dont get my problem. sorry for my bad description, my englisch isnt that good :(

Cronix's avatar

Maybe you're uploading your files through sftp, but that doesn't have anything to do with the web server, or how it's set up.

jlrdw's avatar

The link I added in one of my replies has a link in it to the proper way to set up shared hosting, use it or not that's your choice. If digital Ocean or something like that they actually have tutorials.

Make sure your capitalization is correct Linux is case sensitive.

1 like
m3thodm4n's avatar

ok, i changed my htaccess file:

DirectoryIndex index.php

RewriteEngine On
RewriteBase /testprojekt/

RewriteRule ^$ public/index.php [L]

RewriteRule ^((?!public/).*)$ public/ [L,NC]

but if i access now testprojekt/public i get Internal Server Error

when i just use /testprojekt i get

Forbidden You don't have permission to access /testprojekt/ on this server.

any suggestions?

jlrdw's avatar

You will never get this working correctly unless laravel is properly setup. public should not be in the url.

m3thodm4n's avatar

@JLRDW - can you maybe help me, to set it up? i really dont know, what i have to do

jlrdw's avatar
jlrdw
Best Answer
Level 75

First use this as a guide:

http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/

Second your folder structure would be like this:

https://i.imgur.com/Oo6k4Fp.jpg

Third your htaccess add the line:

    RewriteEngine On
    RewriteBase /laravel54/   //Change this line to your use case

A similar guide:

https://laravel-news.com/subfolder-install

Note in the guide:

FTP everything except your public folder into the back-end folder that you created (dj3core in my example)

FTP the contents of your public folder into the subdomain folder (dj3 in my example)

and

// require __DIR__.'/../bootstrap/autoload.php';
require __DIR__.'/../../dj3core/bootstrap/autoload.php';

and

// $app = require_once __DIR__.'/../bootstrap/app.php';
$app = require_once __DIR__.'/../../dj3core/bootstrap/app.php';

Use your names, and adjust as needed for laravel 5.8

If the guide is followed, this whole process only takes a few minutes.

=====================

Display an image use asset helper:

<img src="{{ asset('assets/upload/imgdogs') . '/' . $row->dogpic }}" alt="" class="image"></a>

Load basic resource:

<link href="{{ asset('assets/css/dog/style.css') }}" rel="stylesheet">

Load js

<script type="text/javascript" src="{{ asset('assets/js/jquery.js') }}"></script>

But use your folder names.

If using mix, follow documentation.

2 likes
m3thodm4n's avatar

thank you very much! i used the guide, and its working without /public now.

but i still have the problem with img and font.

in my app.css im using src: url("/fonts/tomatoes.ttf");

so its looking for /fonts/tomatoes.ttf

but i need /testprojekt/fonts/tomatoes.ttf

where to specify that url?

Thx in advance

jlrdw's avatar

Have you tried url("/testprojekt/fonts/tomatoes.ttf");

m3thodm4n's avatar

@JLRDW - i have it like that:

@font-face { font-family: Tomatoes; src: url("/fonts/tomatoes.ttf"); }

@font-face { font-family: Manigue; src: url("/fonts/manigue.ttf"); }

@font-face { font-family: Roboto; src: url("/fonts/Roboto-Regular.ttf"); }

@font-face { font-family: minimal; src: url("/fonts/minimal.otf"); }

@font-face { font-family: sugar; src: url("/fonts/Sugar.otf"); }

siangboon's avatar

@M3THODM4N - cut your "fonts" folder and paste into public folder.

/testprojectt/fonts => /testprojectt/public/fonts

add a dot "./fonts/tomatoes.ttf" if your app.css located at the same directory as the fonts folder, otherwise, play around with the parent path using "..".

1 like
m3thodm4n's avatar

Ok thank you very much guys. its solved :)

jlrdw's avatar

Glad you got it, that font thing was to to me, I usually just use available fonts.

Please or to participate in this conversation.