Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ralee's avatar

Laravel public path same level as base path

Hi everyone,

I am wondering if its possible to link my public path to a folder on the same level as my base_path/the root directory of my Laravel Application?

I am doing so because my current server is a shared server and I have to separate my public folder and store its file into the public_html folder.

I have done the necessary configuration on my index.php to have the site up. But unfortunately my public_path() is /home/vagrant/Code/Website/public_html instead of /home/vagrant/Code/public_html.

Your help will be much appreciated!

Thanks in advance. Thomas

0 likes
6 replies
khaledSMQ's avatar

Hi,

I think you can do move the file from "Laravel/public/." to you "/public_html/" Then update index.php

require __DIR__.'Laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'Laravel/bootstrap/app.php';

1 like
bestmomo's avatar

Hi,

You must update index.php as said above.

But as "public" is hard coded in application.php you must change it in a provider :

App::bind('path.public', function() {
    return base_path().'/public_html';
});

At last you have to protect all other folders.

3 likes
ralee's avatar

Hi @bestmomo,

I still cant figure out how this works. I tried adding 'public_html' to AppServiceProvider register() function " public function register() "

{
        $this->app->bind(
            'Illuminate\Contracts\Auth\Registrar',
            'App\Services\Registrar'
        );
        $this->app->bind('path.public', function() {
            return base_path().'/public_html';
        });
}

But when i call return public_path in my view i am getting home/vagrant/Code/website/public_html instead of home/vagrant/Code/public_html. Can you please advice me?

Cheers Thomas

bestmomo's avatar

I think I dont really understand what you want to achieve.

datagoniaweb's avatar

khaledSMQ's solution worked for me but I also had to move the index.php file up from the /up_one_level/public folder to the /up_one_level folder. Also, had to remove an ill-advised .htaccess from that /up_one_level folder. So index.php should be up a level from /public. Hope this helps because I spent a good week or so trying to find the correct solution. Lord knows Apache is a TERRIBLE program, in my opinion and I will be staying very far away from it in my future endeavors.

Please or to participate in this conversation.