Index.php isn't working after migration

Index.php isn't working after migration

by Quintin Seegers -
Number of replies: 13
Picture of Particularly helpful Moodlers
We're moving from having our Moodle hosted and managed by a Moodle Partner to hosting and managing it ourselves. (I won't go into the reasons for this decision here.) We received the backup of our mySQL database and MoodleData/filedir folder. (Though it is disappointing that it's not a full site backup, so it won't actually be a true replica of our current Moodle site).

I'm not all that familiar with the backend workings so am muddling my way through with moodle docs and youtube videos. We don't have internal IT with moodle or Linux knowledge I can refer to for assistance.

I installed php7.4 and Moodle 3.11 on an AWS Lightsail Ubuntu 22.04 instance without any issues and got the 'standard' blank moodle running. After coping the filedir folder to MoodleData folder and restoring the mySQL database to a database of the same name as the backed-up database, I updated the config.php file to change the line $CFG ->dbname to use the corresponding database name.

The login page shows (though the behaviour is the default Boost theme behaviour). When I log in, instead of seeing the normal Dashboard/Home page, I get the following error:

(IP address redacted)

Any suggestions/assistance on getting this resolved is greatly appreciated.

Average of ratings: -
In reply to Quintin Seegers

Re: Index.php isn't working after migration

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

HTTP error 500 is Internal Server Error so hopefully your web server has logged a message. So you'll need to find out where these logs are. The web server log location will depend on the web server software in use. If this is Apache this might be in /var/log/apache2 but I'm not an Ubuntu expert so it may be somewhere else.

PHP may additionally be writing error logs to a different location. If you don't know where add a PHP info file, view the page and find the value for "error_log". On my CentOS server these are in /var/log/php-fpm/www-error.log.

(IP address redacted)

So you're accessing the site using an IP address in the URL? Presumably that wasn't the case before? Have you changed $CFG->wwwroot to match? If you're changing the URL you may need to use the search and replace tool to update links in the database although I wouldn't expect this to cause the error in your screenshot.

The login page shows (though the behaviour is the default Boost theme behaviour).

I don't understand what you mean. Are you saying the username and password form appears? And it's only when you click Log in that the HTTP ERROR 500 page appears?

In reply to Leon Stringer

Re: Index.php isn't working after migration

by Quintin Seegers -
Picture of Particularly helpful Moodlers
The backup we received wasn't a full site backup, so it didn't include a config.php file. The one that was created automatically when I installed Moodle is pointing to the correct URL and I didn't change it. The login form does appear and I can enter my username and password and click on the login button, but that's when the error page comes up.
In reply to Leon Stringer

Re: Index.php isn't working after migration

by Quintin Seegers -
Picture of Particularly helpful Moodlers
If I edit the config.php and change the $CFG ->dbname to the default database created when I initially installed moodle (i.e. 'moodle') the site works fine - I can log in without any issues. To me that says it something with the new database I created and restored the backup to that has the issue, but I won't know what that would be.
In reply to Quintin Seegers

Re: Index.php isn't working after migration

by Ken Task -
Picture of Particularly helpful Moodlers
What version was the moodle when hosted with the Moodle Partner?

Does affect what version of PHP you can run.


'SoS', Ken

In reply to Ken Task

Re: Index.php isn't working after migration

by Quintin Seegers -
Picture of Particularly helpful Moodlers
I made sure the PHP and Moodle version matches that of the hosted site (php7.4 and Moodle 3.11 respectively)
In reply to Quintin Seegers

Re: Index.php isn't working after migration

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
> We received the backup of our mySQL database and MoodleData/filedir folder. (Though it is disappointing that it's not a full site backup, so it won't actually be a true replica of our current Moodle site).

You mean the Moodle code was missing? Ref. Site backup. It was a managed Moodle, not Moodle as a service? Then the code must be unchanged from the FOSS code.

What about additional plug-ins?

> I'm not all that familiar with the backend workings so am muddling my way through with moodle docs and youtube videos. We don't have internal IT with moodle or Linux knowledge I can refer to for assistance.

And that for a running production (commercial) site?

