Skip to content

Instantly share code, notes, and snippets.

@johanvanhelden
Last active March 18, 2023 13:16
Show Gist options
  • Save johanvanhelden/29096a9ff31eac9b039d36056919abbb to your computer and use it in GitHub Desktop.
Save johanvanhelden/29096a9ff31eac9b039d36056919abbb to your computer and use it in GitHub Desktop.
Laravel - public > public_html

These are the reconfiguration instructions to make Laravel use a public_html folder instead of a public folder.

  • Rename the public folder to public_html

  • Create a new file in de ./app directory called Bootstrapper.php with the followign contents:

<?php

namespace App;

class Bootstrapper extends \Illuminate\Foundation\Application
{
    public function publicPath()
    {
        $path = $this->basePath . DIRECTORY_SEPARATOR . 'public_html';

        return $path;
    }
}
  • In the ./bootstrap/bootstrapper.php file, use this new bootstrapper like so:
$app = new \App\Bootstrapper(
    realpath(__DIR__ . '/../')
);
  • In the ./app/Providers/AppServiceProvider.php's register() method, bind the public_html directory to the container, like so:
$this->app->bind('path.public', function () {
    return base_path() . '/public_html';
});
  • If you are using Laravel Mix, you need to also bind the public folder in the webpack.mix.js file like so:
mix.setPublicPath('public_html');
if ($uri !== '/' && file_exists(__DIR__ . '/public_html' . $uri)) {
    return false;
}

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

These are the instructions to make a custom Dockerhero vhost for the public folder.

  • Grab a copy of the latest localtest.me vhost from this url: https://github.com/johanvanhelden/dockerhero-nginx/blob/master/.conf/includes/localtest.me.conf

  • Save the file to: ./dockerhero/nginx/conf/laravel-public.conf (the exact filename does not matter)

  • In the new file, replace public_html with public

  • Either: replace localtest.me with another domain that points to your localhost (127.0.0.1). For example: fuf.me (please use Google to find alternatives). -- Or alternatively, set up your /etc/hosts file to make a custom projectname.domain.com point towards your localhost. -- Or, another alternative, is to use a service like dnsmasq to set up a local wildcard.

  • Restart Dockerhero

  • Use the new domain to visit your projects. For example: testproject.fuf.me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment