Page MenuHomePhabricator

Stop using realpath to set $IP in WebStart
Closed, ResolvedPublic

Description

I have setup as follows:

/www/domain/docroot/w is a symlink to /srv/mediawiki/targets/production
/srv/mediawiki/targets/production is a symlink to /srv/mediawiki/tags/XXX

If I enable repo authoritative mode and compile bytecode cache for hhvm using:

find -L /www/domain/docroot -name "*.php" > $FL
hhvm --hphp -t hhbc  -v AllVolatile=true --input-list $FL

Then I get errors as follows:

Fatal error: require_once(/srv/mediawiki/tags/XXX/includes/profiler/ProfilerFunctions.php): File not found in /www/domain/docroot/w/includes/WebStart.php on line 64

This is because of the following code:

# Full path to working directory.
# Makes it possible to for example to have effective exclude path in apc.
# __DIR__ breaks symlinked includes, but realpath() returns false
# if we don't have permissions on parent directories.
$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
        $IP = realpath( '.' ) ?: dirname( __DIR__ );
}

I am not sure whether apc is really concern anymore, as apc itself no longer exists.

It seems it would be possible to override this with an environment variable, but I am not sure how to pass it to HHVM.

Event Timeline

SamanthaNguyen subscribed.

I believe this is the correct project tag, please correct me if I'm wrong :)

It seems it would be possible to override this with an environment variable, but I am not sure how to pass it to HHVM.

https://serverfault.com/questions/351696/how-do-you-set-server-specific-env-values-in-nginx since I think you're using nginx?

Change 393713 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] [WIP] WebStart: Remove use of realpath() for $IP

https://gerrit.wikimedia.org/r/393713

This use of realpath( '.' ); in assigning $IP also breaks if loading MediaWiki indirectly from a different file.

For example, if MediaWiki is installed in the typical /w/ subdirectory, we recommend using a rewrite rule to make / still respond from /w/index.php. However, that requires configuration specific to Apache. In the mediawiki-docker-dev project, I'm trying to instead take the approach WordPress takes by placing an index.php in the document root that simply includes __DIR__ . '/w/index.php'; instead.

At first this seems to work (document root index.php -> mediawiki index.php -> WebStart). And WebStart includes various other files without problems, but then it starts using $IP to load Setup.php, and that one fails.

In the above case, realpath('.'); resolves to where the PHP script starts:

Fatal error: require_once(): Failed opening required '/var/www/includes/Setup.php' (include_path='.:/usr/local/lib/php') in /var/www/mediawiki/includes/WebStart.php on line 97
Stack trace:

  1. {main}() /var/www/index.php:0
  2. require() /var/www/index.php:3
  3. require() /var/www/mediawiki/index.php:40
Krinkle claimed this task.
Krinkle triaged this task as Medium priority.
Krinkle edited projects, added Performance-Team; removed Patch-For-Review, HHVM.

Change 393713 merged by jenkins-bot:
[mediawiki/core@master] WebStart: Remove use of realpath() for $IP

https://gerrit.wikimedia.org/r/393713