breaks during database upgrade saying database table already exists

 If moodle breaks during database upgrade saying "database table already exists", you basically have no choice but to drop that table. My suggestion is to backup the database first: mysqldump moodle > moodle.sql Then use vi editor to locate that table and save that code separately. Obviously if the table is empty it doesn't matter. To find out if the table is empty, go back into mysql and type use moodle; select * from tablename; If it returns zero results, you are in luck, you can just drop the table: drop table tablename; But if it contains some stuff, then you have to save it and reload it later using mysqldump and then  mysql. Something like this: Assuming you've saved it as shown above and assuming you've kept only the SQL of that table; mysql moodle < mytablesql.sql Anyway, back on to the point. Once you have dropped the table, go back to the installer webpage, click in the URL bar where it shows the moodle webserver address, and just press Enter. Do n

turn on debug mode moodle

 in config.php after declaration of the CFG variable: @error_reporting (E_ALL | E_STRICT); @ini_set ('display_errors', '1'); $CFG->debug = (E_ALL | E_STRICT); $CFG->debugdisplay = 1;

database text format inconsistencies

When you create the moodle database, use something like this: mysql > create database moodle collate utf8mb4_unicode_ci; And when you set up the config.php file, make sure the line "dbcollation" mentions the same text format (utf8mb4_unicode_ci). To check what text collation you used, in mysql, type: SELECT @@character_set_database, @@collation_database; If you don't do this, you might have to edit        vi /var/www/html/moodle/lib/dml/mysqli_native_moodle_database.php and change line 196 to read         $sql = "SELECT @@storage_engine engine"; instead of         $sql = "SELECT @@default_storage_engine engine";

Fix: ERROR 1396 (HY000): Operation CREATE USER failed in MySQL?

 Fix: ERROR 1396 (HY000): Operation CREATE USER failed in MySQL? This is a mysql 8 bug. Suppose the user is  myuser . 1. The user already exists. Delete them with DROP. (not DELETE).      DROP USER myuser.     DO NOT use "delete from mysql.user where user=myuser". 2. You already deleted them with DELETE. Try it again with DROP, even if they do not exist.     If you are too late and you already made the mistake in (1) above you can either create a new user with a different name, e.g. myuser2, or, repeat the drop statement above in (1). 3. The password doesn't meet the default MySQL 8 requirements.     Sometimes it is because the password isn't good enough. It must be 8 chars minimum, with at least one caps, one lower, one number, and one punctuation. 4. Check your mysql supports old passwords ( mysql_native_password).    Use  CREATE USER 'myuser'@'localhost' IDENTIFIED WITH  mysql_native_password  BY 's0m3Passw0rd!@#';

installing moosh to make your life easier

If your site is crashed you need to edit moodle on the command line. Enter Moosh, the moodle shell. To install moosh, do this: sudo apt-add-repository ppa:zabuch/ppa sudo apt-get update sudo apt-get install moosh Then, if you want to use moosh, you can use more or less any command shown in the web interface using a syntax of moosh -n the-command the-parameters for example cd /var/www/moodle/ moosh -n plugin-uninstall someplugin  or moosh -n cache-clear note the "cd" part - it won't work unless you do that, as it uses the config file in that directory to login. The -n part means do not ask me about my user id. Normally moodle operates as apache (www-data). Using -n lets you run it as root. Otherwise you have to do something which is in my view, worse, namely enable bash shell for apache. That opens you up to hackers, in my view, as apache is facing the web and accepts uploads on many apps such as wordpress, so it's feasible for someone to hack your server entirely if y

Removing a troublesome plugin

Sometimes you can't login and remove a plugin because your instance crashes before the login completes. Just go to and then uninstall or disable the plugin. This URL should let you login as admin and remove plugins even if the rest of the site doesnt work (with replaced by your web address)

Duplicating moodle to create a new instance

The following are steps to DUPLICATE an existing Moodle on Ubuntu 20.x using PHP 7.4 to make a  NEW instance . First you have to create a new database for the new moodle instance. Let's assume your new moodle instance is going to be called "copytwo" If you are moving an instance from one server to another you will have to edit the SQL to replace the hostname. I suggest VIM or VI. Their details are mentioned in step 5. You will need to make a backup copy of the SQL, then edit the SQL, and replace the old hostname with the new hostname. 1. Set up a second MySQL database After this, set up mysql. Login as  root  on mysql. It will require you to use your root moodle password. If you can't remember what you set it to, instructions on resetting it are below in step 2 . mysql -u root -p 1.1 First, create the database: create database copytwo; When creating the moodle database, you need to set the  owner -  the user who will have  write  permissions. Obviously, "someoth