Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No input file specified - apache and php-fastcgi

My client's website is currently running on a apache server with mod_php. All application's routes are defined in the .htaccess file (see the code below). Now he is trying to migrate to an server running apache and php-fastcgi, but the routes are no long working.

<IfModule mod_rewrite.c>

  RewriteEngine On

  # Redirect
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} -s [OR]
  RewriteCond %{REQUEST_FILENAME} -l [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^.*$ - [NC,L]
  RewriteRule "^noticias/?$" index.php/noticias/frontend/list/ [L,QSA]
  RewriteRule ^.*$ index.php [NC,L]

</IfModule>

When I access http://domain.tld/noticias, I get No input file specified, and in the apache error_log [fcgid:warn] mod_fcgid: stderr: PHP Warning: Unknown: function '1' not found or invalid function name in Unknown on line 0, but if I access the route directly http://domain.tld/index.php/noticias/frontend/list/ it works fine.

UPDATE

I found a working solution changing some of the framework behaviour. If someone has a solution without having to change the framework (probably in the apache or php configuration), I will gadly award the answer the bounty.

like image 714
Lucas Ferreira Avatar asked Aug 27 '15 16:08

Lucas Ferreira


3 Answers

As sugested by @user3584460, I decided to change all my routes to pass the desired controller/action as a querystring parameter. Here how it was done.

I changed all routes to pass a _url parameter:

RewriteRule "^noticias/?$" index.php?_url=/noticias/frontend/list/ [L,QSA]

This way I would not get the error "No input file specified", but the framework (zend) would not recognize the route, and would always show the homepage.

The route dispatcher expected the $requestUri variable to be in the format index.php/module/controller/action, but with the change in the .htaccess, it was index.php?_url=/module/controller/action. So I had to make some changes in the Zend_Controller_Request_Http class, so it would make the conversion.

So I added the following lines to the setRequestUri method:

public function setRequestUri($requestUri = null)
{
    // ...

    // begin changes
    preg_match('/_url=([a-zA-Z0-9\/\-_\.]+)&?(.*)/', $requestUri, $matches);
    if (count($matches) == 3)
        $requestUri = '/index.php' . $matches[1] . '?' . $matches[2];
    // end changes

    $this->_requestUri = $requestUri;
    return $this;
}

Now it works fine.

like image 190
Lucas Ferreira Avatar answered Oct 23 '22 13:10

Lucas Ferreira


Change your line with noticias:

  RewriteRule ^noticias/?$ index.php/noticias/frontend/list/ [L]
like image 25
Croises Avatar answered Oct 23 '22 11:10

Croises


We sometimes see this on sites that use rewrites. We fixed this by changing the rewrite. The old line would be something like:

RewriteRule ^(.*)$ _routing.php/$1 [L]

We changed it into:

RewriteRule ^(.*)$ _routing.php [L]

This resolved the issue.

like image 1
Rudy Broersma Avatar answered Oct 23 '22 11:10

Rudy Broersma