Laravel at Shared Hosting net::ERR_ABORTED 404 (Not Found) - laravel

After I successfully installed composer, npm and Tailwind in shared hosting, I am encountering this problem.
The page is being displayed but without css and js showing the error:
GET http://mydomain.preview-domain.com/css/app.css net::ERR_ABORTED 404 (Not Found)
GET http://mydomain.preview-domain.com/js/app.js net::ERR_ABORTED 404 (Not Found)
but in my app.blade.php I'm importing:
<head>
...
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
...
</head>
<body>
...
<script src="{{ asset('js/app.js') }}" defer></script>
...
</body>
It seems like the path to the public folder is wrong.
I would appreciate any help. I know that using Laravel in Shared Hosting is not a very good idea.
[NOTE]: I created a symbolic link from the website's public folder to the index.php of Laravel. This is how index.php runs.

Related

Laravel failed to load resource, the resource serve r responded with a status of 404

I downloaded my laravel project from live serve (shared hosting) to local hosting because I want to make some changed in the code. I added a new index.php file to the public folder and run composer update and composer install commands and managed to run the project on local server (I use Laragon server on windwos). However, the project can not upload the resource. The resource are located in the public floder and linked using {{asset}} function and {{assetversion}} methods. Honestly, I do not know about the use of version. The code in like that
<link rel="stylesheet" href="{{ asset('public/frontend/infixlmstheme') }}/css/fontawesome.css{{assetVersion()}} ">
<link rel="stylesheet" href="{{asset('public/backend/css/themify-icons.css')}}{{assetVersion()}}"/>
<link rel="stylesheet" href="{{ asset('public/frontend/infixlmstheme') }}/css/flaticon.css{{assetVersion()}}">
<link rel="stylesheet" href="{{ asset('public/frontend/infixlmstheme') }}/css/nice-select.css{{assetVersion()}}">
<link rel="stylesheet" href="{{ asset('public/frontend/infixlmstheme') }}/css/notification.css{{assetVersion()}}">
<link rel="stylesheet" href="{{ asset('public/frontend/infixlmstheme/css/mega_menu.css') }}">
When I check the path in chrom dev tools, the link points to the right folder (except the version in not in the file name). such as
<link rel="stylesheet" href="http://127.0.0.1:8000/public/frontend/infixlmstheme/css/fontawesome.css?v=5.0.0 ">
and the folder in with same path starting from public.
However, the recourse is not connected and the error massage is shown in the attached image fro chrom dev tools.
I appreciate you help guys and thank you in advance for your time and expertise.
I have assempution the error is from {{assetversion}} but I could not find the version in the file name. I do not know a lot about the frontend how the asset version work.

Public folder not working with Mix and Asset Laravel Helpers Ubuntu 21.04

I am in the middle of creating a Laravel website, and have tested everything locally up to now and it has been working fine. I have set up a web server on a vps and have added the website to test that it the server is working. Everything in my public folder is not being picked up by the Laravel helper functions such as 'Mix' and 'Asset'.
This is how I would usually reference files locally, but for it to work on the server, I have to type the file path.
<!-- Styles -->
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
{{-- <link rel="stylesheet" href="/public/css/app.css"> --}}
<!-- Scripts -->
<script src="{{ asset('js/navController.js') }}" defer></script>
{{-- <script src="/public/js/navController.js" defer></script> --}}
When I open up the console in my browser, it shows this error code.
GET http://domain.name/js/navController.js net::ERR_ABORTED 404 (Not Found)
GET http://domain.name/css/app.css net::ERR_ABORTED 404 (Not Found)
Using
Ubuntu Server 21.04
Laravel 8
LAMP (MySql)
If /public appears in your URI, your site is misconfigured. The public/ dir should be the DocumentRoot, so that / in your browser shows the public/index.php file.
Here's an example of how to configure your document root in both Apache and nginx.
Lastly, a warning - serving your site out of the project root (as you are now) instead of public/ is a security risk and you shouldn't do that.

console showing script loading failed in laravel

