How to change public folder to public_html in laravel 8?
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# How to Change Public Folder to `public_html` in Laravel 8 on Shared Hosting
Deploying a modern framework like Laravel onto shared hosting environments, especially those managed through cPanel, often presents a specific structural challenge. You are correct: your hosting environment expects the primary document root to be `/public_html`, but your Laravel application naturally structures its public assets and entry point within a directory named `public`.
As a senior developer, I can tell you that this isn't usually a simple file rename; it’s more about understanding how the web server (Apache or Nginx) is configured to handle requests versus how Laravel expects the request to be routed. This guide will walk you through the correct deployment strategy and configuration adjustments needed to make your Laravel application function correctly on shared hosting.
## Understanding the Conflict: Document Root vs. Application Root
The conflict arises because:
1. **Shared Hosting Expectation:** CPanel sets `/public_html` as the root directory, meaning any file placed there is immediately accessible via a URL (e.g., `yourdomain.com/index.php`).
2. **Laravel Structure:** Laravel requires that all public-facing assets and routing be handled by the contents of the `public` directory. The entry point is typically `/public/index.php`.
If you simply move the entire `public` folder into `public_html`, you might run into issues with file permissions, server configuration (especially in complex shared hosting setups), or legacy `.htaccess` rules that conflict with Laravel’s routing.
## The Recommended Deployment Strategy for Laravel
The most robust and recommended way to deploy a Laravel application on shared hosting is generally *not* to try and force the entire application structure into the primary document root, but rather to ensure the web server points directly at the Laravel entry point.
### Step 1: Standard File Placement
Ensure your entire project directory (including `app`, `vendor`, `.env`, etc.) is uploaded to the root of your hosting space, and the main entry file remains correctly positioned. For most shared hosts, this means placing the contents of your Laravel project *inside* the `/public_html` folder or ensuring the web server configuration points to the correct location.
If you are deploying via FTP/SFTP, place your files such that:
```
/public_html/
├── index.php <-- This file must be accessible directly by the server.
├── .htaccess
└── public/ <-- Your Laravel public directory
├── index.php
└── assets/
```
### Step 2: Configuring the Web Server (The Crucial Step)
Since you are on shared hosting, direct access to modify core server configuration files might be restricted. The solution lies in utilizing the `.htaccess` file within your `public_html` directory to handle URL rewriting and routing, which is how Apache-based hosting environments manage public access.
You need to ensure that requests hitting the root map correctly to the Laravel entry point. While the standard Laravel setup relies on the application structure, shared hosts often require specific rules for handling subdirectories.
For many cPanel setups, if your entire project directory resides in `public_html`, you can leverage `.htaccess` to manage routing cleanly:
**Example `.htaccess` adjustment (for basic routing):**
```apache
RewriteEngine On
RewriteRule ^(.*)$ public_html/public/$1 [L]
```
*Note: This is a conceptual example. Actual implementation depends heavily on the specific Apache configuration provided by your host.*
## Best Practices for Laravel Deployment
Instead of fighting the server structure, focus on making your application self-contained and correctly configured. When working with frameworks like **Laravel**, adhering to best practices ensures smoother deployment regardless of the underlying hosting environment. For instance, ensuring all assets are correctly linked via the `public` directory is fundamental to asset management and scalability, a key principle emphasized by resources like [https://laravelcompany.com](https://laravelcompany.com).
### Conclusion
Changing the public folder structure on shared hosting is less about renaming a single folder and more about correctly configuring the web server's document root and using `.htaccess` files to bridge the gap between the host expectation (`public_html`) and the application requirement (`public`). By focusing on proper file placement and configuration overrides, you can successfully deploy your Laravel application reliably on shared hosting. Always test thoroughly after making these adjustments to ensure all routes and assets load correctly.