PHP $_SERVER['SCRIPT_NAME'] is wrong when loading PHP via mod_fcgid

有些话、适合烂在心里 提交于 2019-12-04 02:04:17

问题


I'm using Apache 2.4.7 and PHP 5.5.7.

I have a test.php file in C:\web\vhosts\Symfony\web.

The value of $_SERVER['SCRIPT_FILENAME'] is correct:

C:/web/vhosts/Symfony/web/test.php

However the value of $_SERVER['SCRIPT_NAME'] depends on how I load PHP:


If I load PHP as an Apache module, the value of $_SERVER['SCRIPT_NAME'] is:

/test.php

I'm a bit surprised that it isn't the same as SCRIPT_FILENAME, but at least it's a correct value, I guess.

Here's how I loaded PHP:

LoadModule php5_module "C:/web/php-5.5.7-Win32-VC11-x86/php5apache2_4.dll"
AddHandler application/x-httpd-php .php 
PHPIniDir "C:/web/php-5.5.7-Win32-VC11-x86"

If I load PHP using mod_fcgid, the value of $_SERVER['SCRIPT_NAME'] is:

C:/test.php

Which is just wrong...

Here's how I loaded PHP (based on a tutorial from ApacheLounge):

LoadModule fcgid_module modules/mod_fcgid.so 

<IfModule fcgid_module> 
   FcgidIOTimeout 40 
   FcgidConnectTimeout 10 

   FcgidMaxProcesses 300 
   FcgidMaxProcessesPerClass 300 

   FcgidOutputBufferSize 64 
   ProcessLifeTime 0 
   FcgidMaxRequestsPerProcess 0 
   FcgidMinProcessesPerClass 0 
   FcgidFixPathinfo 1 
   FcgidProcessLifeTime 0 
   FcgidZombieScanInterval 20 
   FcgidMaxRequestLen 536870912 
   FcgidIOTimeout 120 
   FcgidTimeScore 3 

   FcgidPassHeader Authorization 

   FcgidInitialEnv PHPRC "C:\\web\\php-5.5.7-Win32-VC11-x86" 
   FcgidInitialEnv PATH "C:\\web\\php-5.5.7-Win32-VC11-x86;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;" 
   FcgidInitialEnv SystemRoot "C:\\Windows" 
   FcgidInitialEnv SystemDrive "C:" 
   FcgidInitialEnv TEMP "C:\\WINDOWS\\TEMP" 
   FcgidInitialEnv TMP "C:\\WINDOWS\\TEMP" 
   FcgidInitialEnv windir "C:\\WINDOWS" 
   <Files ~ "\.php$"> 
      Options Indexes FollowSymLinks ExecCGI 
      AddHandler fcgid-script .php 
      FcgidWrapper "C:/web/php-5.5.7-Win32-VC11-x86/php-cgi.exe" .php 
   </Files> 
</IfModule>

What's wrong with this setup?


回答1:


Now I know what's wrong:

FcgidFixPathinfo 1

Set this value to 0. You can also comment it out, or remove it altogether, since 0 is the default.


According to the documentation:

This directive enables special SCRIPT_NAME processing which allows PHP to provide additional path information. The setting of FcgidFixPathinfo should mirror the cgi.fix_pathinfo setting in php.ini.

However I found that the value of cgi.fix_pathinfo in the php.ini file makes absolutely no influence as to the value of $_SERVER['SCRIPT_NAME']:

  • When FcgidFixPathinfo is set to 0 in the httpd.conf file, $_SERVER['SCRIPT_NAME'] is correct (/test.php), regardless of the value of cgi.fix_pathinfo in the php.ini file.

  • When FcgidFixPathinfo is set to 1 in the httpd.conf file, $_SERVER['SCRIPT_NAME'] is incorrect (C:/test.php), regardless of the value of cgi.fix_pathinfo in the php.ini file.



来源:https://stackoverflow.com/questions/21265469/php-serverscript-name-is-wrong-when-loading-php-via-mod-fcgid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!