Topic on Project:Support desk

Parse error: Unexpected "$wikiId" in Localsettings.php

55
Newman2 (talkcontribs)

MediaWiki Version: 1.30

PHP Version: 5.6.36 (litespeed)

MySQL Version: 5.6.39-cll-lve

ICU Version: 57.1

Hello. When I attempted to set up a wiki family on the Localsettings.php of my wiki, I get an error with the following message: PHP Parse error:  syntax error, unexpected '$wikiId' (T_VARIABLE) in /home/gjlxrtap/public_html/mw19/LocalSettings.php on line 259. The code that caused the error while attempting to create the wiki family is:

if ( defined( 'gjlxrtap_pnwiki' ) ) {

''// Set $wikiId from the defined constant 'MW_DB' that is set by maintenance scripts.''

$wikiId = penguinicewiki;

} elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'wiki1.example.org') {

''// Add a value to the $wikiId variable for e.g. https://wiki1.example.org/''

$wikiId = 'wiki1';

} else {

''// Fail gracefully if no value was set to the $wikiId variable, i.e. if no wiki was determined''

die( 'It was not possible to determine the wiki ID.' );

}

if ($wikiId == 'wiki1') {

    $wgSitename = "Penguingame Studio";

    $wgServer = "http://penguingamestudio.com";

    $wgLogo = "ExampleWiki_logo.png";

    $wgDBpassword = "we39585f7ha34";

    $wgSecretKey = "9348vhas589ytas35aurhgao94aywrotuhapw94u";

    $wgLanguageCode = 'en';

}if ($wikiId == 'wiki1') {

    $wgSitename = "Penguingame Studio";

    $wgServer = "http://penguingamestudio.com";

    $wgLogo = "ExampleWiki_logo.png";

    $wgDBpassword = "-----------------";

    $wgSecretKey = "------------------------------";

    $wgLanguageCode = 'en';

}

What can I do to fix this error? I have no idea on what to do here, I never expected to get errors like this. Thank you for reading.

Clump (talkcontribs)

Not sure which line is line # 259, but unless penguinicewiki is a predefined constant I would guess it's the line "$wikiId = penguinicewiki;", where you probably should've either assigned the MW_DB constant, or the string 'penguinicewiki'.

Newman2 (talkcontribs)

I changed it to MW_DB, and it still gives me the same error. And line 259 is the very line that should have the MW_DB constant.

Clump (talkcontribs)

Is "// Set $wikiId from the defined constant 'MW_DB' that is set by maintenance scripts." literally in your file? That is supposed to be a comment, not a string...

The error is because php is encountering a variable ($wikiId) in a place where it makes no sense. So something is syntactically wrong with your file.

Newman2 (talkcontribs)

The error actually occurs with the line that has the following: $wikiId = penguinicewiki

Ciencia Al Poder (talkcontribs)

Shouldn't that line be:

$wikiId = 'penguinicewiki';

?

Newman2 (talkcontribs)

I'm not sure whether the central wiki ID will work the same way with any ID, or if the wiki ID of penguinicewiki should be the same as the if ( defined( 'gjlxrtap_pnwiki' ).

2001:16B8:109A:6600:99CC:A011:191E:55A5 (talkcontribs)

In how far does that have to do with the syntax error, which PHP is throwing?

Does this syntax error go away, if you adjust the code as told by Ciencia?

Newman2 (talkcontribs)

If penguinicewiki would be an unexpected wiki ID, then what can I do to fix this?

星耀晨曦 (talkcontribs)

Looks like penguinicewiki is not a problem, because you got a PHP Parse error, if it is other error, you will get other type messages of the error. A PHP Parse error, mostly because of syntax errors in the code, have nothing to do with the logic of the application.

So you should check the context of the 259 line for syntax error first. If you can't check, you can also post the context of the 259 line here and let us check (pay attention to attach the line number).

Newman2 (talkcontribs)

Do you even notice that line 259 is $wikiId = penguinicewiki?

121.219.12.173 (talkcontribs)

Which is clearly invalid (should be a "string"), along with your comments being invalid syntax as already mentioned.

Clump (talkcontribs)

An error the parser encounters on line 259 could be caused by malformed code on a previous line. If on line 258 you literally have
"// Set $wikiId from the defined constant 'MW_DB' that is set by maintenance scripts."
then that is likely source of the syntax problem, as that is a string, not a comment. It should be
// Set $wikiId from the defined constant 'MW_DB' that is set by maintenance scripts.
Note the lack of quotes. Also note that you have several comment-lines wrapped in quotes.