> I installed php7.4 and Moodle 3.11 on an AWS Lightsail Ubuntu 22.04 instance without any issues and got the 'standard' blank moodle running.

No idea what Lightsail is, but if it is a standard Moodle 22.04 LTS Server, that is a main-stream distribution, which many in the community use.

> After coping the filedir folder to MoodleData folder and restoring the mySQL database to a database of the same name as the backed-up database, I updated the config.php file to change the line $CFG ->dbname to use the corresponding database name.

Not clear. You just have to follow Moodle migration.

> The login page shows (though the behaviour is the default Boost theme behaviour). When I log in, instead of seeing the normal Dashboard/Home page, I get the following error:

You mean, the site presents itself as expected but throws this error only when you try to log in? Create a test.html file in the Moodle code directory and visit yoursite/test.html in your browser. If it does not render the HTML, your problem is unrelated to Moodle.
In reply to Visvanath Ratnaweera

Re: Index.php isn't working after migration

by Quintin Seegers -
Picture of Particularly helpful Moodlers
> It was a managed Moodle, not Moodle as a service? Then the code must be unchanged from the FOSS code.
It's a managed Moodle site. I can't comment on whether the Moodle Partner has customised the Moodle Core code.

>And that for a running production (commercial) site?
Surely it shouldn't be this complicated.

>Not clear. You just have to follow Moodle migration.
I did.

>You mean, the site presents itself as expected but throws this error only when you try to log in? Create a test.html file in the Moodle code directory and visit yoursite/test.html in your browser. If it does not render the HTML, your problem is unrelated to Moodle.
A test.html page presents correct.
In reply to Quintin Seegers

Re: Index.php isn't working after migration

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
> It's a managed Moodle site. I can't comment on whether the Moodle Partner has customised the Moodle Core code.

Can you confirm that the Site backup given to you by the Moodle Partner did not contain the Moodle code?

If the code is indeed missing, did you ask the Moodle Partner, Why? They haven't managed your Moodle for free, I assume.

FYI: The config.php file is not part of the Moodle code.

> Surely it shouldn't be this complicated.

For you? Possibly. But not for everybody. Have a look at the hundreds of thousand help requests in these forums.

>> You just have to follow Moodle migration.

> I did.

No you didn't. It says Moodle_migration#Copy_the_Moodle_code_from_the_old_server_to_the_new_server. Your description doesn't have that. It had only:

>> After coping the filedir folder to MoodleData folder and restoring the mySQL database to a database of the same name as the backed-up database, I updated the config.php file to change the line $CFG ->dbname to use the corresponding database name.

Don't you think you are answering only the questions that suit you? What about,

>> What about additional plug-ins?

Since you don't answer my questions, I won't waste my time formulating questions any more.

Good luck!

In reply to Quintin Seegers

Re: Index.php isn't working after migration

