Fixing Laravel’s Public Folder Redirect on Cpanel Shared Hosting Installation

Chigozie Orunta
2 min readNov 8, 2020

--

Getting the default home page for Laravel to come up as shown above for a Laravel installation on a Cpanel shared hosting might be surprisingly difficult.

This is because the default installation that comes with Cpanel’s Softaculous Laravel package ships with an index.php file that redirects you to the public folder rather than the root folder of your Laravel installation.

For a newly installed Laravel package using Softaculous, you typically see the following screen by default:

This screen after 5 seconds redirects to the public folder within your Laravel application. Obviously, this is not what we want, so let’s fix it in 2 easy steps!

  1. Locate the index.php file installed in your root folder by default. It should look similar to this:
<?php
header("refresh: 5; https://yoursite.com/public/");
echo '<title>Laravel Installed</title><div style="background: #e9ffed; border: 1px solid #b0dab7; padding: 15px;" align="center" >
<font size="5" color="#182e7a">Laravel is installed successfully.</font><br /><br />
<font size="4">Laravel is a Framework and doesn\'t have an index page.<br /><br />
You will be redirected to its "public" folder in 5 seconds...<br /><br />
Laravel is a clean and classy framework for PHP web development.
Freeing you from spaghetti code, Laravel helps you create wonderful applications using simple, expressive syntax. Development should be a creative experience that you enjoy, not something that is painful. Enjoy the fresh air.
</font></div>';
?>

2. Replace the contents of this file with the following script shown below:

<?phpuse Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));require __DIR__.'/vendor/autoload.php';$app = require_once __DIR__.'/bootstrap/app.php';$kernel = $app->make(Kernel::class);$response = tap($kernel->handle(
$request = Request::capture()
))->send();
$kernel->terminate($request, $response);

Once done, save your index.php file and run your Laravel application again. This time it should point directly to your Laravel home page as expected.

And that’s it, you’re good to go!

--

--