CodeIgniter – No input file specified error – .htaccess – PHP5 – Apache 2

Written by Terence Chang on August 28th, 2008

Speed Coder

Image Source: Day 486 / 365 – Late Night High Level Coding Courtesy Of: JasonRogers

What the heck is this blog post all about? I am warning you that this is going to be a very technical driven blog post.

I felt so funny that this blog got more traffic from search engine to IT related blog posts than to my Internet Entrepreneur Diary or Weekend Confession blog posts. This blog was started with many IT relate topic to records the problems I ran into and the solutions I found. It’s a good time to give it a little update.

Let’s cut to the chase. I am working a new projects that is running on PHP5, Apache 2 and MySQL. I need to get this project done fast and good. So I finally found one of the best choice from so many PHP frameworks. CodeIgniter seems to be the best one fit my needs. It’s very simple and fast. Although it does not support PHP5 OO programming, but it does run on PHP5.

ci_logo2

I just ran into problem on my shared hosting server, which is running PHP5 as CGI mode on Apache 2.2 according to PHPINFO(). It throws an error when I access page. “No Input File Specified!” Now the problem is solved!

I have no problem to run the application on my local XP based laptop,which runs PHP5 as Apache Module. Obviously, it’s an Apache error. After reaching on Internet and found the solution. If PHP5 is running on Apache 2.2 as CGI mode, which many web hosting company set as default; Apache is not going to support “PATH_INFO” inside Codeigniter. In order to solve the problem, the solutions is very simple!

There are two solutions. No matter which one you choose, you will always have the same step 1.
Step 1: Obviously, PHP running under CGI mode has cgi.fix_pathinfo default to 1. Simply open /system/application/config/config.php file and make sure the following two options are set.

$config['index_page'] = “”;
$config['uri_protocol'] = “AUTO“;

Solutions 1:
Step 2: Create a customized PHP.INI file under the root directory of your site with the following line.

cgi.fix_pathinfo = 0;

Solutions 2:
Step 2: Go to .htaccess file and add question mark after index.php and before slash.

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

Personally, I choose the Solution 1 with PHP.INI. It seems to run faster. Problem solved!

 

