Search code examples
laravelapachelaravel-8laravel-jetstream

Unable to get the login/register pages with Laravel 8's Jetstream on Apache


I've installed Laravel version 8, and made a project using the --jet flag, I've also run the npm install && npm run dev afterwards, and have also run the migrations successfully(confirmed by the artisan's messages and also looking at my database and seeing the tables there), and also the mydomain.loc is showing me the Laravel's welcome page, but my problem is that the mydomain.loc/register doesn't show the register page, neither does the mydomain.loc/login. Entering these addresses in the browser shows the Apache's 404 page(mod_rewrite is enabled too and I've tried restarting the Apache service as well).

I'm running Apache2 on an Ubuntu 20 virtual machine, and it is serving my Laravel's project in the DocumentRoot /var/www/html/myproj/public. Also the MySQL is running in the VM and I've added its info to both the .env file and the config/database.php, and weirdly everything "seem" to work all fine(Database connection is working... and also the Laravel's welcome page is shown...) except for the login and register pages.

Not sure if it matters, but also since this is only in development, I've done a chmod 777 -R on the project's root too, to make sure it's not a permission thing.

Here is my Apache site's configuration(only the parts that matter for this question):

# nano /etc/apache2/sites-available/mydomain.loc.conf
        ServerName mydomain.loc
        ServerAlias www.mydomain.loc

        DocumentRoot /var/www/html/myproj/public

And here's what I have inside my routes/web.php file:

Route::get('/', function () {
    return view('welcome');
});

Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
    return view('dashboard');
})->name('dashboard');

Solution

  • Sounds like you don't have your site configured correctly for url rewriting (pretty urls). As you should at the least be getting a Laravel 404 error not the web server. Which means rewriting isn't working and it is looking for a file/folder instead of handing off to the index.php file.

    Laravel 8.x Docs - Installation - Pretty URLs