Migrate your Moodle installation

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "installdir/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

There are two important steps when migrating a Moodle Stack: migrate the database and migrate the moodledata/ folder. You may want to migrate the themes/ and modules/ folders if you have them installed also. To make this process easier, divide them into four sub-steps.

Export the database

You can do this manually or with phpMyAdmin. If you use phpMyAdmin, export it as an .sql file.

Copy the Moodle data folder

In this step, you just need to copy the Moodle data directory (moodledata) to the machine where you have installed the new Moodle. When doing this step, copy the exported database file too. If you have themes or modules installed and you want to keep them, you must also copy them.

NOTE: Depending on your installation type, the Moodle data directory will be located in the following paths:

  • Approach A (Bitnami installations using system packages): /bitnami/moodledata

  • Approach B (Self-contained Bitnami installations): installdir/apps/moodle/moodledata

Import the database

Delete the tables in the bitnami_moodle database. To do so, the easiest way would be to use phpMyAdmin, choose the bitnami_moodle database, select all the tables and drop them.

Another option would be to do it manually. Remember to replace the PASSWORD placeholder with the password set in the Moodle configuration file.

$ mysql -u root -p
mysql> drop database bitnami_moodle;
mysql> create database bitnami_moodle;
mysql> grant all privileges on bitnami_moodle.* to 'bitnami'@'localhost'
identified by 'PASSWORD';
mysql> flush privileges;
mysql> exit;

NOTE: Depending on your installation type, the Moodle configuration file will be located in the following paths:

  • Approach A (Bitnami installations using system packages): installdir/moodle/config.php

  • Approach B (Self-contained Bitnami installations): installdir/apps/moodle/htdocs/config.php

After that, import the database. You can do it manually or using phpMyAdmin.

Substitute moodledata/ (and other) directories

Finally, you just need to substitute the moodledata/ directory, as well as the themes/ and modules/ directories if needed.

Once these steps are complete, restart the Apache server and access Moodle through the browser. If you log in as an administrator, you will be asked to update your database. Click to do this and the migration of your Moodle stack will be completed.

Last modification July 8, 2020