1

I use Ubuntu 20.04, Apache/2.4.41 (Ubuntu), PHP 8.0.3 and mediawiki-1.35.1. I extracted mediawiki-1.35.1 archive in /var/www/html/, created symbolic link to its contents in another directory, for example var/www/html/m1:

$ ln -s /var/www/html/mediawiki-1.35.1/* /var/www/html/m1/

Then I pointed my browser to localhost/m1 and set up the wiki in regular way and put downloaded LocalSettings.php in var/www/html/m1. Then again I pointed my browser to localhost/m1 but the result was:

MediaWiki 1.35.1
LocalSettings.php not found.
Please set up the wiki first.

Then I moved downloaded LocalSettings.php to /var/www/html/mediawiki-1.35.1 and now localhost/m1 shows the main page of wiki. That is strange; because I think symbolic links must work as their target.

Really I want to set up multiple wikis on the same server. Previously I did what I described in Ubuntu 16.04 and mediawiki-1.30.0 and that worked. Now I want to know how I can fix that problem without needing to do the complex instructions of creating wiki family?

3 Answers 3

3

Since the marked correct answer means copying ~27.5mb as of MediaWiki 1.38.1, which largely defeats the purpose of using symlinks, I found an alternative solution that avoids copying anything extra.

Edit Original Files Instead of Copying Them

  1. Open the folder containing the original files that are symlinked elsewhere
  2. Make backup copies of index.php, load.php, & Includes/WebStart.php as a precaution
  3. For each of the above files, replace any instance of dirname(__FILE__) or __DIR__ with dirname($_SERVER['SCRIPT_FILENAME'])
  4. Save and close files

That's it! The changes should flow through to any wiki that's symlinked to the source you edited.

Explanation:

dirname($_SERVER['SCRIPT_FILENAME']) respects the SymLink location where __FILE__ and __DIR__ don't.

Source: https://stackoverflow.com/questions/13771021/php-dir-or-file-symlinked

Warning:

  1. I confirmed that loading, logging in/out works, and editing/creating pages work before posting this, but I did not test all wikimedia functions. Additional files may require editing for full functionality.
  2. I'm not certain how this may interact with .htaccess redirects to non-existent folders

Follow-up error & resolution

The above solution breaks the web-installation guide for a new wiki. If your new wiki is installed in a sub-directory of the root directory for your website, the following should work:

  1. Open that Includes/WebStart.php file once more
  2. Look for the line that defines $IP. Should start with $IP =
  3. Replace it with $IP = $_SERVER['DOCUMENT_ROOT'].explode("/", $_SERVER['REQUEST_URI'])[1]."/";
  4. Save and close the file.

Explanation

You need the equivalent of __DIR__, but __DIR__ doesn't respect symbolic links, and dirname($_SERVER['SCRIPT_FILENAME']) works with relative links, which means it breaks things when called from the config sub-folder. The new solution has the following pieces:

  • $_SERVER['DOCUMENT_ROOT] - This is the directory for your site.
  • . - PHP glue to connect string variables
  • explode("/",*string*) - explode breaks the string into pieces around each "/"
  • $_SERVER['REQUEST_URI'] - The string we're exploding, which contains the pieces of the address following the root.
  • [1] - The location of the string we want to keep within the exploded array. Note: an exploded "/moo/index.php" string would have locations & values of [0] = "", [1] = "moo", and [2] = "index.php"
  • . - more glue holding the string variables together
  • "/" - restores the slash removed in the explode so "moo/index.php" doesn't get searched for with "mooindex.php"

If you stored your wiki in a sub-directory of a sub-directory, you would need to add .explode("/", $_SERVER['REQUEST_URI'])[2]."/" just before the semicolon, since you would need both the first and second parts of the exploded string.

1

Your LocalSettings.php is included, ultimately, by /var/www/html/mediawiki-1.35.1/index.php: this is the PHP program that runs. It looks for included files in its home directory, which is /var/www/html/mediawiki-1.35.1, not in another directory that happens to contain a symbolic link to index.php.

4
  • Mediawiki uses dirname( __FILE__ ) to determine what directory it is running from. It isn't like the directory is hard coded into index.php. I'd think that a symbolic link could cause that function to output the directory that contains the symlink. Commented Mar 22, 2021 at 9:12
  • 1
    stackoverflow.com/a/3304606/6632736 says that __FILE__ resolves symlinks and $_SERVER["SCRIPT_FILENAME"] doesn't, which is what I would expect. Commented Mar 22, 2021 at 9:41
  • @StephenOstermiller OK! But how I can solve the problem? Commented Mar 22, 2021 at 14:23
  • @AlexanderMashin I added main part of index.php to the question. How I can solve the problem? Commented Mar 22, 2021 at 14:28
1

I removed symlinks to includes/, load.php and index.php of /var/www/html/mediawiki-1.35.1/ and copy them to the /www/html/m1. This solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.