As the final task of my university practice, we need to deploy our Laravel project to the university server.
When I SSH into the machine, I land in my home directory, which only contains a public_html
directory (and this root directory is not writable). I’ve placed all the Laravel files inside that directory, so the structure looks like this:
public_html
|- .env
|- .htaccess
|- app
|- bootstrap
|- composer.json
|- public
|- resources
|- routes
|- storage
|- vendor
Since there’s no index.php
directly inside public_html
, I added a .htaccess
file to redirect everything to public/index.php
:
RewriteEngine On
RewriteRule ^$ public/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ public/index.php [L]
With this setup, I’m able to access Laravel by visiting:
https://<university domain>/~dramosac
However, Laravel treats ~dramosac
as part of the requested route, which doesn’t exist, so it returns a 404 error.
To debug this, I updated the 404 page to show some request details:
<pre>
Requested URL: {{ request()->fullUrl() }}
Internal path (request()->path()): {{ request()->path() }}
APP_URL: {{ config('app.url') }}
Current route name: {{ Route::currentRouteName() ?? 'None' }}
Current controller: {{ optional(Route::getCurrentRoute())->getActionName() }}
Authenticated?: {{ Auth::check() ? 'Yes' : 'No' }}
HTTP Method: {{ request()->method() }}
</pre>
The output is:
Requested URL: https://<university domain>/~dramosac
Internal path (request()->path()): ~dramosac
APP_URL: https://<university domain>/~dramosac
Current route name: None
Current controller:
Authenticated?: No
HTTP Method: GET
As you can see, Laravel thinks ~dramosac
is the internal path, even though I set the correct APP_URL
in the .env
file.
Question:
Why does Laravel still treat ~dramosac
as part of the route, even though APP_URL
is set correctly? How can I configure Laravel to serve the correct routes from this subdirectory?
Thanks in advance!