0

Fresh new installation of Laravel 12

composer create-project --prefer-dist laravel/laravel api
cd api
composer update
sudo chmod -R 775 storage
sudo chown -R www-data:www-data storage
sudo chmod -R 775 bootstrap/cache/
vim config/database // set pgsql config options
vim .env // set DATABASE from sqlite to pgsql
php artisan route:clear

This allows me to access the default "/" route. All good. Then I add a second route "/foo" but this creates a 404. Any other route is not picked up either. Example below.

<?php

use Illuminate\Support\Facades\Route;

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

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

Mod rewrite is enable, and .htaccess is the default:

<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}]

    # Handle X-XSRF-Token Header
    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # 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>

The routes appear in route:list

php artisan route:list

  GET|HEAD       / ......................................................................................................................................................... 
  GET|HEAD       foo ....................................................................................................................................................... 
  GET|HEAD       storage/{path} .............................................................................................................................. storage.local
  GET|HEAD       up ........................................................................................................................................................ 

Am I missing the bleeding obvious, or missing a step?

6
  • Did you restart your apache after enabling mod_rewrite? Also, can you describe us your 404 screen? Commented Nov 21 at 0:07
  • Yes, restarted apache Commented Nov 21 at 2:42
  • How about the 404 page, what does it look like? Commented Nov 21 at 4:18
  • Not Found The requested URL was not found on this server. Apache/2.4.58 (Ubuntu) Server at wall.kev Port 443 Commented Nov 21 at 5:34
  • 2
    Now we are sure that this is an apache issue instead of laravel issue. Please share all of your related apache configurations. Commented Nov 21 at 6:14

1 Answer 1

0

Issue seemed to be an apache error, or condition. Rebooting fixed it, but not apache restart.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.