How To Fix Authorization Header Missing in PHP Request?

I recently moved my website to a cPanel server running Apache. However, after the migration, I noticed that $_SERVER['HTTP_AUTHORIZATION'] is missing in PHP requests. How can I resolve this issue and ensure the authorization header is available?

Missing HTTP_AUTHORIZATION header in PHP requests on your cPanel Apache server may be due to the server configuration. You can try the follow these steps to fix the issue:

1. Check .htaccess file:
Make sure you have the following lines in your .htaccess file.

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

2. Check Apache Configuration:
Make sure the Apache server is configured to pass the authorization header. Check the configuration file (usually located at /etc/httpd/conf/httpd.conf ) and add the following line if missing:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

Or for WHM and CPanel do as bellow:

  » Service Configuration 
  » Apache Configuration 
  » Include Editor 
  » Pre VirtualHost Include 
  » All Version 

Add this line

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

3. Restart Apache Server (Without restart the config will not work)

service httpd restart

Now check, authorization should be added to your header.