"No input file specified"

January 20, 2005

"No input file specified"

When running PHP as a CGI binary on Apache, you might get the above error if you request a nonexistent PHP file. If you've got a custom 404 page (or even the default one), this can be irritating, as it makes for an inconsistent user experience (although a good site (re)design should never be a catalyst of 404 errors).

The reason this happens is that any requests ending in .php are simply handed off to the PHP executable without verifying that such a file exists. Although this is by design, it can be a bit offputting. Unfortunately, there does not appear to be a way to configure the PHP executable to return a "normal" 404 to Apache if the requested script does not exist. True, it does return a 404 response header along with the "No input file specified", but it won't return the appropriate ErrorDocument under any circumstances.

Google didn't come up with any solutions, although it did find many other people with the same problem.

Luckily for me, I had spent the last few days playing around with mod_rewrite, and it occurred to me that that's how to solve the problem. Mod rewrite is an extremely powerful Apache module that lets you manipulate/redirect urls. In short, if you want to prevent hotlinking, protect content, optimize for search engines, do load balancing, or just about anything you can think of when it comes to urls, then mod_rewrite is for you.

So getting back on topic, all we have to do is create a simple rewrite rule that checks the requested url to see if 1. it is ends in .php and 2. no such file exists. If both conditions are met, we translate the request into a url that we know doesn't exist. This triggers a 404, and Apache sends the client the appropriate ErrorDocument. Rewrite rules are run before anything is sent off to the content handler, so PHP is bypassed entirely.

It's simply a matter of putting an .htaccess file in our base dir with the following lines:

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

And that's it! Your mileage may vary, since not all servers are configured identically. Just be sure that /bogusfile really doesn't exist, otherwise it will be served up instead of the 404.

Update 2005-01-20 10:55 AM
It appears my google skills are lacking. Someone known as n74 solved this about two months ago ... here and here...

The only difference is that his solution rewrites the url to the ErrorDocument, whereas mine rewrites it to a nonexistent file.

The end result is the same, except that his way a 200 status code is sent rather than a 404.

Posted by jon at January 20, 2005 12:07 AM


Thanks for the awesome idea! I'm using it now.

Posted by: Jonathon VS at May 15, 2006 9:52 PM

the only problem is, you get this message when the file DOES exist. what then?

Posted by: frann at June 6, 2006 5:54 PM


That means either the path or the permissions are wrong, or SCRIPT_FILENAME isn't getting set by the webserver. So...

1. See what happens with non-PHP files in the same directory. Do you get a 404, or do they appear as expected? If other files aren't coming up, make sure your DocumentRoot is in fact what you think it is.
2. Check the file permissions of your script. Perhaps PHP/Apache is unable to read the files.
3. If all else fails, look at the comments here regarding "No input file specified". Certain webserver configurations do not set the SCRIPT_FILENAME environmental variable, which is required by the PHP-CGI binary.

Posted by: jon at June 7, 2006 12:35 AM

ihave no http 404 file not found

Posted by: ssachez at June 8, 2006 10:53 AM

Thanks, your solution works for my problem.

Posted by: Daniel at July 7, 2006 3:44 AM

Brilliant! Thank you for this solution!

Posted by: Janet at August 17, 2006 10:20 AM

Brilliant solution, it's been bugging me for weeks.

Posted by: Brian at August 18, 2006 7:08 AM

This requires that the web server has access to your PHP application so it doesn't work if you are running PHP with FastCGI where PHP runs as a different user or on a different host.

Posted by: Christian G. Warden at September 6, 2006 2:53 PM

No input file specified can result from having an alias in httpd.conf and a doc_root in php.ini if you're running PHP as a CGI. Try making your doc_root in php.ini "" or
doc_root = ""
and you may solve this issue.

RE: http://wordpress.org/support/topic/4243

Posted by: Andrew at September 8, 2006 11:00 AM

It's getting late and I'm tired. Your comments were a great help. I had not uploaded the PHP file.

Thank you!!!

Posted by: Regina at October 12, 2006 7:36 PM

Very helpful! I was looking for an answer for a long time and I found this.

Tranks a lot!!

Posted by: Konamito at November 1, 2006 9:04 AM

Thanks to everyone who has posted solutions on this site, I found them very useful as i've been able to get php working which has been buging me for ages.

Thanks again

Posted by: Ryan at November 22, 2006 2:57 PM


Thank you very, very much! Your solution did it for me!

