Avoid Public Folder of Laravel and Open Directly the Root in Web Server

Avoid public folder of laravel and open directly the root in web server

Let's assume you have this folder structure in your server

.cpanel/
public_html/
public_ftp/
..

And the laravel folder structure is

app/
bootstrap/
public/
vendor/
composer.json
artisan
..

You can create a folder name mylaravelsite on your server inline with public_html and public_ftp folder, and copy to it the whole laravel application except the public folder because you will paste all of it contents on the public_html, so you have now:

.cpanel/
public_html/
public_html/packages
public_html/vendor
public_html/index.php
public_html/.htaccess
...
public_ftp/
mylaravelsite/
mylaravelsite/app
mylaravelsite/bootstrap
...

On your public_html/index.php change the following line:

require __DIR__.'/../bootstrap/autoload.php';

$app = require_once __DIR__.'/../bootstrap/start.php';

to

require __DIR__.'/../mylaravelsite/bootstrap/autoload.php';

$app = require_once __DIR__.'/../mylaravelsite/bootstrap/start.php';

and also don't forget to change /mylaravelsite/bootstrap/paths.php public path, you might use it.

'public' => __DIR__.'/../public',

to

'public' => __DIR__.'/../../public_html',

Your site should be running.

How to run laravel in root directory without the public folder?

That is not your problem, you need to point the virtual host to the public folder.

How to run Laravel from root directory, not from public?

•Go to mainproject/public>>

a.  .htacess
b. favicon.ico
c. index.php
d. robots.txt
e. web.config

1.cut these 5 files from the public folder, and then paste on the main project folder that’s means out side of public folder… mainproject/files

2.Next after paste ,open index.php ,modify

•require __DIR__.'/…/bootstrap/autoload.php';  to
•require __DIR__.'/bootstrap/autoload.php';

  1. modify

    $app = require_once DIR.'/../bootstrap/app.php'; to

    $app = require_once DIR.'/bootstrap/app.php';

you can also watch this video for better understanding----------------

https://www.youtube.com/watch?v=GboCYqEbKN0

Laravel 5 – Remove Public from URL

For Laravel 5:

  1. Rename server.php in your Laravel root folder to index.php
  2. Copy the .htaccess file from /public directory to your Laravel root
    folder.

That's it!

how to access website from a sub folder inside the root folder?

I found a solution to this question.

1.Copy all the laravel files inside the public_html folder including the .htaccess file and the index.php file which is suppose to be inside the public folder(keep both the files inside the public folder).

2.Then link your storage to the public folder using SSH, for that open your SSH enter id and password and change directory using "cd domains/yourdomainname.com/public_html"
then give the php artisan command i.e "php artisan storage:link"
(note:- after changing the directory you can give all the php artisan commands like migrate and config:cache or clear:cache as you wish.

3.Now after the all the necessary commands are given you can access your fully functional website including the image display function if you type yourdomainname.com/public on the URL but if you type just your domain name then all the laravel files will appear on the browser to avoid this and to to jump inside the public folder directly create one more .htaccess file outside the public folder but inside the

public_html folder the copy the below given code and then if you just your domain name on the URL then your website will be directly displayed

Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ public [L]


Related Topics



Leave a reply



Submit