Page MenuHomePhabricator

webstart tries to get realpath to set $IP instead of using dirname(__DIR__)
Closed, ResolvedPublic

Description

This caused the installer to fail on a webhost that was using Windows. Changing $IP to dirname(__DIR__) or dirname(dirname(__FILE__)) worked.


Version: 1.20.x

Patch:

Details

Reference
bz44132

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 1:26 AM
bzimport set Reference to bz44132.
bzimport added a subscriber: Unknown Object (MLST).

p.selitskas wrote:

I'm not sure if it's relevant, but on Windows I sometimes get an error from load.php (it fails randomly I guess):

Warning: require_once(Z:\usr\local\apache\bin/includes/Init.php) [function.require-once]: failed to open stream: No such file or directory in E:\Wikimedia\mediawiki\core\includes\WebStart.php on line 94
Fatal error: require_once() [function.require]: Failed opening required 'Z:\usr\local\apache\bin/includes/Init.php' (include_path='.;C:\php\pear') in E:\Wikimedia\mediawiki\core\includes\WebStart.php on line 94

With your patch Id7cd604d applied, I get something way more weird:

Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required 'Z:/home/wikimedia/mw/load.php' (include_path='.;C:\php\pear') in Unknown> on line 0

It may be related. I've updated my commit message to say exactly why WebStart was failing: realpath returned false.

What version of PHP are you using?

p.selitskas wrote:

(In reply to comment #2)

What version of PHP are you using?

PHP Version 5.3.13 (Build MSVC9 (Visual C++ 2008)); Apache/2.2.22

The patch on 44157 has a better fix for this -- could you try it out?

p.selitskas wrote:

(In reply to comment #5)

bug 44157, that is, points to https://gerrit.wikimedia.org/r/44832

No, it still throws an error sometimes, trying to require_once(Z:\usr\local\apache\bin/includes/Init.php).

For the record: document root for my MediaWiki instance is Z:/home/wikimedia/mw/, and it's actually an NTFS symlink to another path. May this fail be a consequence of such scheme?

(I actually don't strive for better Windows support, as it's just so mess with all work-arounds, but if it can be fixed without any collateral damage, then I hope my reports will be in some way useful.)

I have a windows system that I can test on, but I'm NTFS ignorant. How can I create one of these NTFS symlinks? That does sound like a probable suspect.

Hrm... Another possibility, the realpath("."). It sounds like this is being executed when the webserver's path is z:\usr\local\apache\bin and it decides that is the value for $IP, not MW's root.

Is the path for require_once correct? Is Init.php at Z:\usr\local\apache\bin/includes/Init.php ??

p.selitskas wrote:

(In reply to comment #7)

I have a windows system that I can test on, but I'm NTFS ignorant. How can I
create one of these NTFS symlinks? That does sound like a probable suspect.

Hrm... Another possibility, the realpath("."). It sounds like this is being
executed when the webserver's path is z:\usr\local\apache\bin and it decides
that is the value for $IP, not MW's root.

Is the path for require_once correct? Is Init.php at
Z:\usr\local\apache\bin/includes/Init.php ??

According to Wikipedia, a symlink is made with the following command:

mklink /D linkName target

No, it seems like in some situations $IP is set to "Z:/usr/local/apache/bin", not the actual MediaWiki path. Init.php is at Z:/home/wikimedia/mw/includes/Init.php. Z:/usr/local/apache/bin is the path where httpd.exe lives.

If you have a Windows installation, please test these. On my side, I'll try to debug that piece of code to learn what environment does the code execute in, when it fails.

(In reply to comment #8)

No, it seems like in some situations $IP is set to "Z:/usr/local/apache/bin",
not the actual MediaWiki path. Init.php is at
Z:/home/wikimedia/mw/includes/Init.php. Z:/usr/local/apache/bin is the path
where httpd.exe lives.

Right. This makes complete sense.

Now, the question is why does apache/php sometimes execute the the php files from the apache directory instead of the script's directory? Is it just not setting the CWD?

p.selitskas wrote:

(In reply to comment #9)

(In reply to comment #8)

No, it seems like in some situations $IP is set to "Z:/usr/local/apache/bin",
not the actual MediaWiki path. Init.php is at
Z:/home/wikimedia/mw/includes/Init.php. Z:/usr/local/apache/bin is the path
where httpd.exe lives.

Right. This makes complete sense.

Now, the question is why does apache/php sometimes execute the the php files
from the apache directory instead of the script's directory? Is it just not
setting the CWD?

I dunno. I wish I did. Here is some info for further consideration.

When load.php doesn't fail, we have the following data ($IP is the current $IP, realpath - realpath( '.' ) called once again for debugging, dirname - dirname( DIR ), dir - DIR itself):
$IP: E:\Wikimedia\mediawiki\core
realpath: E:\Wikimedia\mediawiki\core
dirname: E:\Wikimedia\mediawiki\core
dir: E:\Wikimedia\mediawiki\core\includes

As you see, all symlinks were resolved into proper paths (not Z:\home\...). When load.php fails, we have the following picture:
$IP: Z:\usr\local\apache\bin
realpath: Z:\usr\local\apache\bin
dirname: E:\Wikimedia\mediawiki\core
dir: E:\Wikimedia\mediawiki\core\includes

According to the logics of present code, realpath should have failed and return false, thus giving MediaWiki a way to fall back to dirname, but it didn't, and moreover it provides a wrong path...

do you control the configuration of apache and php on this host? Would you mind emailing them directly to me?

This bug is fixed since gerrit change Id178ee2f

Krinkle added a project: MW-1.21-release.
Krinkle updated the task description. (Show Details)