Newman2 (talkcontribs)

I just removed the double apostrophes from the comments. Now it only fails gracefully with the following message: It was not possible to determine the wiki ID. What can I do to make it determine the wiki ID?

Clump (talkcontribs)

Not sure, but $wikiId = penguinicewiki; is almost certainly wrong. Try Ciencia's suggested fix:
$wikiId = 'penguinicewiki';
Also note that you have two if-blocks at the end, both testing whether the wikiId is 'wiki1' but doing different things.

Newman2 (talkcontribs)

I just fixed the penguinicewiki variable, and my wiki still fails with the code. What do I do then?

Newman2 (talkcontribs)

^Read above.

Samwilson (talkcontribs)

@Newman2: can you post your current LocalSettings config (same as you did above, but with the changes you've made since)?

Newman2 (talkcontribs)
if ( defined( 'MW_DB' ) ) {

// Set $wikiId from the defined constant 'MW_DB' that is set by maintenance scripts.

$wikiId = 'penguinicewiki';

} elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'en.penguingamestudio.com') {

// Add a value to the $wikiId variable for e.g. <nowiki>https://wiki1.example.org/</nowiki> 

$wikiId = 'wiki1';

} else {

// Fail gracefully if no value was set to the $wikiId variable, i.e. if no wiki was determined

die( 'It was not possible to determine the wiki ID.' );

}

if ($wikiId == 'wiki1') {

    $wgSitename = "Penguingame Studio";

    $wgServer = "<nowiki>http://penguingamestudio.com</nowiki>";

    $wgLogo = "ExampleWiki_logo.png";

    $wgDBpassword = "we39585f7ha34";

    $wgSecretKey = "9348vhas589ytas35aurhgao94aywrotuhapw94u";

    $wgLanguageCode = 'en';

}
Samwilson (talkcontribs)

You should use MW_DB to get the wiki ID if possible, and but apart from that it should be okay:

<?php
if ( defined( 'MW_DB' ) ) {
    $wikiId = MW_DB;
} elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] === 'en.penguingamestudio.com') {
    $wikiId = 'wiki1';
} else {
    die( 'It was not possible to determine the wiki ID.' );
}
if ($wikiId === 'wiki1') {
    $wgSitename = "Penguingame Studio";
    $wgServer = "http://penguingamestudio.com";
    $wgLogo = "ExampleWiki_logo.png";
    $wgDBpassword = "we39585f7ha34";
    $wgSecretKey = "9348vhas589ytas35aurhgao94aywrotuhapw94u";
    $wgLanguageCode = 'en';
}
Ciencia Al Poder (talkcontribs)

Please change your secret key and database password on your server, because you've leaked it publicly

Newman2 (talkcontribs)

Done. I will try not to leak anymore of my passwords in the future. I also changed the penguinicewiki variable to MW_DB, and it didn't fix the issue with the wiki ID.

Samwilson (talkcontribs)

There must be an issue with determining the server name. If you var_dump($_SERVER['SERVER_NAME']); what do you see? Are you serving the wiki from en.penguingamestudio.com or penguingamestudio.com (I assume the former)?

I'm guessing the idea here is to have separate language subdomains with separate wikis, all running from the same MediaWiki directory? If so, you probably want to extract the language code from the domain name and use it as part of the wiki ID. You can then also use it to set things like $wgLanguageCode and $wgServer (after validating it of course).

Newman2 (talkcontribs)

I used var_dump and got the following error: string(19) "penguinicewikis.com" It was not possible to determine the wiki ID. I also serve my second wiki at en.penguingamestudio.com, with my central wiki located at penguinicewikis.com.

Samwilson (talkcontribs)

Okay, so you probably want something along the lines of the following (I've removed the passwords etc. just to make it clearer; you'll need to add them for each wiki).

<?php
if ( defined( 'MW_DB' ) ) {
    $wikiId = MW_DB;
} elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] === 'penguinicewikis.com') {
    $wikiId = 'main';
} elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] === 'en.penguingamestudio.com') {
    $wikiId = 'en';
} else {
    die( 'It was not possible to determine the wiki ID.' );
}
if ($wikiId === 'main') {
    $wgSitename = "Penguinice Wikis";
    $wgServer = "http://penguinicewikis.com";
    $wgLanguageCode = 'en';
}
if ($wikiId === 'en') {
    $wgSitename = "Penguingame Studio";
    $wgServer = "http://en.penguingamestudio.com";
    $wgLanguageCode = 'en';
}
Newman2 (talkcontribs)

