How to change the Laravel public folder location

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Efficiently Modifying Laravel's Public Folder Location on Shared Hosting with cPanel Introduction: Laravel is undoubtedly an incredible framework that allows developers to focus on creating applications rather than worrying about the underlying structure. However, it does have its limitations when used under certain hosting environments, especially those using a control panel like cPanel and limiting root directories like public_html. In this blog post, we will explore how to overcome this challenge by reconfiguring the Laravel installation to use public_html as your application's base directory while still leveraging all its benefits. Step 1: Understanding Your Configuration Before proceeding with the changes, it is crucial to understand the current structure of your Laravel project. The default configuration involves using the public folder under the project root directory for static files like CSS and JS assets. For shared hosting with cPanel, one typically accesses their website through public_html, where all web content is hosted. Step 2: Moving Your Public Folder to public_html The first step is to move your Laravel's public folder from its current location within the project directory to public_html. To do this: 1. Create a new public_html/public (or another name that doesn't conflict with the original) folder under the public_html root directory. 2. Move the contents of your Laravel's public folder into this newly created directory, ensuring all assets are placed in their respective subfolders (css, images, etc.). 3. Inside the new public directory, create a symbolic link named "public" that points to the original Laravel's public folder. This will allow your website to access the Laravel application as usual, but from within the cPanel's public_html folder. Step 3: Configuring Your Virtual Host and .htaccess File Next, you want to update your virtual host configuration file (often found in /etc/httpd/conf.d) with a rewrite rule to match the newly created structure. This will redirect all requests to the public folder within your Laravel installation to its new location under public_html. Here's an example: ``` # Laravel Rewrite Rules RewriteEngine On RewriteCond %{SERVER_PORT} !=443 RewriteRule ^/?(.*)$ https://www.example.com/$1 [R,L] RewriteBase /public_html RewriteRule ^(.*)$ public/index.php [L] ``` Finally, ensure that your .htaccess file within the new public directory contains these lines: ``` RewriteEngine On RewriteBase /public/ RewriteCond %{REQUEST_URI} !^/public RewriteRule ^(.*)$ /public/$1 [L,QSA] ``` These configurations allow your Laravel application to work as expected without conflicts. Step 4: Testing and Troubleshooting Once you've completed the steps above, you can test your new setup by accessing your website through your newly created public_html folder. If everything is working correctly, you should see your Laravel application running as usual. If issues arise, ensure that your server configuration files are correct and check your hosting provider's documentation for further assistance in resolving the problem. Conclusion: Changing the location of Laravel's public folder to public_html can offer a more streamlined experience when using shared hosting with cPanel. By following these simple steps, you can maintain a well-structured and efficient Laravel application without any hassle. Don't forget that the Laravel community is always there to support and guide you through these processes. For additional learning resources, explore https://laravelcompany.com/, where you can find valuable tips, tutorials, and news related to Laravel development.