{"id":1,"date":"2026-02-02T18:25:11","date_gmt":"2026-02-02T18:25:11","guid":{"rendered":"https:\/\/eksprt.com\/blog\/?p=1"},"modified":"2026-02-09T13:00:24","modified_gmt":"2026-02-09T13:00:24","slug":"how-to-change-the-public-folder-to-public-html-in-laravel","status":"publish","type":"post","link":"https:\/\/eksprt.com\/blog\/how-to-change-the-public-folder-to-public-html-in-laravel\/","title":{"rendered":"How to Change the public Folder to public_html in Laravel (Step-by-Step Guide)"},"content":{"rendered":"\r\n<p>If you are deploying Laravel on <strong>shared hosting like <a href=\"https:\/\/www.dpbolvw.net\/click-101203980-13608890\">Hostinger<\/a> or cPanel servers<\/strong>, you may notice that the document root is <code>public_html<\/code> instead of Laravel\u2019s default <code>public<\/code> directory. This mismatch can cause asset loading issues, broken storage links, or security concerns if not handled correctly.<\/p>\r\n\r\n\r\n\r\n<p><\/p>\r\n\r\n\r\n\r\n<p>In this <strong>expert Laravel tutorial<\/strong>, you will learn <strong>how to change the Laravel public folder to <code>public_html<\/code> safely<\/strong>, including support for <strong>Vite, storage symlinks, and Hot Module Replacement (HMR)<\/strong>.<\/p>\r\n\r\n\r\n\r\n<p><\/p>\r\n\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Why Change Laravel\u2019s Public Folder to <code>public_html<\/code>?<\/h2>\r\n\r\n\r\n\r\n<p>Many hosting providers enforce <code>public_html<\/code> as the web root. Common reasons to change it include:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Compatibility with <strong>cPanel \/ shared hosting<\/strong><\/li>\r\n\r\n\r\n\r\n<li>Avoiding unnecessary symlinks<\/li>\r\n\r\n\r\n\r\n<li>Improved <strong>application security<\/strong><\/li>\r\n\r\n\r\n\r\n<li>Cleaner project structure<\/li>\r\n\r\n\r\n\r\n<li>Proper Vite asset resolution<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\r\n<p>\u2705 This method works for <strong>Laravel 9, Laravel 10, and newer versions<\/strong><\/p>\r\n<\/blockquote>\r\n\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\r\n\r\n\r\n\r\n<p>Before proceeding, ensure you have:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Laravel 9+<\/li>\r\n\r\n\r\n\r\n<li>PHP 8 or higher<\/li>\r\n\r\n\r\n\r\n<li>Node.js (for Vite)<\/li>\r\n\r\n\r\n\r\n<li>Access to project files (SSH or FTP)<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Step 1: Override the Public Path in <code>AppServiceProvider<\/code><\/h2>\r\n\r\n\r\n\r\n<p>Laravel internally resolves the public directory using the service container. We override it to point to <code>public_html<\/code>.<\/p>\r\n\r\n\r\n\r\n<p>\ud83d\udccd <strong>File:<\/strong> <code>app\/Providers\/AppServiceProvider.php<\/code><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>\/**\r\n * Overwrite public folder.\r\n *\/\r\n$this-&gt;app-&gt;bind('path.public', function () {\r\n    return base_path('public_html');\r\n});\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Why This Is Important<\/h3>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Updates <code>public_path()<\/code> globally<\/li>\r\n\r\n\r\n\r\n<li>Ensures asset helpers reference <code>public_html<\/code><\/li>\r\n\r\n\r\n\r\n<li>Prevents broken file paths in production<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Step 2: Configure the Public Path in <code>bootstrap\/app.php<\/code><\/h2>\r\n\r\n\r\n\r\n<p>Modern Laravel versions define the public path during application bootstrapping.<\/p>\r\n\r\n\r\n\r\n<p>\ud83d\udccd <strong>File:<\/strong> <code>bootstrap\/app.php<\/code><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n\r\nuse Illuminate\\Foundation\\Application;\r\nuse Illuminate\\Foundation\\Configuration\\Exceptions;\r\nuse Illuminate\\Foundation\\Configuration\\Middleware;\r\n\r\n$app = Application::configure(basePath: dirname(__DIR__))\r\n    -&gt;withRouting(\r\n        web: __DIR__.'\/..\/routes\/web.php',\r\n        commands: __DIR__.'\/..\/routes\/console.php',\r\n        health: '\/up',\r\n    )\r\n    -&gt;withMiddleware(function (Middleware $middleware) {\r\n        $middleware-&gt;validateCsrfTokens(except: &#91;\r\n            '\/admin\/upload',\r\n        ]);\r\n    })\r\n    -&gt;withExceptions(function (Exceptions $exceptions) {\r\n        \/\/\r\n    })\r\n    -&gt;registered(function ($app) {\r\n        $app-&gt;usePublicPath(\r\n            path: realpath(base_path('\/..\/public_html'))\r\n        );\r\n    })\r\n    -&gt;create();\r\n\r\n$app-&gt;bind('path.public', function () {\r\n    return base_path().'\/public_html';\r\n});\r\n\r\nreturn $app;\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">SEO Benefit<\/h3>\r\n\r\n\r\n\r\n<p>Ensures:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Proper asset loading<\/li>\r\n\r\n\r\n\r\n<li>No broken CSS or JS files<\/li>\r\n\r\n\r\n\r\n<li>Faster page rendering (Core Web Vitals)<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Step 3: Fix Storage Symlinks (<code>storage:link<\/code>)<\/h2>\r\n\r\n\r\n\r\n<p>Laravel\u2019s file uploads rely on the public directory. Update the symlink configuration accordingly.<\/p>\r\n\r\n\r\n\r\n<p>\ud83d\udccd <strong>File:<\/strong> <code>config\/filesystems.php<\/code><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>'links' =&gt; &#91;\r\n    app()-&gt;basePath('public_html\/storage') =&gt; storage_path('app\/public'),\r\n],\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>Then run:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>php artisan storage:link\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Result<\/h3>\r\n\r\n\r\n\r\n<p>Uploads will now be accessible at:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>\/public_html\/storage\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Step 4: Update Vite Configuration for <code>public_html<\/code><\/h2>\r\n\r\n\r\n\r\n<p>Vite must be aware of the new public directory for <strong>Hot Module Replacement (HMR)<\/strong> and production builds.<\/p>\r\n\r\n\r\n\r\n<p>\ud83d\udccd <strong>File:<\/strong> <code>vite.config.js<\/code><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>import { defineConfig } from 'vite';\r\nimport laravel from 'laravel-vite-plugin';\r\n\r\nexport default defineConfig({\r\n    plugins: &#91;\r\n        laravel({\r\n            input: &#91;'resources\/js\/app.js'],\r\n            publicDirectory: 'public_html',\r\n        }),\r\n    ],\r\n    build: {\r\n        outDir: 'public_html\/build',\r\n    },\r\n    server: {\r\n        hmr: {\r\n            host: 'localhost',\r\n        },\r\n    },\r\n});\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Why This Matters for SEO<\/h3>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Prevents broken assets<\/li>\r\n\r\n\r\n\r\n<li>Improves Lighthouse performance scores<\/li>\r\n\r\n\r\n\r\n<li>Ensures proper asset versioning<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Step 5: Rename the Public Folder<\/h2>\r\n\r\n\r\n\r\n<p>Rename Laravel\u2019s default public directory:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>mv public public_html\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>Make sure your <strong>server document root<\/strong> points to:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>\/your-project\/public_html\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Clear Cache and Rebuild Assets<\/h2>\r\n\r\n\r\n\r\n<p>After all changes, run:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"><\/pre>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>php artisan optimize:clear\r\nnpm run build\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<p>This ensures:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Fresh configuration<\/li>\r\n\r\n\r\n\r\n<li>Clean route &amp; view caches<\/li>\r\n\r\n\r\n\r\n<li>Correct asset compilation<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Common Issues and Fixes<\/h2>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Problem<\/th><th>Solution<\/th><\/tr><\/thead><tbody><tr><td>Assets not loading<\/td><td>Rebuild Vite assets<\/td><\/tr><tr><td>Storage files 404<\/td><td>Re-run <code>storage:link<\/code><\/td><\/tr><tr><td>HMR not working<\/td><td>Set correct HMR host<\/td><\/tr><tr><td>Cached paths<\/td><td>Run <code>optimize:clear<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\r\n\r\n\r\n\r\n<p>Changing Laravel\u2019s <code>public<\/code> folder to <code>public_html<\/code> is <strong>100% safe and production-ready<\/strong> when configured properly. This setup is ideal for:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Shared hosting<\/li>\r\n\r\n\r\n\r\n<li>cPanel environments<\/li>\r\n\r\n\r\n\r\n<li>Secure Laravel deployments<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>By updating Laravel\u2019s <strong>service container, bootstrap configuration, filesystem links, and Vite settings<\/strong>, you ensure long-term stability and SEO-friendly asset delivery.<\/p>\r\n\r\n\r\n\r\n<p><\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>If you are deploying Laravel on shared hosting like Hostinger or cPanel servers, you may notice that the document root is public_html instead of Laravel\u2019s default public directory. This mismatch can cause asset loading issues, broken storage links, or security concerns if not handled correctly. In this expert Laravel tutorial, you will learn how to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7380,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":1,"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":7376,"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/posts\/1\/revisions\/7376"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/media\/7380"}],"wp:attachment":[{"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eksprt.com\/blog\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}