I did it. I also have already listed the server and the script path in Localsettings.php outside of the wiki family code. I just got the following error: PHP Parse error:  syntax error, unexpected '<' in /home/gjlxrtap/public_html/mw19/LocalSettings.php on line 255

2001:16B8:101A:200:D1C3:3F7F:9E12:ABDC (talkcontribs)

In LocalSettings.php, on line 255, you have a "<" character, which does not belong there.

Honestly I don't know, what you are changing in the file.

Maybe you should first read an introduction to PHP before you go ahead - PHP can be rather picky about its syntax. You should read something about PHP syntax first!

Samwilson (talkcontribs)

@Newman2: Are you including the <?php part? That should be left out (it only goes at the top of LocalSettings, and you've probably already got it in that file). I'm sorry, I shouldn't have included it in the above code.

Newman2 (talkcontribs)

I removed the <?php part from the wiki family code and now my Penguin Ice Wikis site is up and running. However, en.penguingamestudio.com has not loaded when I go to the site. What do I need to do in order to get the en.penguingamestudio.com site up and running?

Samwilson (talkcontribs)

Do you get any error?

You firstly need to make sure that en.penguingamestudio.com is being mapped to the same MediaWiki directory.

Newman2 (talkcontribs)

No, I do not get any error on my main wiki. And by the way, how do I make sure that en.penguingamestudio.com is being mapped to the same MediaWiki directory?

This post was hidden by Newman2 (history)
Newman2 (talkcontribs)

^Read the post above.

Samwilson (talkcontribs)

> how do I make sure that en.penguingamestudio.com is being mapped to the same MediaWiki directory?

One easy way is to create a symlink from wherever it's being served from now to the other directory.

Or you can change your web server configuration to change the document root (e.g. for Apache, set something like DocumentRoot "/var/www/mediawiki").

Basically, it's nothing to do with MediaWiki itself, so you should be able to get the various domains pointing to the same directory on your server, and then after that work on configuring MediaWiki.

Newman2 (talkcontribs)

I have a question. Do I need to add a CommonSettings.php for global settings and separate LocalSettings files for each wiki? If so, do I need a separate database for each wiki? This could be why my Penguingame Studio wiki is not running.

EDIT: I also installed global userrights, and I loaded it into my CommonSettings.php file. When I loaded the extension and added steward rights to my Commonsettings.php file, it did not show up on penguinicewikis.com. The settings of penguinicewikis.com are located in my LocalSettings.php file.

This post was hidden by Newman2 (history)
Newman2 (talkcontribs)

^Read the post above.

Samwilson (talkcontribs)

(You don't need to keep saying "read the post above". It might come across as rude.)

> Do I need to add a CommonSettings.php for global settings and separate LocalSettings files for each wiki?

No, you can configure it all in LocalSettings if you wish, with conditional statements, or you can do something like this and have separate files:

require_once "$IP/LocalSettings_$wikiId.php";

Personally, I prefer having it all in one file, because there's only half a dozen lines that are unique to each wiki and they're easy enough to see when all together.

Did you get the other domain working?

Newman2 (talkcontribs)

I'm sorry about posting "Read the post above", I did it because I was afraid that people wouldn't read my post. And I've tried to get the other domain working, but the sites for my Penguingame Studio wikis can not be reached. And when I try to enable global extensions, it gives me an internal error.

Do I need to install any databases to get multiple wikis running? If none of the additional wikis could have their site reached, then what can I do to make my additional wikis up and running? It is hard for me to find a way to get this all set up on my own.

Samwilson (talkcontribs)

Okay, to get things started I recommend you don't worry about MediaWiki at all: just get both domains being served from the same place. Doesn't matter if that directory just contains a simple index.html file. Don't try to get the MediaWiki side of things sorted out until you've done the webserver part.

What web server are you using? Apache? What filesystem directories are set up as the document roots for the domains? e.g. they might be /var/www/penguinicewikis.com and /var/www/en.penguingamestudio.com . So you need to get both of these pointing to a single place, either by changing the web server config or setting up symlinks (etc.).

Does that make sense?

Newman2 (talkcontribs)

My web host managers said I can't directly manage the Apache configuration files, but I can define specific rules just for your domain using an .htaccess file. Also, I can't change the web server config.

Newman2 (talkcontribs)

I started a subdomain of penguinicewikis.com called Penguiconverter. I pointed it at the original file, but my site shows up as a duplicate of the original site. What can I do to make the data on the wiki separate from the other site?

Samwilson (talkcontribs)

Sounds good! So you've got two domains pointing to the same place. :) That's good. If you've got it working on the subdomain as the same site, then you must have changed LocalSettings.php to have a default DB name etc.; can you post your current config?

So next you need to sort out the configuration in LocalSettings.php — make sure you've got a config like I posted above, with the relevant subdomains in there.

Do you have a second database set up for the other wiki? If not, you can clone your existing working one with tables/structure only and no data. Are you using phpMyAdmin? There's a tool in there for doing that.

Newman2 (talkcontribs)

I cloned my database by importing, and the wiki hasn't become separate yet. I also tried to use require_once in Localsettings.php, and it gave me the following error: PHP Fatal error:  require_once(): Failed opening required '/home/gjlxrtap/public_html/mw19/LocalSettings_penguiconverter.php' (include_path='/home/gjlxrtap/public_html/mw19/vendor/pear/pear_exception:/home/gjlxrtap/public_html/mw19/vendor/pear/console_getopt:/home/gjlxrtap/public_html/mw19/vendor/pear/mail_mime-decode:/home/gjlxrtap/public_html/mw19/vendor/pear/net_smtp:/home/gjlxrtap/public_html/mw19/vendor/pear/pear-core-minimal/src:/home/gjlxrtap/public_html/mw19/vendor/pear/mail:/home/gjlxrtap/public_html/mw19/vendor/pear/mail_mime:/home/gjlxrtap/public_html/mw19/vendor/pear/net_socket:.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/gjlxrtap/public_html/mw19/LocalSettings.php on line 234

What can I do to remove that fatal error? Also, how can I make my new wiki have separate pages and files but still run successfully?

Ciencia Al Poder (talkcontribs)

> What can I do to remove that fatal error?

Seriously, the error is very explicative. Why are you adding PHP code to files without having any clue of what you're doing, and then asking why it doesn't work, if you don't even explain the rationale of adding random require_once?

Newman2 (talkcontribs)

I removed the require_once code and I currently will not remove it because I did not know how to fix it without help. I also want to know if the correct way to clone the old database is to export it and then import it into the new database, because my second wiki still shows the same pages and files as the original wiki.

Samwilson (talkcontribs)

You should export only the database structure, and not any data in it. Then, when setting up the new wiki you'll run:

php maintenance/update.php --wiki penguinconverter

And yeah, if you want to have separate LocalSettings files for each wiki, you'll have to actually create those files. But I'd recommend you keep things simple.

Newman2 (talkcontribs)

Wait... do I run that script with a web server like Apache? Or where do I run it?

Samwilson (talkcontribs)
Newman2 (talkcontribs)

I updated my Penguiconverter wiki, however when I uploaded a test file it showed up on both Penguiconverter and Penguin Ice Wikis. Do I need to create separate directories for images and pages? If not, what do I need to do to fix this?

Samwilson (talkcontribs)

Yeah, you could base this too on $wikiId, e.g.:

$wgUploadDirectory = "$IP/images_$wikiId";
$wgUploadPath = "/images_$wikiId";
$tmpDir = "/tmp/mediawiki_{$wikiId}_" . php_sapi_name();
Newman2 (talkcontribs)

Added the upload location. I also did a test edit on my Penguiconverter wiki, and the edit showed up on my Penguin Ice Wikis wiki. What can I do to make pages and edits separate on each wiki when they are pointed at a single place?

EDIT: I also added the database for Penguiconverter, and I got the following message: (Cannot access the database: Access denied for user 'gjlxrtap_penguinicewiki'@'localhost' (using password: YES) (localhost))

This post was hidden by Newman2 (history)
Newman2 (talkcontribs)

Will anyone be able to read the above post?

Newman2 (talkcontribs)

Sorry if I keep bringing up my post. I am really ticked off that no one has appeared to notice my post.

Reply to "Parse error: Unexpected "$wikiId" in Localsettings.php"