22 Comments so far ↓

  1. Yamin says:

    Well i did both step1 and step2 alternatively. It still returns me “404 Page Not Found The page you requested was not found.” error. Please help!!!

  2. Terence Chang says:

    @Yamin:

    404 page not found is a different story. I checked your site, it shows “No input file specified” error. Looks like you are missing something. I have also tried index.php?/social-media/ or index.php/social-media/ without good luck on your site. So here are few questions I want to ask you to help get this solved.

    1. What version of PHP are you running? PHP4 or PHP5?
    2. Is PHP running as CGI mode or Apache Module?

    If you are running PHP as Apache Module, it should be no brainer. Good luck!

  3. rummuser says:

    This has completely taken me by surprise. I do not know what is going on, but whatever it is, I hope that you will get back to your normal blogging on this site!

  4. Terence Chang says:

    @Yamin:

    I just give it a try with the following link on your site.

    social-media/index.php?/test/

    It throw an 404 page not found error. It’s the default CodeIgniter page not found error. I thought you were saying the default Apache 404 page not found error.

    So I tried social-media/index.php

    It throws “An Error Was Encountered – Unable to load the requested class: myclass”.

    Looks like you have changed something in the config file or class name, which cause the problem. Keep me post.

  5. Terence Chang says:

    @Rummuser:

    Thank you for coming back! I have to admit that I was not very active on my blog recently. Working on my new project to achieve the life time. :-)

    Stay tune!

  6. Yamin says:

    Hi Chang,
    My Php Version: 5.2.6 and Server API: CGI/FastCGI. And i also found out that Virtual Directory Support is set to disabled in my php.ini. I dont know whether its causing the problem. But surprisingly i got another project which is working fine with mod_rewrite in the same server although the virtual directory support is disabled. But i’ve php5, server api: Apache 2.2 Handler, and virtual directory enabled in my local pc. Does that help?

  7. Yamin says:

    By the way, my apache .htaccess has this following codes:
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|css|js|ext|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]

  8. Yamin says:

    Hi chang,
    I got it worked out without the SEO friendly URL (i.e without rewrite rule). Since the app i’m working doesn’t require SEO friendly url, i kind of accepted the sacrifice that i had to make. But i found something peculiar in codeigniter. Whenever i try to destroy the session with the following code:

    $this->CI->session->set_userdata(‘sessionvar’, false);
    $this->CI->session->sess_destroy();

    It destroys the session in FF. But not in IE. However i have installed the session patch that they (codeigniter) have provided, so its working in FF but not in IE. Have any suggestion for me pls???

  9. Terence Chang says:

    @Yamin:

    I hope you found your solutions. Your .htaccess file looks good to me. Just wondering if you every try to add question mark after index.php. Hope that solved your problem. Many hosting site turn off virtual directory so you can’t add your own.

  10. Terence Chang says:

    @Yamin:

    I always try to set session data to NULL or empty string before destroy them. I have not has problem with IE7. Can’t really duplicate with it.

  11. Zarate says:

    THANKS A LOT!!

    I recently was moved servers inside Dreamhost and this was killing me without apparent reason. It was working one day, the day after, it wasn’t.

    I’m glad I found your post : )

    Cheers!

    Juan

  12. Terence Chang says:

    @Zarate:

    I am glad that you got your problem solved! I checked out your site. It’s very interesting. I just learned from you site that there are new languages to create a better user experience. I like your site a lot. I guess that you speak multiple languages.

    I will keep you on my talented developer list. :-)

    Thank you for stopping by!

  13. swap market says:

    Your problem is solved and that is very great,, i also found that your website is truly interested and I start using open source PHP framework.

    ust has an error related to PHP5 running on Apache

  14. Sean says:

    Dear Terence,
    your solution just saved my ass.
    I used the second, the first wouldn’t work for me.
    Honestly, after recompiling php/apache it just started doing this weird behaviour.

    Cheers

  15. Terence Chang says:

    @swap market:

    I hope that I found codeigniter much earlier. I just found it few months ago and love how simple it is to implement complex applications. PHP5 + MySQL 5 + Apache2 + CodeIgniter is a great combination.

    @Sean:

    I am glad that you got your issues resolved. It took me a while to figure out. :-) Thank you for stopping by!

  16. Digitalman says:

    Thank you so much! Option #2 worked for me. I searched and found many examples of fixes but none worked until I tried your. I really appreciate it.

  17. alex-and-r says:

    Hi!

    Thank you for your solution!

    My hosting provider won’t provide IMAp module for PHP by default and after recompiling PHP for me with this module all my site (except index page) stopped working showing “No input file specified”.

    I used solution 2 and it worked for me!

    Thanks!

  18. dewa says:

    hi, thanks for your nice info. it safe my site after the hosting company update php and apache.

    regards

  19. Andrew says:

    Just had this pop up on a client’s application, the host must have changed some configuration. Just needed to add the question mark in my RewriteRule and bam, it was back.

  20. kashif says:

    this is my .htaccess file in godaddy basically what i am doing is my project is on the subdirectory like

    http://www.mydomain.com/lap/codeigniterproject

    what .htaccess setting should i use

    Options -MultiViews
    #Enable mod rewrite
    RewriteEngine On
    #the location of the root of your site
    #if writing for subdirectories, you would enter /subdirectory
    RewriteBase /

    #Removes access to CodeIgniter system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #’system’ can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^/system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn’t true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #This last condition enables access to the images and css
    #folders, and the robots.txt file
    #Submitted by Michael Radlmaier (mradlmaier)
    # I added this line based on some info from other posts
    RewriteCond $1 !^(index\.php|images|robots\.txt|css)

    RewriteRule ^(.+)$ index.php?/$1 [L]

  21. scidar says:

    Thanks!
    Solution 2 worked fine for me!

    You saved my life! ;D

  22. mahrizal says:

    i use .htaccess solution
    it works thanks

Leave a Comment





3 Trackbacks / Pingbacks

  1. CodeIgniter No input file specified error on PHP5 and Apache 2.2 « Terence Chang - Reach Out
  2. Fastlane Plan Update - the reality check - no perfect plan | The Internet Entrepreneur Diary
  3. Resolving PHP No Input File Specified Error for WordPress on IIS « Basil Vandegriend: Professional Software Development