DEV Community


Linking public_html to laravel public directory in shared hosting

Md. Hazzaz Bin Faiz
I am a student. Love to learn and share knowledge.
・1 min read

Putting laravel application in public_html directory is a very dangerous.

User should land on public directory.
If you can edit the document root, update it from /home/user/public_html to /home/user/public_html/public

But some shared hosting provider forbids updating document root of main domain.

Some people stores application to other directory and copies the index.php file from public directory and update path.
It works fine, but if you are serving asset like css and js files from server and try to deploy updates by git, your server will server old contents unless you copy latest assets to public_html directory.

There is another trick, to do it and your assets will remain update to original asset and no need to copy index.php file.

Let's assume that you have laravel application in /home/user/laravel directory.

SSH to your server and cd to home by cd ~.

Back up public_html directory if you have any important file in it.

Delete public_html directory by running rm -rf public_html.

Now create a symbolic link with name public_html point to your laravel applications public directory by running
ln -s /home/user/laravel/public/ public_html

Now the public_html is just a symbolic link of your applications public directory.

If anything change in your applications public directory, it will immediately available for user.

Have Fun 🎉 !!!

Discussion (0)

Forem Open with the Forem app