How to Change the Public Directory Path in Laravel 7

Here is a quick tip for those of you who need to change the public path of your Laravel 7 installation. When working on a local development environment such as Homestead your public path will simply be /public but on many hosting solutions, the public root will be located under /public_html.

 

To change the Laravel public path open the index.php file located at public/index.php.

 

Then after the line:

 

public/index.php
$app = require_once __DIR__.'/../bootstrap/app.php';

 

enter the following code:

 

public/index.php
$app->bind('path.public', function() {
  return base_path().'/public_html';
});

 

After return base_path(). you can enter the file name of any public root you wish.

directory