{"id":328,"date":"2019-08-14T17:00:44","date_gmt":"2019-08-14T11:30:44","guid":{"rendered":"http:\/\/www.bhuvankrishna.in\/blog\/?p=328"},"modified":"2019-08-28T11:24:45","modified_gmt":"2019-08-28T05:54:45","slug":"moodle-migration","status":"publish","type":"post","link":"https:\/\/www.bhuvankrishna.in\/blog\/2019\/08\/14\/moodle-migration\/","title":{"rendered":"Moodle migration"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Moodle migration from one server to another while upgrading to a new moodle version<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Enable maintenance mode before doing anything. This will make sure that there is no data lose and also inform users that the site will not be available. Plan the migration steps before starting the migration which will speed up the process and also reduce the down time. For future reference these are the steps that have to be followed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Change DNS Nameservers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you are hosting in a vm and changed the IP update the ip pointing to the server. Later on when configuring certbot it is necessary to have the new IP for the domain.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing the old System<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We have to backup these folders and database. Change the paths according to where you have installed moodle. In this case moodle in installed as a default portal for the system in \/var\/www\/html, moodledata can anywhere this is just an example.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\/var\/www\/html<\/li><li>\/var\/www\/moodledata<\/li><li>database.sql\nCreate a folder to copy all of them to one location. In this example we will create a folder called backup and copy all the files and folders to it. &#8216;~\/&#8217; is for home directory of the user in this case it is root.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  mkdir ~\/backup\/\n  rsync -avz --progress --numeric-ids \/var\/www\/html ~\/backup\n  rsync -avz --progress --numeric-ids \/var\/www\/moodledata ~\/backup\n  mysqldump -u &lt;dbuser> -p &lt;dbname> > database.sql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">for mysqldump it will ask for a password give the password of the database used in config.php file<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing the new System<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following setup is for Debian 10 adjust package names and other options accordingly to a different OS. Install all the <a href=\"https:\/\/docs.moodle.org\/37\/en\/PHP#PHP_Extensions_and_libraries\">requirments<\/a> as suggested by moodle. For convenience use this command which will install all the packages<br>\n  <code>apt install apache2 mariadb-server php php-mysql php-mbstring php-curl php-tokenizer php-xmlrpc php-soap php-common php-zip php-gd php-xml php-intl php-json<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now transfer the files from old system to the new one<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  mkdir ~\/imported\/\n  rsync -avz --progress --numeric-ids user:OLDSERVER-IP:backup imported<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create mariadb database and user then import data to the new db. login to mariadb prompt by given the command &#8216;mysql&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  CREATE DATABASE databasename;\n  GRANT ALL PRIVILEGES ON databasename.* TO \"username\"@\"hostname\" IDENTIFIED BY \"password\";\n  FLUSH PRIVILEGES;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Import database<br>   <code>mysql -u &lt;dbuser&gt; -p &lt;dbname &lt; database.sql<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Move moodledata to new location<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  cp -r ~\/imported\/moodledata \/var\/www\/\n  chown -R www-data.www-data \/var\/www\/html<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Download or clone the latest version from git repo, follow this <a href=\"https:\/\/docs.moodle.org\/37\/en\/Git_for_Administrators#Obtaining_the_code_from_Git\">guide<\/a> into \/var\/www\/html. At this point you may need to copy some plugins from old installation which you can do once you have started the upgrade. The upgrade page will show what are the missing plugins and you can copy them from back to the new instance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Update config.php to reflect new paths and in case of new database add those changes.<br>   example config.php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For updating mysql to give 4 byte support follow this <a href=\"https:\/\/docs.moodle.org\/33\/en\/MySQL_full_unicode_support\">link<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;?php  \/\/ Moodle configuration file\n\n  unset($CFG);\n  global $CFG;\n  $CFG = new stdClass();\n\n  $CFG->dbtype    = 'mariadb';\n  \/\/$CFG->dbtype    = 'mysqli';\n  $CFG->dblibrary = 'native';\n  $CFG->dbhost    = 'localhost';\n  $CFG->dbname    = '&lt;dbname>';\n  $CFG->dbuser    = '&lt;dbuser>';\n  $CFG->dbpass    = '&lt;dbpass>';\n  $CFG->prefix    = 'mdl_';\n  $CFG->dboptions = array (\n    'dbpersist' => 0,\n    'dbport' => '',\n    'dbsocket' => '',\n    'dbcollation' => 'utf8mb4_unicode_ci', #&lt;-- this is optional for storing emoji's in db. to get it check mysql configuration and update it.\n  );\n\n  $CFG->wwwroot   = '&lt;url>'; #&lt;-- This url is important that what ever we give here either url or ip is used to access the portal\n  $CFG->dataroot  = '\/var\/www\/moodledata'; #&lt;-- Change this if data is in a different location\n  $CFG->admin     = 'admin';\n\n  $CFG->directorypermissions = 0777;\n\n  require_once(dirname(__FILE__) . '\/lib\/setup.php');\n\n  \/\/ There is no php closing tag in this file,\n  \/\/ it is intentional because it prevents trailing whitespace problems!\n  ?><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Upgrade the server from web interface<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once all the files are in place open site url. The site will show upgrade page. Once you continue it will show all the plugins that will be upgraded, installed, deleted. The once which are shown &#8216;missing from disk&#8217; copy them from the back to the new instance and reload. Once the upgrade is done disable maintenance mode.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">For reference these where missing files and plugins from the instance that we where upgrading. ~\/imported being the root of moodle.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">~\/imported\/learning\/mod\/attendance\/<br>\n~\/imported\/learning\/filter\/wiris\/ <br>\n~\/imported\/learning\/lib\/editor\/atto\/plugins\/wiris\/ atto\/plugins\/<br>\n~\/imported\/learning\/lib\/editor\/tinymce\/plugins\/tiny_mce_wiris\/<br>\n~\/imported\/learning\/auth\/a2fa\/<br>\n~\/imported\/learning\/user\/profile\/field\/afaqr\/<br>\n~\/imported\/learning\/report\/benchmark\/<br>\nchown -R www-data.www-data \/var\/www\/html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Moodle migration from one server to another while upgrading to a new moodle version Enable maintenance mode before doing anything. This will make sure that there is no data lose and also inform users that the site will not be available. Plan the migration steps before starting the migration which will speed up the process\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.bhuvankrishna.in\/blog\/2019\/08\/14\/moodle-migration\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-328","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/comments?post=328"}],"version-history":[{"count":4,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/328\/revisions"}],"predecessor-version":[{"id":334,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/328\/revisions\/334"}],"wp:attachment":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/media?parent=328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/categories?post=328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/tags?post=328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}