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

Moonatic89's avatar

Laravel deploy (public issue)

Hello! I have an issue on which i could really use some help. I have this laravel project that i have to deploy, i've searched a lot for answers, what i came to was create a folder structure like this: (sorry if i'm messing up with folder tree visuals)

-main folder

-laravel

-public_html

    -cs

        -index.php

Inside the index.php there are direction like /../../laravel/vendor/autoload.php', which actually brings to my login page. Issue 1: every link is broken (i use Inertia, if that can helps), pointing to a 404 error. Issue 2: My url link somehow is "doubled" like this -> domain/cs/index.php/cs/index.php/login

So, if i type domain/cs it redirects to domain/cs/login (as it is supposed to do, since there is an auth middleware), but the page is a 404. If i type domain/cs/index.php, it redirects to /cs/index.php/login and IMMEDIATLY to domain/cs/index.php/cs/index.php/login showing the login page. Lastly, if I manually enter domain/cs/index.php/cs/index.php/login as a domain, again a 404 error. It's like 4 days since i've started try, i'm pretty desperate.

0 likes
16 replies
Snapey's avatar

Do you need this to run in a sub-folder (not recommended) ?

2 likes
Moonatic89's avatar

Yes, it is a sub-folder. The reason why Laravel's public folder is in a folder itself inside of -cs is because there is another index.php related to the main domain.

Snapey's avatar

@Moonatic89 You will have a lot of problems arising from running in a folder.

Could you use a subdomain instead?

2 likes
Moonatic89's avatar

@Snapey I may ask, there shouldn't be a problem about this.

EDIT: Ok, so i created a new subdomain. But, this subdomain folder is INSIDE of main domain public_html folder...shouldn't this lead to security issues?

Moonatic89's avatar

Hi! Me again. The domain I using dosen't have NGINX, and i've tried to upload my app via SSH to a subdomain. With some trials and errors i've reached laravel folder within the Index.php in public_html, but even if the files routes are correct (i've put an echo on each of the files i have to reach) i always return a 500 error. Am i missing something else? Thank you

jlrdw's avatar

@Moonatic89 If using Apache, you still point to public as document root, then everything will work.

2 likes
Moonatic89's avatar

yeah, it seems so. I peeked in the larvel log, and after a bit it still gives me 500 error, but now because i don't have nodejs installed in the domain. This unfortunately isn't a thing i can do, we asked the providers and we just have to wait, i guess. I'll keep you updated, thank you.

Snapey's avatar

@Moonatic89 why would you need node.js installed? Compile your assets locally then copy them to the server

1 like
Moonatic89's avatar

True, i didn't think about that, though it was obvius :/ Anyway, Im here again with the same problem but with some new details.

If i leave my app.blade.php as it is, with link href="{{ mix('css/app.css') }}" rel="stylesheet" (and so on for manifest, vendor and app) i only see a white page (with every html line i eventually want to write), and with an error in console (net::ERR_ABORTED 404), one for every link mix provides.

The link provided with the console error is domain.name/js/manifest.js? (with the same file id i found on mix-manifest), but i accessed that file forcing the url domain.name/subdomain/js/manifest.js. This is valid for every file.

But, if I try to modify directly the href in php.blade file, it outputs that is unable to locate Mix file.

Again, if i try to swap mix with asset, the login page that is supposed to show is shown, but with a duplicate path in the url (domain/subdomain/index.php/subdomain/index.php/login), and everything else is broken, like if i refresh the page it gives 404 error, i can only access that url typing domain/subdomain/index.php.

I know that is probably something really stupid, but this is the first project i'm deploying and it's driving me nuts.

Thank you, i hope i've described the situation clearly

jlrdw's avatar

@Moonatic89 What is your folder structure? Are you able to do a virtual host. If not there are htaccess rules to still point to public as document root. You can also have a look at:

http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/

Which I've used for shared hosting. But you do have an issue where something is not properly pointing to something correctly.

On local what do you use apache or nginx?

Another option is use a host like digital ocean where you can properly setup laravel. But I have some on shared host with no problems.

2 likes
Moonatic89's avatar

@jlrdwThis is my folder structure:

domain/my_app/my_app files

domain/public_html/my_app_public/my_app_public files

Index.php in public folder is linked correctly, if i echo a string in index.php (in public) and in app.blade.php (in my app/resource/view) i can see both. Also, i think that Inertia is loaded correctly, as i dont see @Inertia string in app.blade.php. config/app is also configured.

I have never used a virtual host, and on local i use apache.

I cannot change my host, since i'm not the one in charge, it's suppose to be a site to support another one on the main domain (that is the reason why i need a subfolder in public_html, there are the public files of main domain.

Another thing to note is, I tryed uploading the same project directly in a public folder, so without the concern of redirecting any file at all: it dosen't work. (same problem of blank file with errors in console)

jlrdw's avatar

@Moonatic89

I have never used a virtual host, and on local i use apache.

How then did you correctly point to public as document root without setting up a virtual host?

Did you use an .htaccess alternative?

But either way, if you get the folder structure correct and point to public as document root all will work correctly.

1 like
Moonatic89's avatar

@jlrdw Oh, yeah. So it seems that i use a virtual host without knowing it :/ I lack some knowledge about it. I will try with a correct .htacces and with his alternative.

Moonatic89's avatar

Hello everyone. After another week without success, i made a new project without Inertia and it somehow worked. I've developed a basic app, and i was about to deploy it when again i hit a wall.

While now i can see my optimal layout, every api is broken (like, it should be domain/subdomain/api and is domain/api). I've checked thrice that i've update Subdomain Document Root, and it SHOULD be correct. I've submitted a ticket to our host to know if there is any kind of problem about it. if i try to hard write the API on url, it works.

Since every API is broken, even auth isn't successfull, so i'm stuck to the login page.

Another thing to note is that instead of being domain/subdomain/login, the first page loaded is domain/login, again returning a 404 error if I try to reload the page. The main domain is occupied and the site is on use, so i'm a bit afraid of get rid of auth for testing vue routes purposes, but i can do that if requested. I've tried many changes like on cors, RouteServiceProvide, even writing hard coded api.

On the main domain there is a Joomla site which i cannot replace in any manner (i'd love to deploy my application on that domain, even redoing the site from scratch, if that could be solving my problem). On this site there is a plugin to translate automatically pages in different languages, so as a result, some urls of my subdomains changes to doman/index.php/lang (that can be en, de, es, it, whatever). This made me think of an .htaccess problem.

I tried also write some gibberish on .htaccess and it invalidates my site, so the file is read upon loading. I didn't check if rewrite rules are allowed, i'm still trying to figure out how. (htacces is a great hole in my knowledge, as deploying in general)

Many, many thanks to whoever can help me figure out how to proceed.

Moonatic89's avatar

I think I found somethng. All the issues are caused by the main domain htaccess file, there is a rule that force redirection for everything below that domain, so everything i try is being redirect. i tried to remove that rule, and my site magically works. The problem is, i cannot permanently remove the rule since the domain is currently in use and it would break. I guess i will start studying some htaccess D:

Please or to participate in this conversation.