Home > Mobile >  Laravel 9 change public() to public_path()
Laravel 9 change public() to public_path()

Time:07-05

I hope you are doing well I am trying to change the public folder to the public_html folder on Cpanel, and it was working fine in local mode on my computer.

I tried these steps.

  1. ./app/AppServiceProvider.php add this code

    public function register(){ $this->app->bind('path.public', function() {
    return base_path().'/public_html'; });}
    
  2. ./config/filesystems.php change public to public_html

     'public' => ['driver' => 'local','root' =>
      storage_path('app/public'),'url' =>
      env('APP_URL').'/storage','visibility' => 'public',],
    
  3. ./webpack.mix.js change public to public_html

     mix.config.publicPath='public_html';
     mix.js('resources/assets/js/app.js', 'public_html/js')
           .sass('resources/assets/sass/app.scss', 'public_html/css');
    
  4. index.php add this code

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

But, I get this error on the site

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

CodePudding user response:

rename your public to public_html

then go to your public_html/index.php and add, just after the line where $app is created:

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

then go to /bootstrap/app.php

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

now you are good to go

CodePudding user response:

I noticed that after running this command

npm run dev // Compile scripts.

It automatically creates a public folder and creates public_html folders and a mix-manifest.json files in it.

enter image description here

If anyone knows, please kindly help. Thankful

  • Related