Last modified: 2013-02-09 14:58:14 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T11330, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 9330 - Error with non standard http port under apache and php in cgi-mode
Error with non standard http port under apache and php in cgi-mode
Status: RESOLVED WORKSFORME
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.9.x
PC Windows XP
: Low major (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-03-18 23:49 UTC by Etienne Durup
Modified: 2013-02-09 14:58 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Etienne Durup 2007-03-18 23:49:14 UTC
I run Apache2 on Windows, with PHP 5.2.0 in cgi mode (php-cgi.exe).
The Apache localhost server listen ports 2710, 2711 and 2712 (and IIS listen on 80).
URL of my MediaWiki :
http://localhost:2712/mediawiki/index.php?title=Accueil

In this case, $_SERVER[HTTP_PORT] gives always 80.
When I edit a page :
 - editing goes right
 - also good with previsualisation 
 - but "save" goes back to http://localhost/mediawiki/.... and fail 

The addition of following lines next line 70 in includes/DefaultSettings.php
solves the problem :

# Get the true http host port if exists even in cgi mode
if ( isset($_SERVER['HTTP_HOST'] )
  &&  strpos($_SERVER['HTTP_HOST'],':') !==false ) {
  preg_match('/.*\:(.*)/',$_SERVER['HTTP_HOST'],$matches);
  $wgServerHostPort = $matches[1];
  $_SERVER['SERVER_PORT'] = $wgServerHostPort;
}

I can't verify if this creates a new bug in other cases. I don't believe that
but... who knows ?
I've verified that this algorithm goes right under apache and IIS in cgi-mode
with php5 and php4 (with other app).

Make a simple test in many web server configurations and you'll get big surprises :
foreach ($_SERVER as $key=>$val) {
echo "$key = $val<br>";
}

Because that, I don't use $SERVER['SCRIPT_NAME'], $_SERVER['SERVER_PORT'],
$SERVER['SCRIPT_FILENAME']  anymore. It's not portable and this breaks ascendant
compatibility.

(For example, the first one with PHP4 returns /php/php.exe in cgi-mode ; with
PHP5 it is corrected and returns the php script path)

My two cents.
Regards
Comment 1 Andre Klapper 2013-01-29 20:47:51 UTC
Hi Etienne! Sorry that nobody has taken a look at this report yet and given feedback.

As the HTTP_HOST code which existed in MediaWiki 1.9 :
https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/core.git;a=blame;f=includes/DefaultSettings.php;hb=1ceeed99432e2715b958df4810a94d3e8f4ea2fa#l43
does not exist in the current codebase anymore:
https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/core.git;a=blame;f=includes/DefaultSettings.php;h=6a4f6a60a37f40e063585f16b0abe77472c6a7f8;hb=HEAD
I assume that the problem and also the provided workaround is obsolete nowadays.
If it's not, please tell us which MediaWiki version you use.
Also see the comments about "CGI mode" in that source file.
Comment 2 Bawolff (Brian Wolff) 2013-02-06 15:49:16 UTC
(In reply to comment #1)

> As the HTTP_HOST code which existed in MediaWiki 1.9 :
> https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/core.git;a=blame;
> f=includes/DefaultSettings.php;
> hb=1ceeed99432e2715b958df4810a94d3e8f4ea2fa#l43
> does not exist in the current codebase anymore:
> https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/core.git;a=blame;
> f=includes/DefaultSettings.php;h=6a4f6a60a37f40e063585f16b0abe77472c6a7f8;
> hb=HEAD

that's because it got moved to WebRequest::detectServer...

However, with that said, newer versions of MW set the host (and port) at install time, so this issue is much less likely to strike [while, I suppose if the installer mis-detects that would still cause badness]. If you are still having problems with host/port auto-detection the correct work around is to set $wgServer = "http://mywebsite.com:8080"; or whatever your server is, in you LocalSettings.php (and still re-open the bug, because the auto-detection should work)
Comment 3 Etienne Durup 2013-02-09 14:58:14 UTC
Better late than never ;-)
And I don't use version 1.9 anymore.
However thank you for feedback !

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links