Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AEROGU/19c63a40923b74f73c0163b1528168e4 to your computer and use it in GitHub Desktop.
Save AEROGU/19c63a40923b74f73c0163b1528168e4 to your computer and use it in GitHub Desktop.
Change `public` folder name to `public_html` in Laravel 8 or 9

Change public folder name to public_html in Laravel 8 or 9

in the most shared servers the default public folder is named public_html or www, whats may present a problem since the server document root and Laravel public folder are not the same.

Let's fix it following this 3 steps:

1. Change the public folder name.

That´s it, just do it.

2. Change the root path.

In app/Providers/AppServiceProvider.php add to the function register():

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

3. Fix the path for scripts used in CLI mode or Artisan script.

In bootstrap/app.php add at the end of the file but before return $app;:

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

this will bind Laravel document root with the correct one, in this case we are linking it to public_html folder, you can also put the full path to your document root instead of the dynamic approach.

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment