Deploy Laravel to Shared hosting and change public folder to public_html

Published on Jul 24, 2022

If you need to deploy your application to shared hosting, you have to figure out if the public_html folder is the default folder of your domain. If you have shared hosting, the domain root folder is usually public_hml folder and if you have a private server or cloud hosting then it will normally be called public folder. It depends on the server config but generally, you have two options, the first option is detailed in the following blog post, or the second option is to change the laravel public folder to read the index.php from the public_html folder. In the following, I will detail the second option.

You should do 2 things. First, in this file AppServiceProvider.php add the following code to the register function:

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

It will override the basic public path.

The second thing you need to change is your webpack.mix.js file setting to generate your assets to the public_html.
Add the following part to the mix section:

mix.setPublicPath('./public_html/');

Don't forget to remove your previously set public folder paths from the mix.js or mix.scss sections.

For example change the code to this: mix.js('resources/js/site.js', 'public/js') to this mix.js('resources/js/site.js', 'js').