Skip to main content

Command Palette

Search for a command to run...

How to run Laravel 5.x on shared hosting?

Updated
1 min read

It is very easy to run Laravel on VPS or dedicated hosting but how about on shared hosting?

On VPS, you just need to create a virtual host and point the root directory into Laravel public folder.

But on shared hosting, they usually have public_html folder instead of public folder. You can create public folder but how to point document root to public instead of public_html folder? Yup, usually not :(

Fortunately, Laravel allow us run under whatever folder we want, just update some lines of code :) First, rename public folder to public_html, edit index.php by adding this block after $app require_once statement:

// set the public path to this directory
$app->bind('path.public', function() {
    return __DIR__;
});

Second, add the below code in register() method at app/Providers/AppServiceProvider.php file:

$this->app->bind('path.public', function() {
  return base_path('public_html');
});

Tada! Now you can run your Laravel application smoothly!

More from this blog

K

Khánh's blog

146 posts