Laravel Lighthouse-PHP GraphQL (Server cannot be reached)

541 Views Asked by At

I'm using Laravel - Lighthouse-PHP GraphQL server, and when I deploy it to production, I have to write public in the URL in order to work:

My .htaccess contains the following:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

while inside the public folder, there's another .htaccess file, contains the below:

<IfModule mod_rewrite.c>
   <IfModule mod_negotiation.c>
   Options -MultiViews -Indexes
   </IfModule>

   RewriteEngine On

   # Handle Authorization Header
   RewriteCond %{HTTP:Authorization} .
   RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

   # Redirect Trailing Slashes If Not A Folder...
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_URI} (.+)/$
   RewriteRule ^ %1 [L,R=301]

   # Send Requests To Front Controller...
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^ index.php [L]
</IfModule>

I tried editing(or removing) this file, but the whole website stopped working.

Any idea what I'm doing wrong?

1

There are 1 best solutions below

0
On

In your webserver configuration make sure the root directory (the directory that is serving requests) is set tot the public folder instead of the root directory of your app as you have now.

You should only make the public folder publicly accessible, not doing so could result in an attacker to access or execute files they shouldn't or strange errors/behaviour (like what you are experiencing).

I also believe this will also fix the issues you are having since the public folder is not being rewritten which is probably picked up by the Laravel router for some reason.

I don't believe the issue is with Lighthouse but with how you are hosting your Laravel application, try and see if that can be fixed and if the problem persists.