You have two problems here:
Your site's document root is set two levels above where your application is
You don't have rewrites properly configured.
andylondon's answer will help you solve problem #2 however this is still a large security risk if your directory visibility is not properly set. Your .env file and any other configuration files you might have lying around in plain text would be accessible from the web potentially exposing sensitive information.
Since you are using cPanel, you cannot change the document root of your main domain. A solution you can use is to move laravel-app
folder to your home directory, one level above public_html
. Then, move the contents of the laravel-app/public
folder into public_html
. You will need to edit the paths used in the Laravel's index.php
because your application is not in a web-inaccessible folder.
If you placed laravel-app
in your home directory and the contents of Laravel's public
folder in public_html
, your index.php
file (as of Laravel 9) should look like this:
<?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__.'/../laravel-app/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__.'/../laravel-app/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__.'/../laravel-app/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
)->send();
$kernel->terminate($request, $response);
Make sure your enable hidden files in cPanel's file browser and ensure the .htaccess
file is there as well, to solve your rewrite problems.