Posted by: Erwin Hunter at December 11, 2006 9:19 AM

Disabling doc_root worked for me. Thanks!

Posted by: DieGoth at December 21, 2006 4:47 PM

If I add that line of code in the .htaccess file it will bring up my custom error page on every page?

Running Linux with Network Solutions.

Posted by: Zane at January 3, 2007 6:10 AM

I've searched many sites to find out how to fix "no input file specified"...everything said it was a permissions problem. I knew it wasn't. Your solution worked perfect.

Thanks so much !!!

Posted by: DAnne at March 8, 2007 10:48 AM

ok my site was working fine and i just suddenly began getting that error yesterday when i typed in the url to my site and hit enter
i've not made any changes to my site structure for a couple months...has anyone else have this prob with a working site as well?

Posted by: propaganda press at March 14, 2007 11:09 PM

Im getting a "No input file" in Firefox and a "404 error" in IE and my website is down becuase of this. How Do I retrieve the situation and get the site up and running again?

Posted by: Michael at April 4, 2007 4:35 PM

Michael, I'd check with your hosting provider to see what's going on. Based on your server IP, it looks like you are hosted with DreamHost.

Posted by: jon at April 4, 2007 8:05 PM

No input file specified when the file actually *IS* present?
This happens often if the value of the doc_root variable in the php.ini file of you php installation does not match the DocumentRoot variable in your server configuration script. Try to set both to the same location.

Posted by: my at April 9, 2007 4:50 AM

Mmmmmh, in my case the problem was not to have a 404 message, rather to have my translated short URLs work!
The files were not missing, they were dynamic URLs which should have been evaluated by my index.php.

Check my post here:
for the problem and the solution!

Posted by: Stefano at April 27, 2007 2:39 AM

No input file specified can result from having an alias in httpd.conf and a doc_root in php.ini if you're running PHP as a CGI. Try making your doc_root in php.ini "" or
doc_root = ""
and you may solve this issue.

RE: http://wordpress.org/support/topic/4243

Posted by: Andrew at September 8, 2006 11:00 AM

Hi, this post was extremly helpful, had been buggin me for weeks, thanks alot!! :)

Posted by: Sam Jones at June 3, 2007 4:16 AM

I tried removing doc_root in my php.ini file and that still didn't solve my problem. I have two websites that uses PHP, one of them works fine with no "No input file specified" error while I'm getting this error on the other site. Seems like that theses solutions work when using Apache webserver. Does anyone know a solution for IIS 6?

Posted by: Bruno at June 19, 2007 1:43 PM

Bruno, take a look at this one: http://wordpress.org/support/topic/4243

It states to try set cgi.force_redirect to 0 if you are running IIS.

I'm running apache, however I have not been able to fix this problem ye.

Posted by: Aaron at July 11, 2007 9:15 PM

This works perfectly. Thanks!

Posted by: Tyler at August 9, 2007 5:13 AM

For some reason beyond my comprehension, those few lines fix a problem with subdomains for me!

I had a number of the following snippets:
RewriteCond %{HTTP_HOST} ^photo\..+\..+ [NC]
RewriteCond %{REQUEST_URI} !^/portfolio/.*
RewriteRule ^(.*) /portfolio/$1 [L]

And they caused 404's until I added the bogusfile lines you mentioned above. Now all the right resources (including .php files) work.

Many thanks but... I still don't understand why this fixes the problem I had.

Posted by: Martijn at October 17, 2007 2:04 PM

Try disabling MultiViews.

Options -MultiViews in your .htaccess file.

Posted by: Kris at October 20, 2007 1:43 AM

thanks for the GREAT post! Very useful...

Posted by: Whatever-ishere at November 21, 2007 11:01 AM

Excellent! Thanks man..

Posted by: pipicom at January 18, 2008 1:40 PM

Thanks for the post. Really came in handy!

Posted by: faejon at April 20, 2008 12:03 AM

YOU ARE A GENIUS!! Man, the company that I have been dealing with about website's search engine optimization could not tell me the right solution. They freaking gave me PHP codes to put on INDEX pages after htaccess codes were blocking the whole PHP catalog. Thank you again and good luck!!

Posted by: nookeen at July 5, 2008 6:50 AM

My host recently started running PHP as a CGI module without letter me know. I still encounter this error from time to time. Shame I still have four years of hosting left, or I would have dropped them for doing that.

Your solution saves me every time!

Posted by: Lachlan at July 8, 2008 6:31 AM

