ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Changeable public directory name

Open isaeken opened this issue 4 years ago • 5 comments

/app
/bootstrap
/database
.
/public_html <-- refactored from /public
/resources
.

easiest usage for shared hostings.we change the directory name in .env like APP_PUBLIC_DIR=public_html

isaeken avatar Dec 14 '20 17:12 isaeken

Wouldn't a symbolic link work for the shared hosting scenarios you mentioned?

paras-malhotra avatar Dec 17 '20 15:12 paras-malhotra

Some providers prevent the creation of symbolic links but a good solution and a public:link command like storage:link can be added.

isaeken avatar Dec 17 '20 17:12 isaeken

You can do this by overriding the path.public instance in the container. You will probably need to register it in bootstrap/app.php or a bootstrapper that's called by the kernel (check the Kernel.php files provided by laravel for more info).

$app->instance('path.public', base_path('public_html'));
❯ php artisan tinker
Psy Shell v0.10.4 (PHP 7.4.13 — cli) by Justin Hileman
>>> public_path()
=> "/Users/matt/code/laravel/public_html"

matt-allan avatar Dec 18 '20 22:12 matt-allan

yes i know but the shortcut would be nice and it would increase portability

isaeken avatar Dec 20 '20 15:12 isaeken

You can do this by overriding the path.public instance in the container

Even that's not good enough, am I right? Other core files still need to be changed:

  • <public folder>/index.php needs to be edited to require() the right paths
  • <project root>/server.php needs to be edited to require() the right paths

What's more, some projects might want different configurations for local dev vs. test/live deployment:

  • On local dev computer developers might prefer the original Laravel application layout, with the original index.php & server.php PHP require()s
  • Only on web deployment is it needed to be in altered public folder layout with altered index.php/server.php PHP require() paths

It would be great if this can be adjusted from .env (though how? this alteration is so early in the boot process dotenv isn't even loaded..) perhaps indeed a command similar to storage:link

kingIZZZY avatar May 26 '21 12:05 kingIZZZY