17

我有一个托管站点,但在配置 Joomla 时遇到问题(在 IIS7 上运行 Joomla + php + mySQL + win server 2008)。我在本地机器上运行了类似的配置(IIS7 + vista x64 上的 Joomla + php + mySQL),所以我至少能够按照各种教程中关于如何设置它的说明进行操作。

托管站点的这种症状是我无法在 Joomla 中打开任何 SEO 设置(甚至不是第一个设置,“搜索引擎友好 URL”)。我得到 404(未找到文件)或 URL 显示正确重写,但始终显示主页的内容。我在我的家用机器上遇到了类似的问题,原来是因为我没有使用 FastCGI 来托管 php,所以我决定在托管站点上进行调查。

无论如何,我在托管站点上托管 joomla 的目录的 web.config 文件中注意到以下行:

<add name="Plesk_Handler_3522909676" path="*.php" verb="*" modules="IsapiModule" scriptProcessor="c:\program files (x86)\parallels\plesk\additional\pleskphp5\php5isapi.dll" resourceType="Either" />

根据过去的经验,我知道 php 在 fastCGI 下不运行时会出现一些问题。我注意到根文件夹中的 web.config 使用了以下行:

<add name="Plesk_Handler_0286090609" path="*.php" verb="*" modules="CgiModule" scriptProcessor="c:\program files (x86)\parallels\plesk\additional\pleskphp5\php-cgi.exe" resourceType="Either" /> 

我将它复制到 joomla 目录的 web.config 中,并得到了不同的行为......但仍然无法正常工作。如果我在运行 phpInfo() 的 joomla 目录中加载 .php 文件,则在 Server API 下它会显示 CGI/FastCGI 。这是对正在使用 FastCGI 的肯定确认吗?为什么 web 配置中的处理程序指向 modules="CgiModule" 而不是 modules="FastCgiModule" (我什至不确定是否存在,但我只是发现提到 CgiModule 很可疑)。

这是一个托管站点,据我所知,我无权访问 ApplicationHost.config 文件...

4

8 回答 8

29

这是一个简单的测试:

  1. 创建一个 phpinfo.php 文件

 <?php phpinfo(); ?> 

里面;

  1. 请求http://yoursite.com/phpinfo.php/foobar?foo=bar

  2. 检查 phpinfo 的输出并查找 _SERVER["REQUEST_URI"]。

如果缺少此变量,则使用 CGI。如果变量存在并正确设置为 /phpinfo.php/foobar?foo=bar,则使用 ISAPI 或 FastCGI。查看服务器 API 的输出顶部附近;它应该设置为 ISAPI(这意味着正在使用 ISAPI)或 CGI/FastCGI(这意味着正在使用 FastCGI,因为我们已经排除了 CGI)。

于 2009-03-17T01:09:49.787 回答
5

php_sapi_name() 或 PHP_SAPI 都可以。

http://php.net/manual/en/function.php-sapi-name.php

<?php
    if (php_sapi_name() != 'cgi-fcgi'){
        echo 'I knew fastcgi wasn\'t working.';
    }else{
        echo 'Holy crap, something worked for once.';
    }
于 2016-04-01T19:12:08.400 回答
4

您可以使用 (on centos) apachectl -M,您将显示启用了哪些模块:

apachectl -M:

file_cache_module (shared)
mem_cache_module (shared)
version_module (shared)
fastcgi_module (shared)
于 2014-01-30T17:49:24.303 回答
2

不幸的是,检查\_SERVER["REQUEST_URI"]对我不起作用。使用CGIFastCGI,它总是显示/phpinfo.php/foobar?foo=bar

也没有看到是否Server API = CGI/FastCGI已设置 - 它只告诉您编译后的 php 版本支持哪些接口,而不是正在使用什么。但是,我发现了另一种可能更可靠的方法。

Plonk 一个名为phpinfo.php的文件,其中包含以下文本:<? php phpinfo(); ?>

检查变量\_ENV["REDIRECT_HANDLER"]
如果它设置为php5-fastcgi(或其他 fastcgi-ish),则请求很可能通过FastCGI。如果它被设置为application/x-httpd-php(或者我假设不是上面的),你正在使用CGI

然而,一个万无一失的方法是运行一个小测试。为此,您需要ab(Apache Bench) 工具。
无论有没有 CGI,都可以从另一台机器上运行:

ab -c 100 -n 1000 http://yourdomain.com/path/phpinfo.php

检查线路Time taken for tests:。至少在我的机器上,通过 1.3Mbps ADSL 连接访问我的 VPS,FastCGI 将其完全最大化,而使用 CGI 只能填充一半。

希望这可以帮助。

于 2009-07-25T05:53:47.170 回答
1

你应该看到从

<?php
phpinfo();
?>

服务器 API = CGI/FastCGI

于 2009-03-04T04:05:28.057 回答
0

Joomla 创建一个 .htaccess 文件,其中包含重写规则,以启用搜索引擎友好的 URL。如果您使用的是 Apache,则需要为包含您的 joomla 安装的目录设置“AllowOverride FileInfo”。如果您使用的是 IIS,您将需要一个模块,例如 IISModRewrite。以下是相关说明:[ http://www.micronovae.com/ModRewrite/articles/SEFJoomla.html]

于 2009-03-06T20:42:35.477 回答
0

确保在 fastcgi 未运行时,最初设置为脚本完全失败的位置。然后你就会知道,当它工作时,fastcgi 守护进程就是原因。

于 2010-08-02T14:14:36.050 回答
0

这对我有用。

/**
 * return phpinfo() results as an array
 *
 * @credit http://php.net/manual/en/function.phpinfo.php#106862
 * @param void
 * @return array
 */
function phpinfo_array(){
    ob_start();
    phpinfo();
    $info_arr = array();
    $info_lines = explode("\n", strip_tags(ob_get_clean(), '<tr><td><h2>'));
    $cat = 'general';
    foreach($info_lines as $line){
        preg_match('/<h2>(.*)<\/h2>/', $line, $title) ? $cat = preg_replace('/\s+/', '_', strtolower(trim($title[1]))) : null;
        if(preg_match('/<tr><td[^>]+>([^<]*)<\/td><td[^>]+>([^<]*)<\/td><\/tr>/', $line, $val)){
            $subcat = preg_replace('/\s+/', '_', strtolower(trim($val[1])));
            $info_arr[$cat][$subcat] = $val[2];
        } elseif(preg_match('/<tr><td[^>]+>([^<]*)<\/td><td[^>]+>([^<]*)<\/td><td[^>]+>([^<]*)<\/td><\/tr>/', $line, $val)){
            $subcat = preg_replace('/\s+/', '_', strtolower(trim($val[1])));
            $info_arr[$cat][$subcat] = array('local' => $val[2], 'master' => $val[3]);
        }
    }
    return $info_arr;
}


// output proper response code
$phpinfo = phpinfo_array();
$configure = (@isset($phpinfo['general']['configure_command'])) ?: null;

// properly account for FastCGI
if ($configure && preg_match('/--enable-fastcgi/', $configure)){
    // fastcgi response
    header('Status: 403 Access is forbidden');
} else {
    // http response
    header('HTTP/1.0 403 Access is forbidden');
}
于 2012-09-27T19:20:20.567 回答