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

dedadev's avatar

Laravel 9 shared hosting deployment

Hi everyone, I need to deploy Laravel 9 on a shared hosting, I know that there are many other threads on the forum about this subject but I can't find one that can help me with my actual Laravel version/hosting configuration. The hosting doesn't have a /public_html folder that I can use as the standard /public like I saw in other threads and, because I'm using version 9, there is no server.php in the root to edit.

I could really use some help with this, thank you in advance for your support.

Bye

0 likes
14 replies
kokoshneta's avatar

What folder does your server have for uploading files that can be opened in a browser (known as the document root)? Do you have any access to folders outside the document root?

If you don’t have access to anything outside the document root (which is not uncommon with shared hosting), don’t deploy Laravel apps to that hosting.

dedadev's avatar

Hi @kokoshneta, thank you for your reply. I can confirm that I don't have any access outside the document root, I can only add files/folders inside it. Is there any workaround? I know that this type of deployment is discouraged but at the moment we can't use another hosting.

Thank you again

Bye

kokoshneta's avatar

@dedadev Unfortunately, there is no way to safely deploy a Laravel app if you do not have access to any folders that are not viewable by the world. Things like .htaccess files can go some way towards plugging the worst of the security issues, but without folders outside the server software’s remit, you can’t plug them all.

Lara_Love's avatar

you want place your site on the host cpanel ?

dedadev's avatar

@LoverCode Hi, nope, we don't have cpanel on the host, just a web gui with a file manager and ftp access to the document root.

dedadev's avatar

@dysentry30 Thank you but as I said before we don't have a public_html, just a single document root

jlrdw's avatar

@dedadev if you read the deployment documentation there's actually an nginx example right in the documentation.

Tray2's avatar

It's actually quite simple.

  1. Change your document root to <old_document_root>/public if possible.
  2. If you can't change the document root, and you are running apache, create a ,htaccess where you rewrite any requests to the /public directory. You also need to make sure mod_rewrite is enabled. I have shared the .htaccess that I use in several threads here.
  3. For nginX you need to ask someone else.
dedadev's avatar

@Tray2 Thank you, I've found your htaccess:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/public 
Rewriterule ^(.*)$ public/ [L]

however now for every asset(pathtoresource) I need to add public/ like this:

asset(public/pathtoresource)

otherwise the specified resource is not reachable (404)

Is it right or I'm doing something wrong?

Thank you again

Bye

Thank you

jlrdw's avatar

@dedadev you can try:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^ [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/ 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php

I have used with success. But still leave the original htaccess in public as is.

Please or to participate in this conversation.