HTTP Authentication when PHP runs as a CGI/PHPSuExec
Historic archive · Reviewed November 20, 2026
This is a historic Francey article. Software and hosting references reflect the time it was written.
PHP is a
feature-rich programming language
that includes simple HTTP
authentication. Unfortunately, if
PHP is running under CGI then PHP
scripts cannot use HTTP
authentication. The workaround for
this problem is to use mod_rewrite
to pass HTTP authentication info to
scripts as a GET parameter.
The following are step-by-step instructions on how
to get HTTP authentication working when PHP is running as a CGI/PHPSuExec.
Step 1: Create a plain text file using a
text editor such as Windows Notepad.
Step 2: Add the following text…
<IfModule
mod_rewrite.c>
RewriteEngine on
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
Step 3: Save the file as a plain text
file. Name the file “.htaccess”
Step 4: Upload the .htaccess file in
ASCII mode to your web space using
an FTP application.
Step 5: Add the following in your PHP
script right before your user/pass
check routine.