aknEvrnky's avatar

How to change public path on Laravel 10.x

Hi guyz, in early versions of laravel, it was easy to change default public path. I was editing the line in server.php file:

require_once __DIR__.'/public_html/index.php';

But in laravel 10, there is no server.php file and even though I bind the 'path.public' to container, laravel throws error and server is never being initialized. What I tried is:

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

What error I got when I try to initialize artisan server is:

The provided cwd "C:\Users\evren\Desktop\hello-world\public" does not exist.

For conclusion, my app was able to use public_html as public path in laravel 9 but when I upgraded base code to laravel 10, my app could not use public_html longer.

Some usefull dd's:

> public_path()
= "C:\Users\evren\Desktop\hello-world\public"

> app('path.public')
= "C:\Users\evren\Desktop\hello-world\public_html"

0 likes
7 replies
ecollado's avatar

I had the same problem. Using this in bootstrap/app.php worked for me:

$app->usePublicPath(base_path('public_html'));
6 likes
ethar's avatar

@ecollado i add your code in app.php but not working ''' $app->singleton( Illuminate\Contracts\Http\Kernel::class, App\Http\Kernel::class );

$app->singleton( Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class );

$app->singleton( Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class );

$app->usePublicPath(base_path('public_html')); '''

puresoft's avatar

@mask477 i added this code $app->bind('path.public', function() { return base_path('public_html'); }); but still not running . any way to change it?

kyobul's avatar

@ecollado Add it rather in the register method of AppServiceProvider instead of bootstrap/app.php

Snapey's avatar

far easier to make a symlink. You are then also not messing up your local dev environment

Please or to participate in this conversation.