How to change the Laravel public folder location

How to change the Laravel public folder location

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

How to Change the Laravel Public Folder Location

Laravel's default installation places the entry point for your application in a dedicated public directory, but shared hosting environments often enforce a stricter structure where public_html serves as the document root. If you are deploying on cPanel, you might find that placing the entire Laravel project inside public_html causes issues because the web server expects the static assets and entry file to be at the root level, not nested within another folder.

The standard solution is to rename the default public directory to your application's root name (often laravel) and then configure the framework to use the original public folder as its actual public path. However, simply renaming directories isn't enough; you must also update Laravel's configuration to tell the framework where the actual entry point resides.

Renaming the Public Directory

The first step involves moving the files physically into the correct location and adjusting the directory names accordingly. If your application is currently in public_html/laravel/public, you need to restructure it so that public_html becomes the new root for your web server, containing a public subdirectory.

You can achieve this by renaming the default public folder to match your project name (e.g., laravel) and then moving the original public contents into public_html/public. Alternatively, if you prefer keeping the project name at the root, you can rename the public directory to laravel and ensure that public_html/laravel becomes your new document root.

For a typical cPanel setup where public_html is the document root, the recommended file structure looks like this:

/home/username/public_html/
├── .htaccess          (Optional, if needed for specific routing)
└── public/            (Laravel's actual public folder)
    ├── index.php
    ├── mix/
    └── storage/
        └── ...

However, since public_html is now the document root defined by cPanel, you must ensure that your application files reside directly within it or in a subdirectory that the web server can access. If you move the entire Laravel project into public_html, you must rename the public folder to something else (like web or keep it as laravel) and update the configuration.

Updating Laravel Configuration

Once the file structure is adjusted, you need to inform Laravel where its public directory actually lives. By default, Laravel assumes the public folder is located in the root of your application (base_path('public')). If you have moved this folder or renamed it, you must update the APP_PUBLIC_PATH environment variable or configure the framework explicitly.

In older versions of Laravel (prior to 5.4), this was handled via the .env file:

APP_PUBLIC_PATH=/path/to/public_html/public

In modern versions of Laravel (5.4 and later), the APP_PUBLIC_PATH variable is deprecated in favor of using the standard APP_BASE_PATH combined with a relative path, but if you are restructuring the root entirely, you may need to adjust how you serve the application.

If you decide to keep the public folder nested inside your project root (e.g., laravel/public) and want to access it via public_html/laravel, you can use Laravel's built-in support for custom public paths by setting the APP_PUBLIC_PATH environment variable in your .env file:

APP_PUBLIC_PATH=/home/username/public_html/laravel/public

Be cautious when modifying this path, as incorrect configuration can lead to 403 Forbidden errors or missing asset issues. Always verify that the web server user (usually nobody or www-data) has read permissions on the new public directory.

Handling .htaccess and Security

When moving Laravel to a non-standard location, you must also consider Apache's .htaccess file. Laravel includes a default .htaccess file in its public directory that handles routing for assets like CSS, JavaScript, and images. If you rename the public folder or move it outside the expected location, ensure that this .htaccess file is present in the new public directory and not blocked by server-level restrictions.

On cPanel, sometimes the default .htaccess is ignored if placed incorrectly. Make sure your public directory contains a valid .htaccess file with the following configuration to ensure proper routing:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

This ensures that all requests are routed through index.php, which is critical for Laravel's routing mechanism to function correctly.

Trade-offs and Considerations

While moving the public folder allows you to comply with shared hosting constraints, it introduces complexity in deployment workflows. When deploying updates or running artisan commands like php artisan serve, you must ensure that the working directory references the correct base path. Additionally, some hosting providers may not allow symbolic links to the public folder due to security policies, so physical restructuring is often safer.

Another consideration is caching. If you use tools like Varnish or CDN services that cache based on URL structure, changing the public path might invalidate existing cached assets unless configured correctly. Always test your application thoroughly after making these changes to ensure that assets load properly and no 403 or 404 errors occur.

If you encounter persistent issues with file permissions or routing, consult your hosting provider's documentation or consider using a managed Laravel hosting solution that handles these configurations automatically. For more advanced deployment strategies on shared hosting, resources like https://laravelcompany.com offer insights into optimizing Laravel for constrained environments.

Our network