Learn how to deploy Laravel 13 on shared hosting using the public_html directory instead of Laravel’s default public folder. This guide covers Vite configuration, public path overrides, storage setup, and production-ready deployment tips for modern Laravel applications.
Running Laravel on shared hosting can be challenging because most hosting providers use a public_html directory as the document root instead of Laravel’s default public folder.
In Laravel 13, there are a few clean ways to handle this setup. In this guide, we’ll configure Laravel to use public_html as the public directory while keeping the application structure secure and maintainable.
Why Shared Hosting Is Different
On VPS or cloud servers, the web server usually points directly to Laravel’s public directory.
Shared hosting environments are different:
Your domain typically points to
public_htmlYou usually cannot modify the server configuration
Access to Apache or Nginx configs is limited
The application files often live one level above
public_html
A typical shared hosting structure looks like this:
/home/username/
├── laravel-app/
│ ├── app/
│ ├── bootstrap/
│ ├── storage/
│ └── ...
└── public_html/Option 1: Point the Domain to Laravel’s Public Folder
Some hosting providers allow you to change the domain’s document root.
If possible, point the domain directly to:
/home/username/laravel-app/publicThis is the cleanest and most secure solution.
If your hosting provider does not allow this, continue with the next option.
Option 2: Use public_html as Laravel’s Public Directory
Step 1: Override Laravel’s Public Path
Open the following file:
app/Providers/AppServiceProvider.phpAdd this code inside the register() method:
public function register(): void
{
$this->app->bind('path.public', function () {
return base_path('../public_html');
});
}This tells Laravel to use the public_html directory instead of the default public folder.
Depending on your folder structure, you may need to adjust the path.
Step 2: Configure Vite
Laravel 13 uses Vite instead of Laravel Mix.
Open:
vite.config.jsUpdate the build output directory:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel([
'resources/css/app.css',
'resources/js/app.js',
]),
],
build: {
outDir: '../public_html/build',
emptyOutDir: true,
},
});Now your compiled assets will be generated directly into public_html/build.
Build your frontend assets:
npm run buildStep 3: Update the index.php File
Copy Laravel’s default public/index.php file into:
public_html/index.phpThen update the paths:
require __DIR__.'/../laravel-app/vendor/autoload.php';
$app = require_once __DIR__.'/../laravel-app/bootstrap/app.php';Adjust the folder names based on your actual directory structure.
Step 4: Create the Storage Symlink
Laravel needs access to public storage files.
Run:
php artisan storage:linkIf your hosting provider does not allow symlinks, manually create the following folder:
public_html/storageThen copy the contents from:
storage/app/publicStep 5: Check Your .htaccess File
Make sure your public_html/.htaccess file contains Laravel’s rewrite rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>Without this configuration, Laravel routes may return 404 errors.
Security Recommendations
When using shared hosting:
Keep your
.envfile outsidepublic_htmlNever expose the
vendordirectory publiclyDisable directory listing if possible
Always use HTTPS
Regularly update Laravel dependencies
For production environments, also make sure:
APP_ENV=production
APP_DEBUG=falseOptimize Laravel before deployment:
php artisan optimizeFinal Thoughts
Shared hosting is not ideal for Laravel applications, but it still works well for small projects, MVPs, and client websites.
If your hosting provider does not support changing the document root, using public_html as Laravel’s public directory is a clean and reliable workaround for Laravel 13 applications.