Home > Backend Development > PHP Tutorial > How to Change Laravel's Public Folder Location on Shared Hosting?

How to Change Laravel's Public Folder Location on Shared Hosting?

Barbara Streisand
Release: 2024-12-09 01:47:10
Original
602 people have browsed it

How to Change Laravel's Public Folder Location on Shared Hosting?

How to Adjust the Laravel Public Folder's Location

When using shared hosting platforms like cPanel, where the default root directory is "public_html," it can conflict with Laravel's default public folder location. This can hinder the proper functioning of Laravel applications.

Solution:

To address this issue, you need to modify the index.php file located in your project's root directory. Add the following lines of code:

// Set the public path to the current directory
$app->bind('path.public', function () {
    return __DIR__;
});
Copy after login

Alternatively, and more preferably, you can set the public path within the register() method of your AppProvidersAppServiceProvider class:

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

By implementing these changes, Laravel will now recognize the "public_html" directory as its public folder, allowing your application to function as expected within the cPanel environment.

The above is the detailed content of How to Change Laravel's Public Folder Location on Shared Hosting?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template