As a security precaution, my boss has requested I move my Laravel 7 app outside the public_html folder and into private_html.
So my directory structure looks like this:
public_html/public/ private_html/ <-- All the rest of the Laravel core files, app, config, routes, .env, etc.
Now, as expected since I moved the files, I’m getting an HTTP ERROR 500 when I visited the the website.
How do I tell Laravel where my public folder is so can get back to serving my web pages? Which configuration files do I need to edit?
Thanks for any help.
Edit 1: After trying Youssef’s suggestion, everything worked great except when I run
php artisan storage:link
I get:
Edit 2:
I was able to fix “php artisan storage:link” by opening config/filesystems.php and changing:
'links' => [ public_path('storage') => storage_path('app/public'), ],
To:
'links' => [ '/new/directory/public_html/public/storage' => storage_path('app/public'), ],
Then, when I type:
php artisan storage:link
A new symlink is created.
Advertisement
Answer
In public/index.php change path of this two files to current path of them.
first line path of autoload.php
__DIR__.'/../vendor/autoload.php';
to
require __DIR__.'/../../private_html/vendor/autoload.php';
second line path of app.php
$app = require_once __DIR__.'/../bootstrap/app.php';
to
$app = require_once __DIR__.'/../../private_html/bootstrap/app.php';
and put this in the AppProvidersAppServiceProvider
register()
method to set path of public directory.
** * Register any application services. * * @return void */ public function register() { // ... $this->app->bind('path.public', function() { return base_path().'/../public_html/public'; }); }
finally reassign path of storage directory if you need access to stored files directly, using command :
php artisan storage:link
you can also move all files from public_html/public
to public_html
and adjust paths I mentioned above