I too got this error installing PHP on IIS 7.0 (Vista SP1 - following these instructions: http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/)
And commenting our the doc_root *THEN RESTARTING IIS* fixed the problem - thanks to everyone for posting this!

Andrew :o)

Posted by: Andrew at September 21, 2008 4:18 AM

For the original "No input file specified" problem: What about using the mod_rewrite in the following way:

RewriteCond %{DOCUMENT_ROOT}/$1 !-f
RewriteRule ^(.*\.php)$ - [T=text/html]

This effectively prevents the execution of the PHP for missing files and processes the PHP URI exactly like a HTML URI, causing normal 404 processing.

This way can be used also on sites using the default 404 document, which reveals the bad URL to the user. With the solution suggested above, the "bogusfile" is shown to the user, which is confusing: "The requested URL /bogusfile was not found on this server."

Posted by: panuworld at October 11, 2008 4:46 AM

Hi Guys,

You all seem to have good solutions, but I have a different set-up but with the same problem.

I have the php cgi binary placed in /cgi-bin for 5.2 as my normal php is 5.1

this works fine, but all my files are symbolic links to another vhost.

I have set up vhost.conf to allow access to the other vhost.

I have also set Options Indexes FollowSymLinks

Permission of the symbolic links set to the vhost where they were created.

I have tried removing the doc_root and setting cgi.force_redirect to 0 and 1 and comment out.

vhost conf is like this;

php_admin_value open_basedir "/var/www/vhosts/domain2.com/httpdocs:/var/www/vhosts/domain1.com/httpdocs:/tmp"
Options Indexes FollowSymLinks

in /var/www/vhosts/domain2.com/httpdocs/ I did this

ln -s ~domain1ftp/httpdocs/app ~domain2ftp/httpdocs/
ln -s ~domain1ftp/httpdocs/index.php ~domain2ftp/httpdocs/

chown domain2ftp.psacln -R *

/etc/init.d/httpd restart

If I copy the actual index.php file over, it then says it can't find an include file in /app/conf.php

If anyone can work this one out, I would greatly appreciate it.


Posted by: Saloob at January 8, 2009 9:55 PM

@panuworld your fix doesn't work for me, I suppose in my setp php is run before the mime-type is changed...

If you have the same problem, and still want to redirect, throw a 404 and show the incorrect url to the user, this works for me:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (^.+)\.php$ $1\.phpfix [NC,L]

Posted by: Namdnal Siroj at February 11, 2009 10:22 AM


Go To: Abyss Web Server Console :: Hosts - Edit - Default Host On Port 80 :: Scripting Parameters :: Interpreters - Edit - FastCGI (Local - Pipes)

Change: Type = Standard

Posted by: Michael at February 12, 2009 10:48 PM

Brilliant!!! Just what i needed, thanks - (just noticed your post was done just over 4 years ago - still valid) Thanks

Posted by: Melt du Plooy at April 24, 2009 3:51 AM

wow thanks, I was sick of this problem.

Posted by: Kusal at May 31, 2009 5:37 PM

tks for the effort you put in here I appreciate it!

Posted by: MichaellaS at July 22, 2009 5:11 PM

I was getting this problem on a Fasthosts server (UK hosting company).

To get round it I had to change my rewrite rule as follows:

# original
# ========
RewriteBase /
RewriteCond $1 !^(index\.php|images|css|robots\.txt|favicon\.ico|js|uploads|flash)
RewriteRule ^(.*)$ index\.php/$1 [L]

# On fasthosts replace the last line above with this:
# RewriteRule ^(.*)$ index\.php?/$1 [L]

Note the additional question mark (?) after the .php

Posted by: Chris Cook at October 27, 2009 1:50 PM

Posted by: Sam Jones

It work! make sure your php.ini file changed is in actually path.

No input file specified can result from having an alias in httpd.conf and a doc_root in php.ini if you're running PHP as a CGI. Try making your doc_root in php.ini "" or
doc_root = ""
and you may solve this issue.

RE: http://wordpress.org/support/topic/4243

Posted by: Andrew at September 8, 2006 11:00 AM

Hi, this post was extremly helpful, had been buggin me for weeks, thanks alot!! :)

Posted by: Sam Jones at June 3, 2007 04:16 AM

Posted by: jacks at April 14, 2010 9:27 AM

Hi guys,

if still there is any problem, have a look at this link, it will help you.


Posted by: Pankaj Dangi at April 15, 2010 3:04 AM