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:
    $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:
    if ($uri !== '/' and file_exists(__DIR__.'/public'.$uri)) {

    To:

    if ($uri !== '/' and file_exists(__DIR__.'/public_html'.$uri)) {

    And change the last line from:

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

    To:

    require_once __DIR__ . '/public_html/index.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:
    var elixir = require('laravel-elixir');

    Add:

    elixir.config.publicDir = 'public_html';

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 thought on “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!

Leave a Reply

Your email address will not be published. Required fields are marked *