In the course of building products. You will encounter a situation where some of your users are hosting your product on a shared server. So here is how to do it if you encounter such problem.

First, let say in your shared hosting, you have current www or public_html directory, which is accessible publicly via web domain

Let say your laravel project is named laravel50 with the following folder structure:

After you have copied all the files to your www or public_html folder of your shared hosting. Create a folder and name it protected. You can call it any other name that you like. Then move all the files and folders to this new folder you created except the public folder. So you new folder structure would be

|--public_html
|--protected |--app
|--bootstrap
|--config
|--database
|--resources
|--storage
|--tests
|--vendor
|--.env
|--.env.example
|--.gitattributes
|--.gitignore
|--artisan
|--composer.json
|--composer.lock
|--gulpfile.js
|--package.jso
|--phpspec.yml
|--phpunit.xml
|--readme.md
|--server.php
|--public

Then after that, move all the content in the public folder into the main www or public_html folder. Your final folder structure would then be like this

|--public_html
|--protected bind('path.public', function() {
return __DIR__;
});

$kernel = $app->make('Illuminate\Contracts\Http\Kernel');

$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);
?>

After that open server.php in the protected folder and line 21 to something like this

*/

$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'../'.$uri))
{
return false;
}

require_once __DIR__.'../index.php';

And that’s it.

I would also recommend using the same folder structure during your development so that you can experience the whole process of deployment before you upload to your hosting server.

Hope this helps!