Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make public folder as root in Laravel?

Tags:

php

laravel

I use Laravel framework. As you know, its directory looks like this:

enter image description here

To open the homepage of my website (Route::get('/', 'HomeController@index');) I need to open /public folder of directory. In other word, to see the first page of my website, here is the URL:

http://example.com/public

anyway, only my domainname (http://example.com/) isn't my root. How can I make /public folder as root?


Curently I've found a workaround. I can create an index.php on the root and write a redirect code to /public folder. So when user enters http://example.com/, it will be redirected to http://example.com/public automatically. But still that's ugly. I don't like to see /public in the URL. Any suggestion?

like image 512
Martin AJ Avatar asked Nov 23 '16 05:11

Martin AJ


People also ask

How do I change the root path in laravel?

./config/filesystems.Modify the section 'public' to change the 'root' value 'app/public' to your desired location, for example, app/public_html ( app is an alias of your root folder).

Where is the root directory in laravel?

By default in the Laravel app core, this directory is namespaced under App and it is autoloaded by Composer using the PSR-4 autoloading standard. The app directory has a variety of additional directories such as console, http, and providers.

What is root in laravel?

Root is an admin package for Laravel applications.

What is the use of 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

Do not mofidy any Laravel files. Use web server (Apache or Nginx) to point Laravel project to public directory.

For Apache you can use these directives:

DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">

For nginx, you should change this line:

root /path_to_laravel_project/public;
like image 136
Alexey Mezenin Avatar answered Oct 17 '22 05:10

Alexey Mezenin