Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Jle's avatar
Level 1

Assets are not loading

Hello, I've created a website in Laravel 8 and I have a problem when it comes to putting it into production. I'm a beginner in Laravel and this is the first site that comes out of my localhost. As I'm a layman, I'll try to explain the situation as best I can. I use a shared host where I need to serve my site from a subdirectory and I have no choice about that. It can only be accessed via SFTP. When I put the URL into the browser, it returns 404 Not Found nginx. So I have to add the subdirectory to the url in order to access it. Example: www.example.com/example. When I do that, I see a 404 error screen, but now with a style that tells me I've reached the site. I've made a change to the RouteServiceProvider to add the subdirectory as a prefix to my web routes, so I can finally access the login page, but without my CSS, JS or images having been loaded. The DevTools console gives me a 404 error for each, while the script and link tags in app.blade.php give me net::ERR_ABORTED 404 (Not Found). To solve this problem, I've tried checking asset permissions, changing ASSET_URL in .env, I've tried removing the helper asset from my app.blade.php and trying to put the path in directly, but none of this has worked. I've tried changing things in htaccess or the location of folders on the server, but also to no avail. I don't have access to anything above the subdirectory where my files are. Can anyone help me?

0 likes
11 replies
MohamedTammam's avatar

Delete the public_html directory in you shared hosting. Then create a shortcut (link) with the same name shared_hosting that points to your project public directory.

If the shared hosting isn't allowing shortcuts (links), then move the public directory content to public_html directory and change the index.php content to make paths points to right directory.

Search in YouTube about (Deploy Laravel application on shared hosting) and you will find a lot of tutorials.

Jle's avatar
Level 1

@MohamedTammam

Thank you for replying.

I had already left the contents of my public folder at the same level as the project and updated the paths within the index.php file accordingly. This allowed me to access the views of the project, but not my css or js to load...

Jle's avatar
Level 1

@MohamedTammam

Is it possible that some server configuration could be preventing my application from finding my assets or could the problem only be internal to my application?

MohamedTammam's avatar

@Jle Move you assets build to public (or public_html) folder. And delete public/hot file if you have it.

MohamedTammam's avatar

@Jle

This allowed me to access the views of the project, but not my css or js to load

What's the actual behavior? Is it 404? or files not built, or what?

Jle's avatar
Level 1

@MohamedTammam

For asset('js/app.js') and asset('css/app.css') in my app.blade.php it returns net::ERR_ABORTED 404 (Not Found). For images, only 404 not found is returned.

martinbean's avatar

@jle Why are you trying to deploy Laravel to a subdirectory, instead of just the root domain? If you’re a beginning, then you’re just making the step of deployment more difficult for yourself.

I’m also confused as to why you have a Laravel 8.x application if this is your first app? You should have used the latest version possible (which is 11.x as of writing). Laravel 8.0 was released in September 2020 and stopped receiving security updates in January 2023, more than 18 months ago, so should now be considered vulnerable and a security liability for you and your host.

Jle's avatar
Level 1

@martinbean Doing this in a subdirectory was imposed on me by the server managers. The Laravel version was due to the php version.

martinbean's avatar

@Jle Laravel 8.x requires either PHP 7.3 or PHP 8.0 (https://github.com/laravel/laravel/blob/8.x/composer.json#L8).

Again, both of these PHP versions are end of life (no longer receiving security updates) and have been since for months now: https://www.php.net/supported-versions.php

I’m sorry, but your server managers need to pull their finger out instead of forcing you to use long out of date software. You’re just creating vulnerabilities for your workplace and its servers by doing so.

I also fail to see why you have server managers in the first place if you’re using shared hosting. Usually updating PHP is just picking a version in cPanel or similar. So again, sounds like your “server managers” are just being lazy.

1 like
jlrdw's avatar

@Jle Sounds as though you could tell the main boss why do we have server managers since they don't do nothing. And like mentioned above, just use the correct php version yourself.

Server managers for sháred hosting at a company. And I thought I had heard everything.

But just my thoughts on this.

1 like

Please or to participate in this conversation.