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

xitec's avatar

Laravel 5.1 - Change name and location of public folder

Hello,

this question might be asked before, but I can't figure out how to change the name AND the location of the Laravel public folder. I'm on a shared host and placed the laravel folder below my hostingproviders webroot for security reasons.

The folder structure on the server is like this:

  • |_ bin
  • |_ conf
  • |_ ...
  • |_ usr
    • |_ laravel
      • |_ app
      • |_ bootstrap
      • |_ ...
  • |_ www

The usr/laravel folder is where I placed Laravel. The www folder is my hostingproviders public root folder. I want to use this folder as Laravel's public folder. However, the name "www" cannot be changed.

I tried to change the public/index.php file to this:

require __DIR__.'/../usr/laravel/bootstrap/autoload.php';

But this doesn't seem to work. Does anyone know a solution?

Thanks in advance!

0 likes
8 replies
fideloper's avatar

If you can create a symlink (you might not be able to, but perhaps you can!) youcan try that route instead of moving laravel folders around.

ln -s /path/to/laravel/public /path/to/www

Note that this command might fail if the www directory already exists. You can try deleting it or naming it something other than "www", then using the symlink to create the faux-www directory ("faux" because it's fake, it points to laravel's public directory).

1 like
xitec's avatar

Thanks for your suggestion fideloper. Unfortunately I don't have shell access on the server or other options to create symlinks. Is there any other way to change the name and location of the Laravel-public folder?

sid405's avatar
sid405
Best Answer
Level 27

@xitec Of you're right about that, it's been asked and answered many many times.

Anyhow

  1. The index.php is fine.
require __DIR__.'/../usr/laravel/bootstrap/autoload.php';
  1. If you don't have access to do what @fideloper suggested create app/MyApp.php
<?php namespace App;

use Illuminate\Foundation\Application;

class MyApp extends Application  
{
    public function publicPath()  
    {
        return $this->basePath.DIRECTORY_SEPARATOR.'www';
    }
}

And then in bootstrap/app.php comment out the default application and replace it with your own

// $app = new Illuminate\Foundation\Application(
//  realpath(__DIR__.'/../')
// );

$app = new App\MyApp(
    realpath(__DIR__.'/../')
);

Remove the compiled.php file if you have one and make sure to find a way to dump the autoloader as well

You should be good to go

3 likes
Snapey's avatar

when you say it doesn't work, what happens? there can be several reasons for a white screen. Your path may indeed be correct.

xitec's avatar

@Snapey I got an error 500 (internal server error). After checking the error.log file on my server, it says that "Option MultiViews not allowed here". I solved this by modifying the .htaccess that ships with Laravel.

@sid405 Thanks a lot, this solved my problem! Below I'll post the exact steps I took to make it work.

xitec's avatar

This is what I did to change the name AND location of the public folder in Laravel 5.1:

Step 1: Edited these 2 lines in public/index.php to the following:

require __DIR__.'/../usr/laravel/bootstrap/autoload.php';

$app = require_once __DIR__.'/../usr/laravel/bootstrap/app.php';

Note that I also edited the $app path. It now points to the same location as the line above it (my Laravel root folder).

Step 2: Created app/MyApp.php with the content that sid405 wrote:

<?php namespace App;

use Illuminate\Foundation\Application;

class MyApp extends Application  
{
    public function publicPath()  
    {
        return $this->basePath.DIRECTORY_SEPARATOR.'www';
    }
}

Step 3: In bootstrap/app.php commented out the default application and replace it with:

// $app = new Illuminate\Foundation\Application(
//  realpath(__DIR__.'/../')
// );

$app = new App\MyApp(
    realpath(__DIR__.'/../')
);

Step 4: There wasn't a compiled.php file present in my Laravel project, so no action taken there. About dumping the autoloader.. I'm unable to run composer on my production server, so I executed the following command on my localhost:

composer dump-autoload -o

Step 5: Uploaded the entire Laravel folder via FTP to the production server and made sure that the contents of the /public/ folder are located in my hosting providers public root. After navigating to www.mydomain.com I got an error 500 (internal server error), but this was solved by using Laravel's alternative .htaccess:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

I hope these steps are a correct and complete solution for changing the name and location of Laravel's public folder. However, any additional feedback is highly appreciated.

1 like

Please or to participate in this conversation.