Home >Backend Development >PHP Tutorial >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__; });
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'); }); }
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!