Parse error: syntax error, unexpected end of file

Parse error: syntax error, unexpected end of file

by Jaap Nieuwenhuijzen -
Number of replies: 9

Moodle version 4.1.2+ (build 20230406)

Solved all Plugin and Theme issues while updating, now I get this error. 

Parse error: syntax error, unexpected end of file in /home/customer/www/consultingmethodology.com/public_html/moodle/config.php on line 34

I did all the checks on the config.php and it is 100% correct. 

Here is my config.php. Can anyone help me with this?


<?php  // Moodle configuration file

unset($CFG);
global $CFG ;
$CFG = new stdClass();

$CFG->dbtype    = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'xxxxxxxxxx';
$CFG->dbuser    = 'xxxxxxxxxxx';
$CFG->dbpass    = 'xxxxxxxxx';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbport' => '',
  'dbsocket' => '',
  'dbcollation' => 'utf8mb4_general_ci',
);

$CFG->dataroot  = '/home/customer/www/Mysite.com/moodledata';
$CFG->admin     = 'admin';
$CFG->siteadmins = 2 ;

$CFG->directorypermissions = 0777 ;

require_once(__DIR__ . '/lib/setup.php');

// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!

Average of ratings: -
In reply to Jaap Nieuwenhuijzen

Re: Parse error: syntax error, unexpected end of file

by Ken Task -
Picture of Particularly helpful Moodlers

This line:

$CFG->siteadmins = 2 ;

enclose the 2 in between 'ticks'

$CFG->siteadmins = '2';

no space after the last 'tick' ... the ; character is next after last 'tick'.

'SoS', Ken


In reply to Ken Task

Re: Parse error: syntax error, unexpected end of file

by Jaap Nieuwenhuijzen -

Thanks Ken, for your fast response.

I corrected this, and indeed this could be a flaw. But unfortunately this didn't do the trick.
Still the same  error: Parse error: syntax error, unexpected end of file in /home/customer/www/Mysite.com/public_html/moodle/config.php on line 34 

And there even isn't a line 34. It stops 1t 31.

Regards,  Jacob

In reply to Jaap Nieuwenhuijzen

Re: Parse error: syntax error, unexpected end of file

by Ken Task -
Picture of Particularly helpful Moodlers

These lines should be flush left - not indented as shown in your postings:

unset($CFG);
global $CFG ;
$CFG = new stdClass();

If not that, then it has to do with what comes after:

// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!

Make sure there is no blank line - carriage return after 'problems!'

Is your site directory really 'Mysite.com' ... in /home/customer/www/?
The cap M?

And you did edit config.php with a true text editor, correct?
'SoS', Ken

In reply to Ken Task

Re: Parse error: syntax error, unexpected end of file

by Jaap Nieuwenhuijzen -
Thanks, Ken.
Well, there's nothing after " // it is intentional because it prevents trailing whitespace problems! "
My site is not called "Mysite.com" I just changed this for this post, like the names of database, etc. Although I forgot this in my original question, ha ha, so you can see the site's name there.
I use the editor that's in my control panel from the site. Don't really know what that is. To be sure, I now try with "Sublime text".
KR, Jacob
In reply to Jaap Nieuwenhuijzen

Re: Parse error: syntax error, unexpected end of file

by Ken Task -
Picture of Particularly helpful Moodlers

Follow up ...

As you are learning, moodle is *very* particular about config.php.

The line you've added to get user id 2 to  be admin level is not typically there.  User ID 2 was the original installer user. ID 1 is guest, BTW.

It is possible that somehow a hidden machine character ... that you cannot see .. has inadvertently been added somewhere in the file .... most likely that line(s) you added.

To see if that might be the case, cut the lines you added and save the file.

Try with browser.

Fixed?

If that fixed it, then go back to a true text editor and add them again but be careful you don't inadvertently add machine characters back in the file.

How are you editing the file ... with what?

'SoS', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: Parse error: syntax error, unexpected end of file

by Jaap Nieuwenhuijzen -
Thanks Ken, that worked. Indeed, using a true text editor, did the thing.
Probably the editor in the site's control panel doesn't work.

Not ready yet, because now I am, faced with some plugin issues as a result of the update. But that's another story.

Many thanks!
Jacob
In reply to Jaap Nieuwenhuijzen

Re: Parse error: syntax error, unexpected end of file

by Ken Task -
Picture of Particularly helpful Moodlers

Good to hear!

Earlier you said "Solved all Plugin and Theme issues while updating"

And now you are faced with some plugin issues?

The last thing moodle does now upon an upgrade is to check all values for all settings - core and/or third party plugin.   Before you pulled the trigger on upgrading, guess you might not have checked plugins for compat with 4.1?

The other ... go to Server Environment - update component.

Is there anything at the bottom of that check related to DB - like full compliance?

That could directly relate to Leon's suggestion to concerning DB collation needing to be utf8mb4_unicode_ci.

There are some command line only scripts in code/admin/cli/ that will help fix that.

'SoS', Ken


In reply to Jaap Nieuwenhuijzen

Re: Parse error: syntax error, unexpected end of file

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

What's the PHP version? To find out run php --version if you have command line access, or use a phpinfo file if you don't.

It looks like there's some third party installer involved, both $CFG->siteadmins = 2 ; and dbcollation' => 'utf8mb4_general_ci' wouldn't be generated by Moodle as far as I know. The latter would be 'utf8mb4_unicode_ci' based on the docs.

The lines as you've posted parse correctly. As Ken suggests maybe there's a hidden character in the actual file. If you're still getting this error you could attach a copy of the file to your reply (with the sensitive information replaced by 'x's).

You can run php -l config.php to check for parse errors.

In reply to Leon Stringer

Re: Parse error: syntax error, unexpected end of file

by Jaap Nieuwenhuijzen -
Hi Leon,
My PHP version is 7.4.33.
My problem is already solved, though. Maybe I can use your help again (as you did before) with some plugin upgrading issues wink
That will be a separate thread of course, and I will try to solve them myself first.
Thanks anyway for your suggestion here,
Jacob