Laravel can't find my assets on production

Published 2 months ago by ramonpego

Hello, i have an application on production made on laravel, but all my assets on public paste, laravel can't find using {{asset()}} or {{url()}}.

My host is limited i can't use ssh, i cant install composer, i can't run composer dump-autoload etc.

My application does not work perfectly, i had to import using normal tags href="../../foo/bar.jpg"

But values from database doesn't work

What i can do to solve this. I read about its possible wrong because my htaccess it's wrong but i can't solve, here's my htaccess

Options -MultiViews -Indexes

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]

Cronix
Cronix
2 months ago (786,650 XP)

the url helpers use the APP_URL from .env to construct the url. It should be "http://yourhost.com/"

Is laravels /public dir set to be your servers DocumentRoot?

Where are your assets located?

But values from database doesn't work

Give an example of something coming from the db that isn't working?

ramonpego
<link rel="stylesheet" href="{{asset('css/framework/materialize.min.css')}}">"

does not work i had to put

<link rel="stylesheet" href="{{asset('public/css/framework/materialize.min.css')}}">

my document root is on www/ (in my case on host is /public_html)

jlrdw
jlrdw
2 months ago (251,930 XP)

You need to properly set up laravel where all the main files are above public_html.

Where of course a simple search here would show past replies with details on how to set up I myself have posted images and everything showing and I know Cronix has helped many in that regard.

Can you give us your full site URL?

ramonpego
jlrdw
jlrdw
2 months ago (251,930 XP)

I can read your environment file as example part of your app key contains

GK9rV

So as I suggested in my above post please stop what you're doing and set up everything correctly and then start troubleshooting other problems.

The way you are set up now is a major security flaw.

Furthermore you have debug is equal to True on production site that should be false so you really need to study how to setup laravel correctly.

On mobile now I will try to post some good links a little later.

Tray2
Tray2
2 months ago (109,970 XP)

I have my site on a shared host where I can't put my files in the proper place above the document root but I have a .htaccess that prevents any access to the except those in /public.

#Rewrite everything to subfolder
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public
Rewriterule ^(.*)$ public/ [L]

This one works for me.

ramonpego

I understand that I left my .env online. But if I can say that if without ssh access, without installing composer I can run my application normally, I also need to solve the problem of imports.

Cronix
Cronix
2 months ago (786,650 XP)

You have some work to do since you're using shared hosting (ick!) in order to set things up properly. The best thing is to not use shared hosting, and just make DocumentRoot the /public dir that laravel ships with. Then everything just works. So, you'll have to do a bunch of workarounds... As @jlrdw said, right now your site is totally insecure. You shouldn't be able to go to http://yourhost.com/.env and see your .env file with all of your passwords!!! Fix this asap!

https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e

In the guide where they refer to the "www" dir, it would be the "public_html" dir for your setup, since public_html is your DocumentRoot.

ramonpego

@Cronix I already did this, but I do not have SSH access to execute some commands. And also I do not agree on using shared hosts, but it is my client, since I convinced him to use new services on a private host. But those that already exist (there are 22 of them) are still using shared.

Cronix
Cronix
2 months ago (786,650 XP)

Sorry, I don't have any answers for you. I quit using shared hosting and apache many years ago.

Tray2
Tray2
2 months ago (109,970 XP)

Upload the .htaccess I provided it will redirect all calls to http://yourhost.com/* to http://yourhost.com/public/* thus securing your application a bit.

jlrdw
jlrdw
2 months ago (251,930 XP)

you can set things up correctly on a shared host. However on one shared host I put the images under a folder under public_html, which is usually just fine for images that aren't private. If it was a big time business application you would have a dedicated server anyway for example I do not think that FedEx uses shared hosting.

In other words a little Common Sense has to be used when it comes to assets and where you place as public is fine on a shared host.

If you need a very secure site that has images that are strictly private I would not use shared hosting I would look into a dedicated server.

ramonpego

@Tray2 I forgot to respond to you, it did not work. I'm thinking that is not the problem with the root folder

jlrdw
jlrdw
2 months ago (251,930 XP)

Please sign in or create an account to participate in this conversation.