There can be various reasons that can lead you to use a Shared hosting to deploy Laravel App (application), though it’s not recommended. Shared hosting providers bunch or group many of their clients into a single server to process requests for each of them, thus called Shared Hosting. So, it’s hard for them to change the behaviour of the server for a single client. Since that can affect the other clients using the same instance of the server and lead them into trouble. Sometimes opening a ticket to your hosting provider works as they transfer you to another server that can run your stack or application. Although if they’re unable to do this, relax, You can still use that same server to deploy your Laravel app.
There are many ways, methods or tutorials available on the internet to make it possible. Some of them make use of .htaccess file whereas some prefer to move the files of the public directory to the root directory of the Laravel application. Although doing any of the listed above procedure is dangerous and can make your website vulnerable to attacks. The public directory was chosen as an entry point on purpose to avoid inappropriate access to the existing files. While moving files out to the root directory would just break this barrier the Laravel developers have set. And it will lead your Laravel application to vulnerabilities and might break down the application itself.
Many shared hosting makes use of public_html or www directory to serve the application. So it would make more sense to utilize this directory provided by the shared hosting and use it instead of the public directory.
First and foremost, begin with uploading your project to the very root directory of the hosting where the public_html directory is located. Like in the example given below, I’ve uploaded my demo project. Sure, your project name could be anything.

Once uploaded, we’re good to move to the next step which is to copy all the files located in the public directory of your Laravel application to the public_html directory. So, the index.php file of the public directory of your application serves as the index.php file of the public_html directory. In the PHP application, index.php file is always the entry point.
After copying the files of your public directory to the public_html directory. We need to make a few changes into your application to make it work. We need to somehow tell Laravel about where to look for the application files from the public_html directory and vice-versa. Open up the index.php file you just copied along with the other files to the public_html directory in your favourite editor and change the line that says.
require DIR.'/../vendor/autoload.php';
To,
require DIR.'/../demo/vendor/autoload.php';
So, it looks something in the screenshot given below. Of course, replace demo with your project name. Here I have set demo based on my project.

Next, proceed and do the exact same thing for the line that says.
$app = require_once __DIR__.'/../bootstrap/app.php';
To,
$app = require_once __DIR__.'/../demo/bootstrap/app.php';
Make sure to replace the demo with your project name.

Once done, we need to explain
$app->bind('path.public', function() { return __DIR__; });
After making the above changes the code inside the index.php file would look something like this.

We’re almost done. Last-step would be to do a quick change in the server.php file located inside your application. Go back to the project’s root directory and look for the file server.php. Once found, open it up in your favourite text editor to explain the application’s server about the public_html directory. Look for the code given below in the server.php file.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { return false; } require_once __DIR__.'/public/index.php';
And replace the public directory with the new path of the public_html directory.
if ($uri !== '/' && file_exists(__DIR__.'./../public_html'.$uri)) { return false; } require_once __DIR__.'./../public_html/index.php';
Finally, the code inside the server.php file might look like the one given below.

After making these changes your application would be all set and be ready to work. Though you might need to do some more steps such as Installing Composer Packages, Installing Javascript Packages, Bundling up Javascript Packages, Database migration, Database seeding, Symlink, etc. depending upon your application.
Sometimes, your Shared hosting provider does not provide the Composer and NPM libraries preinstalled in the server. In that case, You can always look for the packages Composer & NodePHP developed by me to solve these issues respectively. These packages install a copy of Composer and Node JS right in your project. So, You don’t have to have these preinstalled in the server. Also, check out my guide on Disabling Auto-login after Registration in Laravel.
That’s it my friends. Let me know, how was your journey of deploying your Laravel application on Shared Hosting in comments below. Last but not least a tight hug for deploying your new Laravel application.
Awesome post bro and easy to understood
I don’t see why you need to change server.php on shared hosting
It’s fine if you don’t change it either.
how can i fill file .htaccess on production, in my case I try to open my website by chrom or mozila but error. the error “not found”. and when i open in my phone use chrome the error “error forbidden”. Can you give advice form my case bro. thanks
To change the “.htaccess” file you must have the access to the server or ftp. The “.htaccess” is generally located in the root of the website or in case of laravel it’s located in “public” directory. I wouldn’t recommend you to change the “.htaccess” file content since it’s something that only experts should touch because it can break your entire website. Given below is the link to the original “.htaccess” file that gets shipped with laravel default installation.
https://github.com/laravel/laravel/blob/master/public/.htaccess
I haven’t change my .htaccess file, but my website can’t be found still, the error always not found(404). What should i do … I am stuck bro
Can you share with me your website url.
My site toyotapetapahan.com
I think, just solved this case bro. I just only clear cache on my browser. And then i can access my site. But i still confuse why i should clear cache
Well, It’s Great! That you’re being able to access your website back.
May want to say install apache2 first
Generally, Shared Hosting providers already keep their Apache and Database ready to use.
This website was… how do you say it? Relevant!!
Finally I have found something which helped me.
Many thanks!
Thanks a lot, after searching nearly a 100 website, just got the answer…
The lack of documentation on shared server literally mesmerizes …
Simple, Concise and Perfect.
Thanks. That means a lot to me. 🙂
Hi Abhishek. Your method does work, but npm is not compiling changes made in javascript. Do you think is because of the separated public app.js ?
Hello Carol Zsolt Domjan,
I hope you’re doing good. This method shouldn’t affect the compilation or installation of any of your javascript file or module.
However, You can still drop the error you’re receiving so I can help.
Thanks.