Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change public folder to public_html in laravel 5

I'm using a shared hosting which uses cPanel as its control panel and within the cPanel public_html is the default root directory, because of this I can't get my Laravel application work properly.

Is there any way to make Laravel use public_html instead of public folder?

like image 218
Ravexina Avatar asked May 12 '15 18:05

Ravexina


People also ask

How do I change directory in Laravel?

Add a line to change the default public path ( mix. config. publicPath ), and change the public folder to your desired public folder name in the Laravel mix configuration.

How do you change to public in HTML?

Run rm -r public_html . This command will delete public_html folder and all its contents. Make symbolic link ln -s $(pwd)/laravel/public $(pwd)/public_html . $(pwd) will be substituted with absolute path from root of the server.

Can we change view folder in Laravel?

1 Answer. Show activity on this post. 'paths' => [ realpath(base_path('resources/views')) ], So you might change it to realpath(base_path('public/assets/views')) to be in your public path.

What is public folder in Laravel?

The files and folders in laravels public folder are meant to be web accessible. For security, all other files and folders in the laravel framework should not be web accessible. Moving the index. php to laravels root will break the framework and defy best practices.


1 Answers

Quite easy to find this with a simple search.

See: https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5

In your index.php add the following 3 lines.

/* |-------------------------------------------------------------------------- | Turn On The Lights |-------------------------------------------------------------------------- | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it | will load up this application so that we can run it and send | the responses back to the browser and delight our users. | */  $app = require_once __DIR__.'/../bootstrap/app.php';  // set the public path to this directory $app->bind('path.public', function() {     return __DIR__; }); 

Edit:


As Burak Erdem mentioned, another option (and more preferable) is to put this in the \App\Providers\AppServiceProvider register() method.

/**  * Register any application services.  *  * @return void  */ public function register() {     // ...      $this->app->bind('path.public', function() {         return base_path('public_html');     }); } 
like image 199
Robert Avatar answered Sep 16 '22 12:09

Robert