Ticket #390 (closed bug: fixed)

Opened 1 year ago

Last modified 11 months ago

Erreur dans le traitement des URLs avec php5 en cgi

Reported by: bballizlife Assigned to: laurentj
Priority: high Milestone: Jelix 1.0RC2
Component: jelix:core Version: 1.0RC1
Severity: critical Keywords: cgi, pathinfo suphp
Cc: Php version:
Review: Hosting Provider:
Documentation needed: Blocking:

Description

Contexte

  • application utilisant les URLS significatives + configuration pour supprimer le point d'entrée
  • serveur apache + php5 en cgi
  • mise en place .htaccess dans www/ de l'application pour ajouter des règles de rewrite afin de faire fonctionner l'application sans utiliser le point d'entrée.

Le .htaccess :

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

Bug

Debug

Dans les logs, il apparaît :

"Premature end of script headers: index.php"

Test avec cette règle de rewrite :

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

En testant toujours http://foo.com/bar l'application s'affichait bien (même si la page affichée ne correspondait pas à ce qui était demandé)

Dans le php.ini on a fini par passer cgi.fix_pathinfo à 0 et le serveur s'est mis à bien faire fonctionner l'application.

Voici ce qui est dit à propos de cette variable :

cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting this to 1 will cause PHP CGI to fix it's paths to conform to the spec. A setting of zero causes PHP to behave as before. Default is 1. You should fix your scripts to use SCRIPT_FILENAME rather than PATH_TRANSLATED.

Change History

12/20/07 13:13:27 changed by laurentj

  • status changed from new to assigned.
  • owner set to laurentj.
  • component changed from jelix to jelix:core.
  • milestone set to Jelix 1.0.

12/20/07 18:40:51 changed by Julien

Salut,

je ne sais pas si ca va fixer le truc, mais voici ce que j'avais rajouté dans dragon-cms (dans application.init.php)

// sometimes $_SERVER['PATH_INFO'] isn't set, when PHP used in CGI mode
if(!isset($_SERVER['PATH_INFO']) && isset($_SERVER["ORIG_PATH_INFO"])){
    $_SERVER['PATH_INFO'] = $_SERVER["ORIG_PATH_INFO"];
}


// with mod rewrite enabled, we need to fix some other thing
if(isset($_SERVER['ORIG_SCRIPT_NAME']) && $_SERVER['ORIG_SCRIPT_NAME'] !== $_SERVER['SCRIPT_NAME']){
        $_SERVER['SCRIPT_NAME'] = '/index.php';
}

j'avais constaté ça sur le php5 de debian etch en cgi via suphp ($_SERVER\['PATH_INFO'\] n'était jamais défini).

Sur un autre serveur, php compilé à la main, j'avais bien un pathinfo correct.

Je n'avais pas regardé l'histoire de cgi.fix_pathinfo dans php.ini

En espérant que ça aide.

12/21/07 22:15:07 changed by laurentj

Je n'arrive pas à reproduire le bug.

  • Ubuntu 7.10, php 5.2.3, Apache/2.2.4.
  • cgi.fix_pathinfo = 1

Le contenu du vhost :

   AcceptPathInfo On
   ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
   <Directory "/usr/lib/cgi-bin">
       AllowOverride None
       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
       Order allow,deny
       Allow from all
   </Directory>
   AddHandler x-httpd-php5 .php
   Action x-httpd-php5 /cgi-bin/php5

urls.xml

<urls xmlns="http://jelix.org/ns/urls/1.0">
    <classicentrypoint name="index" default="true" noentrypoint="true"><!-- -->
        <url pathinfo="/hello" module="main" action="default:hello" />
        <url pathinfo="/hello2" module="main" action="default:hello2" />
        <url pathinfo="/hello3" module="main" action="default:hello3" />
    </classicentrypoint>
</urls>

J'ai bien le PATH_INFO généré.

Par contre, en mettant cgi.fix_pathinfo=0 j'ai l'erreur "No input file specified." (sauf pour les fichiers en dur, donc c'est par le mod_rewrite qu'il y a un problème dans ce cas)

12/21/07 22:20:37 changed by laurentj

J'ai aussi essayé avec AcceptPathInfo? off, +Multiviews... Ça fonctionne parfaitement chez moi

12/21/07 23:34:43 changed by laurentj

J'ai trouvé : il s'agit en fait quand on utilise suphp. On n'a pas de PATH_INFO quand cgi.fix_pathinfo=1. Et on a à la place un ORIG_PATH_INFO. En CGI donc, pas de blem, mais en CGI+suphp, y a un problème. Je corrigerai ça un peu plus tard.

12/21/07 23:34:53 changed by laurentj

  • keywords changed from cgi, pathinfo to cgi, pathinfo suphp.

12/30/07 13:59:02 changed by laurentj

  • priority changed from normal to high.
  • severity changed from normal to critical.

12/30/07 18:34:10 changed by laurentj

Je pense avoir corrigé ce qu'il faut. j'ai fait des tests avec php+suphp et php+cgi sur ma becane et ça semble fonctionner.

Il faudrait tester de votre coté, et surtout en mettant cgi.fix_pathinfo à 1 puisque c'est la conf par défaut de php et celle recommandée.

Merci de confirmer qu'on puisse fermer le ticket.

01/02/08 21:06:00 changed by laurentj

  • status changed from assigned to closed.
  • resolution set to fixed.

Aprés quelques autres vérifications, le bug semble être plus du coté de PHP en CGI que de jelix. Ticket fermé donc.

Download in other formats: Comma-delimited Text Tab-delimited Text RSS Feed