How to remove public from laravel 5.4

Published 6 months ago by Imamul.Hossain

I'm learning laravel 5.4. I want to remove public from url. If I move .htaccess and index.php to root folder, no css or js is found. What can I do now?

Best Answer (As Selected By Imamul.Hossain)
samalapsy

There's no need to copy index.php fro myour public folder, just copy only your .htaccess file to the root folder and also change your server.php in the root file to index.php

Thanks

samalapsy

There's no need to copy index.php fro myour public folder, just copy only your .htaccess file to the root folder and also change your server.php in the root file to index.php

Thanks

Ricardo

@imamulhossain you shouldn't remove the public directory; you should use your .htaccess to rewrite it. Check for mod rewrite, it is Apache business not Laravel's

Snapey
Snapey
6 months ago (647,435 XP)

NO!!! The best practice is to set your document root to your public folder

jlrdw
jlrdw
6 months ago (196,140 XP)

Why can't you just install laravel correctly, I even install this way in development. http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/

Main files above htdocs and public in a subfolder under htdocs. I have a production site on godaddy using laravel 5.1. I have never had any problems.

@Snapey I figured you would reference this article sometimes.

Edit: @Snapey has covered security and the .env file on numerous post and the dangers of an in-proper install.

dharmendrajadon

You should not remove public from project.

On your hosting, add AddOn domain and give path as:

path: domain_root_folder/public/

You domain will be propagated as www.example.com instead of www.example.com/public/ 
Snapey
Snapey
6 months ago (647,435 XP)

As you have marked bad practice as best reply, do yourself a favour and just check that .env is not accessible by the world yourdomain.com/.env

jlrdw
jlrdw
6 months ago (196,140 XP)

@Snapey with all the previous post on proper installation, plus other sites with tutorials like I mentioned above, and people still refuse to do a proper install. Makes you wonder.

I hope other new to laravel folks scroll down and do not use this best answer, could be bad for security.

Imamul.Hossain

@samalapsy I tried it several times, but no css or js is found.

@Snapey could you show me the proper ways, please please....

Finally, many many thanks to those persons who have come forward to help me......

jlrdw
jlrdw
6 months ago (196,140 XP)

@Snapey could you show me the proper ways, please please....

For crying out loud, I gave a link that has step by step instructions, really? And worse yet it is @Snapey that's in the tutorial. You couldn't at least read through the tutorial?

Imamul.Hossain

@jlrdw I visited the link you provided......... and thanks for your courtesy..........

jlrdw
jlrdw
6 months ago (196,140 XP)

@Imamul.Hossain installing laravel as in that link should get you all fixed.

samalapsy

@Imamul.Hossain ensure your use

{{ asset('path to css or js')}}

//OR

{{ url('path to css or js') }}

PLEASE only place the content of your public file in the public_html folder for security reason...Else your .env file would be easily accessed. Just like @Snapey said....

PLEASE PLEASE PLEASE

Please install your Laravel Files on your server root Folder. Thanks

Please sign in or create an account to participate in this conversation.