Search code examples
laraveldeploymentcpanel

How to change public folder to public_html in laravel 8?


I wanna deploy my application on shared hosting on Cpanel where the primary document root has public_html but Laravel project public


Solution

  • You have to follow 2 steps to change your application's public folder to public_html then your can deploy it or anything you can do :)

    1. Edit \App\Providers\AppServiceProvider register() method & add this code .

       // set the public path to this directory
       $this->app->bind('path.public', function() {
           return base_path().'/public_html';
       });
      
    2. Open server.php you can see this code

      if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
         return false;
      }
      
      require_once __DIR__.'/public/index.php';
      

    Just Replace it with :

      if ($uri !== '/' && file_exists(__DIR__.'/public_html'.$uri)) {
       return false;
      }
    
      require_once __DIR__.'/public_html/index.php';
    

    Then serve your application with php artisan serve, you also can deploy it on your Cpanel shared hosting where primary document root public_html