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

Jdagger's avatar

500 Internal server error on shared web hosting Hostinger

So I've been trying to get my Laravel application running on Hostinger under a shared hosting plan (I wasn't aware VPS is actually better for Laravel) but I'm getting a 500 server error.

I have already configured my index.php and .htaccess files as well as made a database and put the credentials into the .env file so now I'm confused as to what I'm doing wrong. Also: the URL of the website redirects me to website.com/public which is pretty weird because there's no file or folder anymore called public as I've put all the files and folders of public into public_html and the rest of the files/folders in their own seperate folder on the level above.

.htacces:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>
    
    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteRule ^(.*)$ public/ [L]
    </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]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

index.php:

<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/

if (file_exists($maintenance = __DIR__.'/../aquatory/storage/framework/maintenance.php')) {
    require $maintenance;
}

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/

require __DIR__.'/../aquatory/vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/

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

$kernel = $app->make(Kernel::class);

$response = $kernel->handle(
    $request = Request::capture()
)->send();

$kernel->terminate($request, $response);

My guesses:

  1. the website root is pointing at a file/folder that doesn't exist
  2. something up with my .htacces because idk what all of it does
  3. the symlink of public_html in my root folder of my domain
0 likes
17 replies
Tray2's avatar

You should not change the document root, it should always be pointing to the public directory.

If you aren't allowed in your shared hosting to change the document root, then use an htaccess that redirects everything to /public.

I use this one on my site

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

However, it's better to set the document root correctly.

1 like
martinbean's avatar

@jdagger If you’re getting a 500 error then that means an exception is being thrown. So check the error log on the server to see what the actual error is, and resolve it.

1 like
Jdagger's avatar

@martinbean I can't seem to find them. There is a .logs file, but it does not contain any errors. I have enabled PHP error logging.

martinbean's avatar

@Jdagger So long as you haven’t changed any log-related environment variables, then the default location is storage/logs/laravel.log

1 like
Jdagger's avatar

@martinbean This was the latest error in that file:

[2024-07-30 09:50:48] local.ERROR: Vite manifest not found at: /home/u998977360/domains/mywebsite/myproject/public/build/manifest.json {"view":{"view":"/home/u998977360/domains/mywebsite/myproject/resources/views/components/layout.blade.php","data":[]},"exception":"[object] (Spatie\LaravelIgnition\Exceptions\ViewException(code: 0): Vite manifest not found at: /home/u998977360/domains/mywebsite/myproject/public/build/manifest.json at /home/u998977360/domains/mywebsite/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Vite.php:728)

I have since removed any @vite calls in my project header but the problem persists.

What I also tried doing was keeping a copy of the manifest.jason in the folder that laravel requested but no success yet.

I do have a Hostinger branded 404 error now. Different error, so that means we're making progress. Yay!

Also: the URL request seems to be stuck on https:/mywebsite.com/public

martinbean's avatar

@Jdagger Then you’ll need to run npm run build somewhere else, and ensure the generated files are uploaded along with the rest of your application to Hostinger.

1 like
Jdagger's avatar

@tray2 I put those rules into the .htaccess and the domain went from a big black 500 error screen to a now chrome browser branded 500 error

Jdagger's avatar

@martinbean I followed the Laravel 8 tutorial from Hostinger: https://support.hostinger.com/en/articles/6152127-how-to-deploy-laravel-8-at-hostinger since I couldn't find more resources by them on shared hosting but step 2 was unclear to me and I only put my "laravel-project/public" in public_html and the rest of the project in a level above public_html. Customer support recommended that I put all the other files in public_html too and my website runs smoothly now. I've just made the same file structure that I had before but now all within public_html.

The other commenters suggested that I run npm run dev and then upload the /build folder to the file manager.

I also did this with .htaccess:

<IfModule mod_rewrite.c> 

    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]
    
    # Send Requests To Front Controller... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^ index.php [L]
    
    # Redirect all traffic to public directory
    RewriteEngine On RewriteRule ^(.*)$ public/ [L]
    
</IfModule>
Tray2's avatar

@Jdagger What you have done is very dangerous, anyone will most likely have access to your .env file. There is a reason why it should be placed in a directory above public.

andreigirnet96's avatar

@Jdagger I was facing the same problem, and I told my hosting provider to host the website as root public_html/public, so when you access the domain it will search for index.php in public_html/public, by default it will search for index.php in public_html folder

1 like
andreigirnet96's avatar

@Jdagger I am also sure that I had issues with these lines as well Options -MultiViews -Indexes I think you need to comment them

Jdagger's avatar

@Tray2 I changed it so that in my /home/domains/my-website/public_html I now have /public where I have the index.php, .htaccess and npm build folder. Everything else is in a folder above /public. I have edited the .htaccess to point to the correct references and still runs. Or are you suggesting I need to run the rest of the files outside of public_html?

shariff's avatar

@jdagger In Hostinger, we have SSH access to run Laravel commands, but npm commands cannot be executed there. The best approach is to run npm run build on your local system, then upload the public\build folder.

1 like

Please or to participate in this conversation.