Laravel Framework | PHP & MySQL | Tutorials

David Carr

Laravel 5.5 change public to public_html

When moving Laravel onto a production server I like to place all Laravel files in their own directory above the document root. This keeps your files organised but does present a problem since the document root is often a public_html folder.

One solution that I’ve seen suggested a lof is to bind the path fro public in the appServiceProvider.php register method:

public function register()
    $this->app->bind('path.public', function() {

I’ve had mixed results with this, it means the public_path does look at the correct path in controllers but when you need the paths in configs before the provider has had a chance to kick in the original path comes back in.

I’ve found a much more reliable way is to go into your public_html/index.php and add:

$app->bind('path.public', function() {
    return __DIR__;

This updates your public path to the current directory, this even works for subfolders say public_html/beta.

After setting the above the public_path() helper correctly returns the new path.

Domains are often purchased from multiple providers, keeping track of where a domain is and its DNS settings can be tricky. Domain Mapper solves this by listing all your domains in one place. View your DNS settings and receive reminders to renew your domains. Try it today.

Support my work by donating with PayPal.

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2021 DC Blog. All code MIT license. All rights reserved.