php-cgi does not give proper 404 errors

When using php-cgi via .htaccess you will find that missing files give “No input file specified” instead of a proper 404 error.

To fix this, add :


RewriteEngine On
RewriteRule ^.+\.php$ /file_name_that_does_not_exist

to your .htaccess

replace “file_name_that_does_not_exist” with any file name that does not exist – ie. something that will trigger a 404 error.



php cgi and $_SERVER[‘php_auth_user’] problems


I upgraded my version of PHP from 4.4.0 mod_php (scripts run as nobody) to 4.4.0 (run as my username), per the PHP version configuration panel. Now I am getting some authentication problems:

Since the upgrade I am finding that $_SERVER[‘PHP_AUTH_USER’] is now null, whereas before it was populated.

Answer :


Try and use :


That should work. The cgi versions of php don’t have access to the HTTP vars. Check :

for more on this.

My CGI script is not working! It worked fine until I uploaded a new copy. What’s going on?


I have a perl cgi script that is not working. I’m sure I have the chmod settings correct and their are no syntax errors.


Unfortunatly there can be many different reasons why a script stops working. The most common is that you made a recent edit to the file that broke it. If you are sure that you did not make any syntax (aka programming) errors in the script, the following may help:

When you upload a script (cgi, perl files, etc.) from a windows computer to a unix-based server, you need to upload them in ascii mode. If not, windows adds some extra control characters at the end of each line that cause the script to not run correctly. Normally your FTP program will switch the mode in the background for you. Sometimes it does not though.

In the future, you can just manually hit the ascii mode switch in your FTP program to make it upload the script in ascii mode. The best mode to keep your FTP program in is usally labeld as “auto”. Keep in mind that in your particular FTP program it may be labeled differently. Each FTP program uses their own terminology.

Most ftp programs in auto mode will do the right thing for each file you upload.

I’d like to run cgi’s from anywhere in my site – not just the cgi-bin directory.

Question :

I’d like to run cgi’s from anywhere in my site – not just the cgi-bin directory.

Answer :

Create a .htaccess file and add the lines:

AddHandler cgi-script .pl
AddHandler cgi-script .cgi

to it.

Add other AddHandler statements if you are using different file extensions.

I wrote a very basic cgi script but it doesn’t work

If you are trying to write a basic “hello world” type cgi but keep getting:

500 error response – Internal Server Error

Make sure the first line of output from your script is:

print “Content-type: text/htmlnn”;

All cgi’s (in any language) need to output a header line, followed by two newline characters (n) before any “regular” output is done from the script.

Also, check that you have made the script executable :

From the ssh command line, issue this command :

chmod u+x name_of_script here

or from inside most FTP programs:

1. click properties for the file and select “Change permissions” or “chmod”

The wording will vary from one FTP program to another.

Can I point a subdomain to a cgi script?

Can I point a sub domain at a cgi script?


A subdomain in DNS can only point to an IP. A full URL (ie. a script) is above the level of DNS. DNS only understands
IP’s and domain names. Not full URLs.

You can use the 403 redirect option to have the webserver forward the subdomain request to the URL.

Another approach is to point the subdomain to a sub-directory in the control panel and then have that sub-directory’s index page immediately redirect to your cgi script. You could also use .htaccess to make the filename for your script be one of the index pages.