problem(showing in console)
GEThttp://127.0.0.1:8000/public/vuexy-assets/vendors/css/vendors.min.css
[HTTP/1.0 404 Not Found 580ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/css/bootstrap-extended.css
[HTTP/1.0 404 Not Found 1153ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/css/bootstrap.css
[HTTP/1.0 404 Not Found 885ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/css/core/menu/menu-types/vertical-menu.css
[HTTP/1.0 404 Not Found 2443ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/css/themes/semi-dark-layout.css
[HTTP/1.0 404 Not Found 2158ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/css/themes/dark-layout.css
[HTTP/1.0 404 Not Found 1917ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/css/components.css
[HTTP/1.0 404 Not Found 1664ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/css/colors.css
[HTTP/1.0 404 Not Found 1405ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/css/core/colors/palette-gradient.css
[HTTP/1.0 404 Not Found 2671ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/css/pages/authentication.css
[HTTP/1.0 404 Not Found 3185ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets-sep/assets/css/style.css
[HTTP/1.0 404 Not Found 3580ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/images/pages/login.png
[HTTP/1.0 404 Not Found 5053ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/vendors/js/vendors.min.js
[HTTP/1.0 404 Not Found 3878ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/js/core/app-menu.js
[HTTP/1.0 404 Not Found 4127ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/js/core/app.js
[HTTP/1.0 404 Not Found 4425ms]
GEThttp://127.0.0.1:8000/public/vuexy-assets/js/scripts/components.js
[HTTP/1.0 404 Not Found 4681ms]
Loading failed for the <script> with source “http://127.0.0.1:8000/public/vuexy-assets/vendors/js/vendors.min.js”. 127.0.0.1:8000:297:1
Loading failed for the <script> with source “http://127.0.0.1:8000/public/vuexy-assets/js/core/app-menu.js”. 127.0.0.1:8000:302:1
Loading failed for the <script> with source “http://127.0.0.1:8000/public/vuexy-assets/js/core/app.js”. 127.0.0.1:8000:303:1
Loading failed for the <script> with source “http://127.0.0.1:8000/public/vuexy-assets/js/scripts/components.js”. 127.0.0.1:8000:304:1
This is my problem. when I load my website, its frontend UI is gone, only shown the basic HTML structure. I tried every thing to make it to correct but I cant make it.
code from my layout
<link rel="stylesheet" type="text/css" href="{{ asset('vuexy-assets/css/bootstrap.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('vuexy-assets/css/bootstrap-extended.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('vuexy-assets/css/colors.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('vuexy-assets/css/components.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('vuexy-assets/css/themes/dark-layout.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('vuexy-assets/css/themes/semi-dark-layout.css') }}">
<!-- BEGIN: Page CSS-->
<link rel="stylesheet" type="text/css" href="{{asset('vuexy-assets/css/core/menu/menu-types/vertical-menu.css') }}">
<link rel="stylesheet" type="text/css" href="{{asset('vuexy-assets/css/core/colors/palette-gradient.css') }}">
<!-- END: Page CSS-->
<script src="{{ asset('/vuexy-assets/vendors/js/vendors.min.js') }}"></script>
<!-- BEGIN Vendor JS-->
<!-- BEGIN: Page Vendor JS-->
<script src="{{ asset('/vuexy-assets/vendors/js/ui/jquery.sticky.js') }}"></script>
<!-- END: Page Vendor JS-->
<!-- BEGIN: Theme JS-->
<script src="{{ asset('/vuexy-assets/js/core/app-menu.js') }}"></script>
<script src="{{ asset('/vuexy-assets/js/core/app.js') }}"></script>
<script src="{{ asset('/vuexy-assets/js/scripts/components.js') }}"></script>
my page currently looks like this
what I tried
install npm
npm run div
composer require laravel/ui
php artisan install bootstrap ui
I also tried installing yarn, and also did sass-loader degrade to "sass-loader": "10.1.1", from 11.0.0
By default, Laravel's asset helper points to public folder inside your application folder. If your assets are placed there, then your asset path should be like this.
Instead of
If your assets are outside from public directory, then please make a magic link between that directory and public directory.
Rewrite link from
To
This will correct the following errors.

The Mix manifest does not exist - Laravel Fortify Jetstream Login/Registration Issue when deploying laravel in Hostgator shared hosting

I have been able to deploy Laravel projects successfuly in the past.
For the first time I am using Laravel 8 with Jetstream and Livewire. Laravel is now using Fortify for login and registration auth.
My local server works perfect, no issues. After deploying the project to a Hostgator shared hosting account, my homepage loads correctly and reads and outputs data from my DB correctly.
However, when I try to access
mydomain.com/login/ or mydomain.com/login
or
mydomain.com/register/ or mydomain.com/register
I get a 500 error. Below at the end of this question I am pasting the error log.
I have done the following:
Updated composer version
npm rebuild
npm install
I tried both: npm run dev and npm run production and re-uploaded everything in each scenario.
I have pointed public/index.php path to the correct app folder to read the autoload.php and bootstrap/app.php files.
I have chmod all folders and subfolders to 755 and all files to 644
I find it really strange that my homepage loads flawless and brings data from DB just fine, therefore I know that my .env file has the correct db connection credentials. Only the login and registration will throw a 500 error.
My env file:
APP_NAME=NameOfApp
APP_ENV=production
APP_KEY=base64:KeyGeneratedWhenProjectCreated
APP_DEBUG=false
APP_URL=http://domain
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=db_works_good
DB_USERNAME=username_works_good
DB_PASSWORD=passwordWorksGood
Here is the laravel.log (shortened to what seems important):
[2020-11-30 20:25:34] production.ERROR: The Mix manifest does not exist. (View: /domain_root_path/app/resources/views/layouts/guest.blade.php) (View: /domain_root_path/app/resources/views/layouts/guest.blade.php) {"exception":"[object] (ErrorException(code: 0): The Mix manifest does not exist. (View: /domain_root_path/app/resources/views/layouts/guest.blade.php) (View: /domain_root_path/app/resources/views/layouts/guest.blade.php) at /domain_root_path/app/vendor/laravel/framework/src/Illuminate/Foundation/Mix.php:46)
[stacktrace]
#0 /domain_root_path/app/vendor/livewire/livewire/src/CompilerEngine.php(38): Illuminate\\View\\Engines\\CompilerEngine->handleViewException(Object(ErrorException), 0)
#1 /domain_root_path/app/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(60): Livewire\\CompilerEngine->handleViewException(Object(ErrorException), 0)
#2 /domain_root_path/app/vendor/livewire/livewire/src/LivewireViewCompilerEngine.php(32): Illuminate\\View\\Engines\\PhpEngine->evaluatePath('/home2/usr2...', Array)
...................
#52 /domain_root_path/public_html/index.php(52): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#53 {main}
[previous exception] [object] (Exception(code: 0): The Mix manifest does not exist. at /domain_root_path/app/vendor/laravel/framework/src/Illuminate/Foundation/Mix.php:46)
[stacktrace]
#0 /domain_root_path/app/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(506): Illuminate\\Foundation\\Mix->__invoke('/css/app.css')
#1 /domain_root_path/app/storage/framework/views/f25b68bee7f180a7da8624828693071be98325dc.php(14): mix('css/app.css')
#2 /domain_root_path/app/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(107): require('/home2/usr2...')
............................................
#66 {main}
THE STRUCTURE OF FILES:
root has two folders:
app (has all files except public folder)
public_html : has all public content including index.php
My index.php (inside public) has the following paths:
require __DIR__.'/../app/vendor/autoload.php';
$app = require_once __DIR__.'/../app/bootstrap/app.php';
GUEST.BLADE.PHP looks like this:
(please note that this file was auto-generated by Laravel and I have not touched it)
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:wght#400;600;700&display=swap">
<!-- Styles -->
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
<!-- Scripts -->
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine#v2.7.3/dist/alpine.js" defer></script>
</head>
<body>
<div class="font-sans text-gray-900 antialiased">
{{ $slot }}
</div>
</body>
</html>
/public/mix-manifest.json:
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css"
}
If you read below the error there is a hint about the solution :
Error's screenshot with a hint
You missed npm install && npm run dev
I replaced
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
with
<link rel="stylesheet" href="/css/app.css/">
and it works now.
The error happens because of two reasons:
you have to run npm install && npm run dev
if npm run dev command occurs error, please upgrade your node.js version to latest.

CSS and JS not working over HTTPS in laravel

My CSS and JS file work fine on localhost but when up to host it not working.
I use laravel 5.4. I tried a lot of ways but still failed.
enter image description here
My embedded CSS and JS code
enter image description here
UPDATE: Thanks all i have fixed my problems follow this:
1. change http://localhost to https://localhost at APP_URL line in .env file
2. add \URL::forceScheme('https') to AppServiceProvider.php file in boot() function
3. the last is include {{asset('--link_on_href--')}} for each CSS and JS embeded on index.php
Use the asset() helper to include assets in your view. This will automatically generate the appropriate URL for the included files based on you APP_URL in your .env file.
For CSS,
<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css" >
Or
<link href="{{ URL::asset('css/app.css') }}" rel="stylesheet" type="text/css" >
For JS,
<script type="text/javascript" src="{{ asset('js/custom.js') }}"></script>
Or
<script type="text/javascript" src="{{ URL::asset('js/custom.js') }}"></script>
For Images and other such assets,
{{ asset('img/photo.jpg'); }}
Link to the Docs

Resources