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

emeryinca's avatar

Laravel Routes returning 404 for every single thing

Hey all, I'm really struggling here and spent hours trying to debug this

here's my route:

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;

Log::info("Route started");
$controller_path = 'App\Http\Controllers';
Log::info('Current route', ['route' => Route::currentRouteName()]);

Route::get('/', function (Request $request) {
  Log::info('Request data', ['request' => $request->all()]);

  // your route logic
});


// Main Page Route

Route::get('/your-route', function (Request $request) {
  Log::info('Request data', ['request' => $request->all()]);

  // your route logic
});

//migrate
Route::get('/migrate', [App\Http\Controllers\MigrationController::class, 'migrate']);

Route::fallback(function () {
  Log::info("Fallback route hit. Request details:", request()->all());
  return view('404');
});

You'll notice the ton of debug lines and I've removed almost every other route for testing, when they were there everything got a 404 as well

Here's the story: Everything runs fine locally running in docker, however as soon as it gets sent to run on google cloud run by google cloud build I get 404's on everything In my logs I'm not getting the logs from inside the route:get's, just the "Log::info("Route started");" I know phpfpm, nginx etc should be good as I'm getting the laravel 404 branded page

I just can't get over why it works locally, but not on google cloud run

The google cloud run logs are limited:

WARNING 2023-06-07T20:19:05.500783Z [httpRequest.requestMethod: GET] [httpRequest.status: 404] [httpRequest.responseSize: 7.15 KiB] [httpRequest.latency: 163 ms] [httpRequest.userAgent: Chrome 113.0.0.0] [ URL, blanking for span]
DEFAULT 2023-06-07T20:19:05.635658Z NOTICE: PHP message: [2023-06-07 20:19:05] development.INFO: Route started
DEFAULT 2023-06-07T20:19:05.636061Z NOTICE: PHP message: [2023-06-07 20:19:05] development.INFO: Current route {"route":null}
DEFAULT 2023-06-07T20:19:05.636663Z NOTICE: PHP message: [2023-06-07 20:19:05] development.INFO: Route started
DEFAULT 2023-06-07T20:19:05.636680Z NOTICE: PHP message: [2023-06-07 20:19:05] development.INFO: Current route {"route":null}
DEFAULT 2023-06-07T20:19:05.637018Z NOTICE: PHP message: [2023-06-07 20:19:05] development.INFO: Route started
DEFAULT 2023-06-07T20:19:05.637110Z NOTICE: PHP message: [2023-06-07 20:19:05] development.INFO: Current route {"route":null}
DEFAULT 2023-06-07T20:19:05.637403Z NOTICE: PHP message: [2023-06-07 20:19:05] development.INFO: Route started
DEFAULT 2023-06-07T20:19:05.637517Z NOTICE: PHP message: [2023-06-07 20:19:05] development.INFO: Current route {"route":null}
DEFAULT 2023-06-07T20:19:05.666099Z 169.254.1.1 - - [07/Jun/2023:20:19:05 +0000] "GET /migrate HTTP/1.1" 404 6616 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
DEFAULT 2023-06-07T20:19:05.667023Z 127.0.0.1 - 07/Jun/2023:20:19:05 +0000 "GET /index.php" 404

I really appreciate anyones input, chatgpt has been leading me in circles of checking php-fpm, routes etc but it must be somewhat right if it works locally, and even deployed serving the laravel 404 format Oh, I also put a ping.html file in the public folder just to be sure, and that does return when deployed publically

thanks again

0 likes
8 replies
click's avatar

I just can't get over why it works locally, but not on google cloud run

First question if routes are working on X but not on Y, did you clear the (route) cache on the live server? php artisan route:clear

What route are you visiting on your live server? yourdomain.com/your-route ?

emeryinca's avatar

@click Thanks for trying to help This did come up, with it running in google cloud run, I don't have direct access to the docker container It's being built fresh before deployment and I have run that command locally, but I don't think that transfers to the container when being deployed

My, maybe poor, understanding is that with it being a new container built on google cloud build it shouldn't have to be cleared? I'm also not sure how to run that command

My /migrate route I tried to create there is also to run the PHP artisan migrate command, as I don't know any other way to run that remotely however all routes return 404, so I'm in a bit of a catch 22

@click just saw the other part of your question

/ /migrate /your-route

anything and everything just gives that laravel 404 page

click's avatar

My /migrate route I tried to create there is also to run the PHP artisan migrate command, as I don't know any other way to run that remotely however all routes return 404, so I'm in a bit of a catch 22

That seems not like a good idea. Migration should be part of your deployment process, the same way that caching or clearing cache should be part of the deployment process.

How did you get your code on the server? Via some deployment tool, a git checkout?

emeryinca's avatar

@click Makes sense, Right now when I do a PR into main google cloud build triggers a build and pushes it to google cloud run I wasn't too sure how to get those commands to work as I don't think google cloud build has access to run them, if that makes sense - or I'm missing something

Snapey's avatar

do you have your requests forwarded through index.php ?

emeryinca's avatar

@Snapey

Here's my index.php

<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/

if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
    require $maintenance;
}

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

$kernel = $app->make(Kernel::class);

$response = $kernel->handle(
    $request = Request::capture()
)->send();

$kernel->terminate($request, $response);

I believe so although one of the logs from google is

DEFAULT 2023-06-07T20:17:59.339530Z NOTICE: PHP message: [2023-06-07 20:17:59] development.INFO: Current route {"route":null}
DEFAULT 2023-06-07T20:17:59.624477Z 169.254.1.1 - - [07/Jun/2023:20:17:59 +0000] "GET /your-route HTTP/1.1" 404 6616 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
DEFAULT 2023-06-07T20:17:59.628274Z 127.0.0.1 - 07/Jun/2023:20:17:58 +0000 "GET /index.php" 404
INFO 2023-06-07T20:18:00.005093Z [httpRequest.requestMethod: GET] [httpRequest.status: 200] [httpRequest.responseSize: 726 B] [httpRequest.latency: 2 ms] [httpRequest.userAgent: Chrome 113.0.0.0] /favicon.ico

Which, if I'm reading right, almost seems like index.php is giving a 404? But the same folder, ping.html is accessible from the web

Snapey's avatar

@emeryinca are you sure the document root is pointing at the public folder and not your project folder?

emeryinca's avatar

@Snapey hey, I am, because I added ping.html to my public folder and it returns at domain/ping.html

Please or to participate in this conversation.