How to deploy Laravel App on Shared Hosting.

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.

Laravel Shared Hosting Deployment.
Laravel Shared Hosting Deployment.

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';


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.

Laravel Shared Hosting Deployment - Index.php
Laravel Shared Hosting Deployment – Index.php

Next, proceed and do the exact same thing for the line that says.

$app = require_once __DIR__.'/../bootstrap/app.php';


$app = require_once __DIR__.'/../demo/bootstrap/app.php';

Make sure to replace the demo with your project name.

Laravel Shared Hosting Deployment - Index.php
Laravel Shared Hosting Deployment – Index.php

Once done, we need to explain Laravel application about the new path of the public directory that we want to set is public_html. That can be achieved by adding the code below right after the application is bootstrapped on line number 39 in index.php.

$app->bind('path.public', function() {
    return __DIR__;

After making the above changes the code inside the index.php file would look something like this.

Laravel Shared Hosting Deployment - Index.php
Laravel Shared Hosting Deployment – Index.php

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.

Laravel Shared Hosting Deployment - Server.php
Laravel Shared Hosting Deployment – Server.php

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.



  1. Bhaswanth Chittanoor December 15, 2018 at 4:55 am

    Awesome post bro and easy to understood

  2. Josh Kisb April 18, 2019 at 9:16 am

    I don’t see why you need to change server.php on shared hosting

  3. Ucok Pasaribu April 21, 2019 at 2:25 pm

    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

    1. Abhishek Prakash April 21, 2019 at 3:05 pm

      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.

      1. Ucok Pasaribu April 21, 2019 at 3:14 pm

        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

          1. Ucok Pasaribu April 21, 2019 at 3:38 pm

            My site

          2. Ucok Pasaribu April 21, 2019 at 3:38 pm

            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

          3. Abhishek Prakash April 21, 2019 at 3:47 pm

            Well, It’s Great! That you’re being able to access your website back.

          1. Abhishek Prakash - Site Author May 15, 2020 at 7:02 am

            Generally, Shared Hosting providers already keep their Apache and Database ready to use.

  4. January 23, 2020 at 11:27 am

    This website was… how do you say it? Relevant!!
    Finally I have found something which helped me.
    Many thanks!

  5. Ajay February 8, 2020 at 6:51 pm

    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.

    1. Abhishek Prakash - Site Author February 8, 2020 at 7:06 pm

      Thanks. That means a lot to me. 🙂

  6. Carol Zsolt Domjan March 29, 2020 at 9:09 am

    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 ?

    1. Abhishek Prakash - Site Author March 29, 2020 at 1:27 pm

      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.


  7. Jordan November 13, 2020 at 7:00 pm

    Thanks a bunch for sharing this with all people you really realize what you are speaking
    about! Bookmarked. Kindly additionally consult
    with my site =). We can have a link trade arrangement between us


Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.