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

Kirkland's avatar

Get header in middleware works with PHP dev server on local machine, but not on a LAMP

I have an API written in Lumen that works exactly as expected on my local PHP dev server (php -S in {project_directory}/public/), but on my dev server (Amazon Linux LAMP, all default settings for dev purposes) it returns NULL when trying to the the Authorization header. I have other Laravel applications on the same type of configuration that work perfectly, and ideas?

public function handle($request, Closure $next)
{
    $apiKey = $request->headers->get('Authorization');

    dd($apiKey);

if(self::validateApiKey($apiKey)) {
     return $next($request);
} else {
    return response()->json(['error' => 'The given API key is invalid.'])->setStatusCode(401);
}
}
0 likes
1 reply
willvincent's avatar

You could probably do something like this:

if (!$apiKey = $request->headers->get('Authorization') && function_exists('apache_request_headers')) {
  $all = apache_request_headers();
  if (isset($all['Authorization'])) {
    $apiKey = $all['Authorization'];
  }
}

Or, you might be able to just add the following to your .htaccess file:

SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

Please or to participate in this conversation.