Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

danielbrendel's avatar

Proper deployment of a Laravel application (.htaccess, /public)

I am developing an app with Laravel that gets self-hosted by the customer. Now, in my documentation I want to describe how to install the app. My app shall be embedded on websites with, e.g. an iframe. Nonetheless it needs to be hosted most probably on the same webserver. For instance if I have the URL www.example.com/ticketsystem the "ticketsystem" is the root project directory. How can I now route every request in that directory to the /public directory? I tried some .htaccess files but everyone I got there was the public folder name in the URL. I want to hide the public directory name in the URL and also don't want users have access to everything except the public folder. My question now is: Do I have to achieve that entirely with an .htaccess file (how?) or do I have to instruct the user to redirect requests of the project root to the public folder via his server control panel?

0 likes
4 replies
bobbybouwmann's avatar

You need to point the webserver to the public directory. You can't put the .htaccess file in your root directory and make it work.

Laravel already comes by default with a .htaccess file in the public directory that works ;) The only thing you need to do on the server is pointing the domain to the public directory of your project.

It depends on the server on how you need to do this. This can be nginx or plesk or some other tool that can do this for you.

bobbybouwmann's avatar

@jlrdw Those are good guides for shared hosting indeed. It depends on hosting of the OP on what answer should work here.

jlrdw's avatar

@bobbybouwmann thanks for the reply, good to know. And @danielbrendel as said, as long as "main laravel app" is secured, not exposed to the World.

You do not want to view:

site/.env

Please or to participate in this conversation.