My laravel (v5.8) project works fine in localhost , but after I uploaded it to cPanel
all images and css and JS files in public html failed to load in the browser and show errors in browser console like :
"Failed to load our-approach.png:1 resource: the server responded with
a status of 404 ()"
"Failed to load resource: the main.css:1
server responded with a status of 500 ()"
While the framework itself loaded fine and show no errors.
I updated PHP to 7.4
and followed almost every youtube and StackOverflow thread and nothing worked.
index.php modified :
require __DIR__.'/../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
AppServiceProvider.php modified
public function register()
{
$this -> app -> bind('path.public', function()
{
return base_path('public_html');
});
}
My project structure in cPanel :
|– bin
|– cache
|– laravel (project files without the public folder)
|– app
|– bootstrap
|– config
.env
server.php
… and the rest of the files
|– etc
|– logs
|– mail
|– public_html
|– css
|– js
|– img
.htaccess
index.php
…rest of files
My htaccess file in public_html :
<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>
2
Answers
Apparently the problem was in the files permission , i set it to 755 for folders and 644 for files and everything worked like charm
You need changes in .htaccess file.
Add these lines
But please take a backup before doing changes in htaccess files