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 AMComments
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@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 2: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 7: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 9: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 2:57 PMAndrew,
Thank you very, very much! Your solution did it for me!
Posted by: Erwin Hunter at December 11, 2006 9:19 AMDisabling doc_root worked for me. Thanks!
Posted by: DieGoth at December 21, 2006 4: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 6: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 4: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 8: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 1: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 9:15 PMThis works perfectly. Thanks!
Posted by: Tyler at August 9, 2007 5: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 2:04 PMTry disabling MultiViews.
Options -MultiViews in your .htaccess file.
Posted by: Kris at October 20, 2007 1: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 1:40 PMThanks for the post. Really came in handy!
Posted by: faejon at April 20, 2008 12:03 AMYOU 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 AMMy 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 AMI 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 AMFor 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 AMHi 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.
Cheers!
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]
IF YOU ARE USING ABYSS WEB SERVER:
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 PMBrilliant!!! 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 AMwow thanks, I was sick of this problem.
Posted by: Kusal at May 31, 2009 5:37 PMtks for the effort you put in here I appreciate it!
Posted by: MichaellaS at July 22, 2009 5:11 PMI 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 PMPosted 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 AMHi guys,
if still there is any problem, have a look at this link, it will help you.
http://pankajdangi.com/2010/04/no-input-file-specified-codeigniter/
Thanks
Pankaj
Thanks for the awesome idea! I'm using it now.
Posted by: Jonathon VS at May 15, 2006 9:52 PM