IIS 7 and Above
How to know for sure if FastCGI is being used to run php scripts
Last post Mar 10, 2009 05:41 PM by jtalbot
Mar 03, 2009 09:23 PM|jtalbot|LINK
I have a hosted site and I'm having trouble configuring Joomla (running Joomla + php + mySQL on IIS7 + win server 2008). I have a similar configuration running on a local machine (Joomla + php + mySQL on IIS7 + vista x64), so I was at least able to follow
instructions showed in various tutorials on how to set this up.
This symptom with the hosted site is that I can't turn on any SEO settings in Joomla (not even the first setting, "Search Engine Friendly URLs"). I get either 404 (file not found) or the URL appears correctly rewritten but it's always the home page's content
that is displayed. I had a similar issue on my home machine and it turns out to have been because I wasn't using FastCGI to host php, so I decided to investigate that on the hosted site.
Anyway, I noticed in the web.config file of the directory hosting joomla on the hosted site the following line:
<add name="Plesk_Handler_3522909676" path="*.php" verb="*" modules="IsapiModule" scriptProcessor="c:\program files (x86)\parallels\plesk\additional\pleskphp5\php5isapi.dll" resourceType="Either" />
From past experience, I know that php has some issues when not running under fastCGI. I noticed the web.config in the root folder used the following line instead:
<add name="Plesk_Handler_0286090609" path="*.php" verb="*" modules="CgiModule" scriptProcessor="c:\program files (x86)\parallels\plesk\additional\pleskphp5\php-cgi.exe" resourceType="Either" />
I copied that in the web.config in the joomla directory, and got different behavior... but still not working. If I load a .php file in the joomla directory that runs phpInfo(), under
Server API it says
CGI/FastCGI . Is that positive confirmation that FastCGI is being used? Why does the handler in the web config point to
modules="CgiModule" instead of modules="FastCgiModule" (I'm not even sure that exists, but I just find the mention of CgiModule suspicious).
It's a hosted site, so as far as I know I don't have access to
Mar 03, 2009 10:52 PM|ruslany|LINK
Based on the symptoms you described and based on the handlers configuration examples, it looks like your hoster provides PHP either via ISAPI or via CGI. Both of those are not recommended for running PHP on windows as they cause application compatibility
issues as well as stability or performance problems.
Mar 04, 2009 10:33 AM|jtalbot|LINK
Yeah, I think so too, but is there a way to get certainty about this?
Mar 04, 2009 12:55 PM|ruslany|LINK
An easy way to test that is:
If this variable is available and is set to /phpinfo.php/foobar/?foo=bar, then FastCGI is used. If it is not set or is set to just /phpinfo.php, then you use CGI or ISAPI respectively.
The lack of REQUEST_URI or its incorrect value is what causing application compatibility issues.
Mar 04, 2009 07:25 PM|jtalbot|LINK
That's an awesome answer! Just the kind of details I was lookin for. However, such a good answer is bound to lead to more questions :)
I eagerly went ahead to try the test you suggested... but unfortunately the results I got don't quite seem to match up what you described.
First the URI /phpinfo.php/foobar/?foo=bar returned a 404. I used /phpinfo.php/foobar?foo=bar (without the / after foobar, before the ?) and that seemed to work fine.
If I set up the web.config file to use CGI, then phpInfo() returns ServerAPI = CGI/FastCGI (so it's ambiguous as to whether it's using CGI or FastCGI, but it's not using ISAPI). In that case, _SERVER["REQUEST_URI"]
is absent (which I assume is equivalent to not being set) -- so this matches what you describe.
However, if I set up the web.config file to use ISAPI, then phpInfo() returns ServerAPI = ISAPI (so I assume that means I properly set it up to use ISAPI). Yet, _SERVER["REQUEST_URI"] returns the full request (/phpinfo.php/foobar?foo=bar) (actually I'm in
a subdirectory, so the result is /joomla156_mx/test.php/foobar?foo=bar -- I assume the subdirectory doesn't make a difference).
I don't know if that means the host has done 'something' to fix ISAPI, or if I screwed up the test, or if you got it wrong in your post.
So do the above results mean that using ISAPI would be better than using CGI, meaning less likely to have incompatibility for php?
Is there a list of other incompatibilites that can occur when using ISAPI or CGI documented somewhere, or is _SERVER["REQUEST_URI"] the only issue?
Are you familiar with joomla, and more specifically the SEO settings in joomla?
Mar 04, 2009 07:54 PM|ruslany|LINK
Using ISAPI will still cause incompatibility issues when you use URL Rewriter to enable SEO URL's in joomla. The problem is that when you use URL Rewriter the ISAPI will set REQUEST_URI to contain the rewritten url, which, according to the Joomla rewrite
rule, will always be index.php. Joomla uses that server variable to figure out which page to serve so it ends up always showing the home page for any URL you requested.
If you use FastCGI then Joomla SEO functionality should work properly because FastCGI module will set the REQUEST_URI correctly, i.e. to contain the original URL before any rewriting happened.
Mar 05, 2009 07:33 AM|jtalbot|LINK
Hmm, but according to the tests described in my previous post, when using ISAPI the variable
REQUEST_URI does contain the full URI with the request -- are you saying even if that's true, joomla SEO will still not work?
I asked the host why they can't let me use FastCGI with php; their answer was:
"The FastCGI doesn't like the dedicated pools that we use for each site."
This might not be enough information, but do you know if this is in fact a known issue, or if there is a how-to somewhere for getting FastCGI to work with dedicated pools?
Mar 05, 2009 01:05 PM|ruslany|LINK
In your test you did not use url rewriting. If you used URL rewriting then the REQUEST_URI would contain the rewritten URL. You can confirm that by creating this simple rewrite rule:
<match url="foo\.html" />
<action type="Rewrite" url="phpinfo.php" />
Then request http://yoursite.com/foo.html and check what's the value of $_SERVER["REQUEST_URI"]. You will see that the value is "/phpinfo.php". For Joomla SEO to work the value needs to be "/foo.html".
I am not sure I understand the reason for not supporting FastCGI. The answer is too generic. FastCGI works fine when there are separate application pools for each site. It is actually the recommended way of using FastCGI in shared hosting enviornment.
Mar 10, 2009 05:41 PM|jtalbot|LINK
I haven't looked at the joomla source code yet, but would it be correct to say that the joomla SEO code could be modified to work with IIS running php as either cgi, ISAP, or FastCgi? I assume there is either a different variable than REQUEST_URI that can
be used that has the same information?