by Ken Task -
Picture of Particularly helpful Moodlers
It's not an un-common practice when you leave a Moodle Partner to get only a DB dump (sql file) and an archive of the MP hosted moodledata/filedir/ that's because each MP might have offered customized plugins (not supposed to modify core, but that might not have been true.   I helped a gentleman a few years ago do this feat only with a 3.9 at the time.

It would help if you had some technical info beyond what version of moodle related to customizations the MP might have offered and that your MP hosted site used.
Those could include authentication methods ... manual - which is probably the only setup you have with your 3.11.18 setup you have.

I don't think you will be able to solve this using GUI only ... command line will be necessary.

There is one CLI tool that at this point would be extremely helpful:
in admin/cli/ of your current code there should be a uninstall_plugins.php - does what it says - and it has options to the script that will id what addons you do have in the DB, but don't have in code.    Can't get the code ... MP will not give it to you ... so the only choice you have is to id them and remove the tables associated with them - which uninstall_plugins.php script can do.

Here's the help screen from that script:

Command line tool to uninstall plugins.

Options:
    -h --help                   Print this help.
    --show-all                  Displays a list of all installed plugins.
    --show-contrib              Displays a list of all third-party installed plugins.
    --show-missing              Displays a list of plugins missing from disk.
    --purge-missing             Uninstall all missing from disk plugins.
    --plugins=<plugin name>     A comma separated list of plugins to be uninstalled. E.g. mod_assign,mod_forum
    --run                       Execute uninstall. If this option is not set, then the script will be run in a dry mode.
    --showsql                   Show sql queries before they are executed.
    --showdebugging             Show developer level debugging information.

Examples:

    # php uninstall_plugins.php  --show-all
        Prints tab-separated list of all installed plugins.

    # php uninstall_plugins.php  --show-contrib
        Prints tab-separated list of all third-party installed plugins.

    # php uninstall_plugins.php  --show-missing
        Prints tab-separated list of all missing from disk plugins.

    # php uninstall_plugins.php  --purge-missing
        A dry run of uninstalling all missing plugins.

    # php uninstall_plugins.php  --purge-missing --run
        Run uninstall of all missing plugins.

    # php uninstall_plugins.php  --plugins=mod_assign,mod_forum
        A dry run of uninstalling mod_assign and mod_forum plugins.

    # php uninstall_plugins.php  --plugins=mod_assign,mod_forum --run
        Run uninstall for mod_assign and mod_forum plugins.

'SoS', Ken



Average of ratings: Useful (1)
In reply to Quintin Seegers

Re: Index.php isn't working after migration

by Ken Task -
Picture of Particularly helpful Moodlers
Since you have command line ...
some investigation as to what you do have ... using the DB you imported.

Let's see if moodledata/filedir has any backups of courses:
From code/admin/cli/
Create a bash shell script called 'getbackups'.
Contents of 'getbackups':

mysql -u $mddbuser -p$mddbpass -e "use $mddbname;select contenthash,filename,component from mdl_files where (filename like '%.mbz' and component= 'backup');" > backups.txt;cat backups.txt
wc -l backups.txt

Is a one-liner so above is all one line.
You replace $ variables in above with your info.

Output will look like this if you do have backups.

contenthash     filename        component
35584c737a95f204c9180c9d34702919ccc1ed31        backup-moodle2-course-1-m311-20220420-1250.mbz  backup
b106680ac570d3f3b276f0c8f5668e57abebc5f3        backup-moodle2-course-1-m311-20240105-1550.mbz  backup
8421db2cc5b3bf49ff7d65e539345723adc8b07b        backup-moodle2-course-2-sa-20221204-1550.mbz    backup
9d91a7ee9655dfff59dbf4b9fb83017328590583        backup-moodle2-course-2-sa-20221205-1550.mbz    backup
4c91df255f6d5b2624f5b5087b407e9ac68c1bb2        backup-moodle2-course-4-t-20220420-1250.mbz     backup
3011a48195a12f840c19f8b78b77b64a2f157fdb        backup-moodle2-course-5-test-20221006-1550.mbz  backup
e75e53f6c6178f1c4214f049fe1e02d673a06f32        backup-moodle2-course-5-test-20231107-1550.mbz  backup
a61de1d4fb5c6980372fbe90e4a1e2fea700b35a        backup-moodle2-course-6-h5pt-20220420-1250.mbz  backup
96c859bd5fa256bac301d9914ca656cadd0cf442        backup-moodle2-course-7-test2-20221204-1550.mbz backup
11f48144ad11371ced6a48217c4b81d25cf4eca9        backup-moodle2-course-7-test2-20221205-1550.mbz backup
bce9d8b05bd760563132b85ab4d9bff689bf8330        backup-moodle2-course-8-ktnoclas-20231106-1550.mbz      backup
afe8603f99cb4b2a52cebf76e097005f80c0ab7c        backup-moodle2-course-8-ktnoclas-20231107-1550.mbz      backup
fc3bb1b8227f330a658972f385836ea2c9c85a01        backup-moodle2-course-9-mdlsampler-20220805-1550.mbz    backup
a117f0f57c1262f46eab6198151d27bc88df3042        backup-moodle2-course-9-mdlsampler-20220806-1550.mbz    backup
9c073730f0310ec9e2e4e2f86c8954be6e1bab59        backup-moodle2-course-10-ktnoclas_frm_42-20230813-1550.mbz      backup
d3f74cec74f60da773b1362b66c228ddf24f0849        backup-moodle2-course-10-ktnoclas_frm_42-20240105-1550.mbz      backup
af159110dacd3308135616838d786b5de4e27871        backup-moodle2-course-5-test-20211007-1327.mbz  backup
45e49153226272e1f0ecb07ee2825016f0f872a3        backup-moodle2-course-5-test-20211224-2029.mbz  backup
e57d06f8512dcbd4c7d6f9b556aea86471cae9e0        backup-moodle2-course-5-test-20220407-1047.mbz  backup
7999117b6829160b5e2bebecbdec94a38e54e7a1        backup-moodle2-course-5-test-20220407-1100.mbz  backup
00f6d84b515885fc0089f7029ae749def4c391bf        backup-moodle2-course-6-h5pt-20230517-1537.mbz  backup
41ceed1820ab54e7f978a333a4fc1f33c595cd8c        backup-moodle2-course-8-ktnoclas-20220318-1658.mbz      backup
c1f1ea4647462c1a486c1e0c3879529d9bca4b20        backup-moodle2-course-8-ktnoclas-20221202-1556.mbz      backup
3658502ea187c8501e71c6bd95fd5fc41b44ddd0        backup-moodle2-course-9-mdlsampler-20230629-1050.mbz    backup
25 backups.txt

Taking the first line - bold above:
35584c737a95f204c9180c9d34702919ccc1ed31
is both the backup filename as it exist in moodledata/filedir/ and it's location:

moodledata/filedir/35/58/ then a file called bold above

The humanly recognizable filename you see in bold example
backup-moodle2-course-1-m311-20220420-1250.mbz
tells you that the backup includes users and their work.
If the backup filename had 'nu' in it, that means that course backup doesn't include users (nu = no users).

Here's another that might come in handy ... using the imported DB again and again from the code/admin/cli/ directory:

php cfg.php > allsettings.txt

That script list all settings contained in the DB and redirects to a text file 'allsettings.txt'
which will be rather long.   You could, download via browser, to your local machine and browse it locally.

Or use it on the server seeking info ... like the exact version of moodle the db contains:
fgrep 'version' allsettings.txt

Another ... getusers
contains
mysql -u $mddbuser -p$mddbpass -e "use $mddbname;select id,auth,username,email from mdl_user;" > users.txt;cat users.txt
wc -l users.txt

ID #2 was/is the original admin user that installed software ... usually .. cept in your case coming from a MP, dunno that to be true.
Since you cannot login, the auth column might be of interest.
There is a password column but don't think that will do you much good as it is not clear text password.

BTW, you could make any of those userid's admin levels to the moodle.
And for manual auth accounts, you can change the password via
reset_password.php in code/admin/cli/

The above is the sort of thing you will have to do to get things sorted.

Uhhh, one is not looking at something that is gonna be 100% so expect other issues to raise their ugly head.

'SoS', Ken


In reply to Quintin Seegers

Re: Index.php isn't working after migration

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
My first thought is did the url change? ...and did you run the replace tool on your database?
In reply to Emma Richardson

Re: Index.php isn't working after migration

by Ken Task -
Picture of Particularly helpful Moodlers
@Emma ... have had brief PM exchange with OP.   OP is 'confident' that the restoration of the site formerly hosted with a Moodle Partner (thus only DB dump and moodledata/filedir/ given to restore) can be accomplished without assistance.

One thing for sure - OP will learn a lot about moodle to be sucessfull ... and OP did say he  would share solution back here when done. smile

'SoS', Ken

In reply to Ken Task

Re: Index.php isn't working after migration

by Quintin Seegers -
Picture of Particularly helpful Moodlers
Thanks, Ken. That information you provided was very useful. Unfortunately, after all that, we still have the same issue. The Moodle Partner is (understandably) not being very helpful - though the decision to drop them is largely due to their own actions.

As we are running out of time and not finding a solution to this issue, we've opted to do a manual migration - backup the courses manually from the partner-hosted site and manually restoring them onto a 'clean' install of Moodle.