Laravel 5 quick-tip: Change the public directory

Currently I’m converting my Laravel 4 application to Laravel 5. When finding tricks or goofs I will post it to this blog.

One of the first thing I’m doing after installing Laravel is changing the public directory. In Laravel 4 it was pretty straight forward, just edit the bootstrap/paths.php. Unfortunately in Laravel 5 it’s a bit more tricky, but not that hard either.

In my case, I need to rename the public folder to public_html. So everywhere I change public you can change it to the directory you want:

  1. Open public/index.php
  2. Add:
    [php]$app->bind(‘path.public’, function() {
    return base_path() . ‘/public_html’;
  3. Open up server.php from the root directory of your Laravel installation.
  4. Change:

    [php]if ($uri !== ‘/’ and file_exists(__DIR__.’/public’.$uri)) {[/php]


    [php]if ($uri !== ‘/’ and file_exists(__DIR__.’/public_html’.$uri)) {[/php]

    And change the last line from:

    [php]require_once __DIR__ . ‘/public/index.php’;[/php]


    [php]require_once __DIR__ . ‘/public_html/index.php’;[/php]

PHP knows the new public folder. There’s one more thing to do, we need Elixir to tell where to find the assets.

  1. Open gulpfile.js
  2. After:

    [javascript]var elixir = require(‘laravel-elixir’);[/javascript]


    [javascript]elixir.config.publicDir = ‘public_html’;[/javascript]

The only thing to do now, is to rename the folder.

This solution will not work when using php artisan serve. I will create an updated blog post soon.

One Reply to “Laravel 5 quick-tip: Change the public directory”

  1. There is no base_patch() function. It is only base_path(). In spite of this issue works like a charm!

Comments are closed.