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
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
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 | TrackBackComments
the only problem is, you get this message when the file DOES exist. what then?
Posted by: frann at June 6, 2006 05:54 PM@frann
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.
ihave no http 404 file not found
Posted by: ssachez at June 8, 2006 10:53 AMThanks, your solution works for my problem.
Brilliant! Thank you for this solution!
Posted by: Janet at August 17, 2006 10:20 AMBrilliant solution, it's been bugging me for weeks.
Thanks!
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 02:53 PMNo 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 AMIt'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 07:36 PMVery 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 09:04 AMThanks 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 02:57 PMAndrew,
Thank you very, very much! Your solution did it for me!
Posted by: Erwin Hunter at December 11, 2006 09:19 AMDisabling doc_root worked for me. Thanks!
Posted by: DieGoth at December 21, 2006 04:47 PMIf 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 06:10 AMI'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 AMok 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?
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 04:35 PMMichael, 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 08:05 PMNo 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.
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:
http://digitalemagine.com/wordpress/archives/13
for the problem and the solution!
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!! :)
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 01:43 PMBruno, 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 09:15 PMThis works perfectly. Thanks!
Posted by: Tyler at August 9, 2007 05:13 AMFor 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 02:04 PMTry disabling MultiViews.
Options -MultiViews in your .htaccess file.
Posted by: Kris at October 20, 2007 01:43 AMthanks for the GREAT post! Very useful...
Posted by: Whatever-ishere at November 21, 2007 11:01 AMExcellent! Thanks man..
Posted by: pipicom at January 18, 2008 01:40 PMThanks for the post. Really came in handy!
Posted by: faejon at April 20, 2008 12:03 AM
Thanks for the awesome idea! I'm using it now.
Posted by: Jonathon VS at May 15, 2006 09:52 PM