/
Clone LMS (moodle)

Clone LMS (moodle)

A guide on how to clone Moodle into another instance. We take into account that all backups for RDS, EFS and AMI’s for EC2 instances are already set up.

 

Restore RDS

Navigate into AWS Console.

We either take a new snapshot or we go into already created snapshots and restore the latest.

Steps in order to take a new snapshot.

  1. Navigate into RDS → DB instances.

  2. Select the database we want to take a snapshot from

  3. Actions → Take Snapshot

  4. We give a name of the snapshot and hit create.

Snapshot it will take approximately 15 minutes to finish.

Restore from a snapshot (Manual or Automated).

  1. Navigate into RDS → Snapshots

  2. Select the snapshot we want to restore

  3. Actions → Restore Snapshot

  4. We navigate into a new window where we must select the appropriate Security Groups and availability zones.

  5. Restore DB instance.

Restore EFS

Take an EFS backup right away

In order to make an EFS backup right away we need to navigate into AWS Backup service.

  1. We select the Create on-demand backup.

  2. Resource type we select EFS

  3. Select the File system ID

  4. Backup window set to “Create backup now“

  5. Transition to cold storage Never

  6. Retention period Always

  7. Backup vault set to Default

  8. IAM role set to Default role

  9. Set tags

  10. Create on-demand backup.

Creating the backup will take approximately 2 hours for 1.4TB

Restore EFS from Backup vaults

In order to restore EFS we need to go into AWS Backup services and then into Backup vaults

  1. Select the EFS we want to restore

  2. Actions → Restore

  3. We can select Full restore if we want the whole EFS or item-level restore if we want a specific directory from the EFS.

    1. eg. for item path we can write /wwwroot/courses…

  4. Restore to a new file system.

  5. Restore role → Default role

  6. Restore backup

This action will take approximately 15 minutes.

Mount EFS into EC2 instance

We assume that our instances already have the necessary PHP, apache, packages installed.

In order to mount EFS into ec2 instance we need to make sure that both services exist into the same VPC and availability zone. This action wont work if the above are not correct.

The steps to mount the EFS are:

  1. create a directory also called as mount point on which we will mount the efs

    1. sudo mkdir efstemp
  2. create a mount target in order to allow ec2 instance to mount the efs. In EFS we select the file system we want to mount and then we go into Network tab. We then select the Manage button in order to create a mount target. After we finish this step we should be able to see a DNS name set to our EFS we want to use.

  3. In EFS dashboard we select the EFS that we have restored and we navigate into another page

  4. we select Attach we chose the option Mount via DNS

  5. Using the NFS client we select the appropriate command on which we paste into our EC2 console.

  6. example of command

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-.....:/ efs

After using the command the EFS should be attached into our instance and ready to be used right away.

In case the EFS does not mount probably we need to change the subnet ID of the instance.

Some additional commands:

1. Report file system disk usage

df -h

2. persist mount EFS (when restarting server will reattach EFS automatically)

3. Check EFS mounted successfully

Make appropriate changes in Moodle config

We navigate to /efstemp/..../moodle

We backup config.php into configbackup.php just for safety measures.

We edit config.php and we make the relevant changes:

  1. we need to make sure the dbtype is the correct one in our case we have 'mariadb'

  2. dbhost,dbname,dbuser,dbpass need to be of the newly restored DB instance.

  3. wwwroot needs to change into the new URL eg https://dev.courses

  4. dataroot need to point to newly restored EFS with a path to moodledata

  5. session_redis_host need to have the name of the redis for our application

Make appropriate changes in HTTPD

We need to log into our ec2 instance. and then navigate into our httpd configuration for Moodle

We have to make 2 changes. the Document Root and the Directory path. It needs to point into our new EFS that we mount.

Go through the file and make sure we didn’t forget to use the path anywhere else.

First Sign in

Inside config.php we need to include alternate url so that it won’t navigate into the previous website.

After signing in we comment out the $CFG->alternateurl and we go into the Manage authentication page in moodle. We search for Alternate login URL and we set there the URL we want the website to have. This is so the alternate url to be saved into the database.

Make sure Redis cache is correct in Moodle application

Right after we finish cloning we need to log in into the website.

We then must go directly into Site administration → plugins → caching → configuration

Alternatively we can go directly with /cache/admin.php

in Configured store instances table we edit redis_all and on the server input we put the one we have for our cloned website. eg dev-courses[…]amazonaws.com

In this area we need to put the Primary endpoint which we can found in our Amazon ElasticCache service

This is an important step as if it’s not configured then changes that are suppose to happen in cloned website will be done into the previous website because of redis caching.

Forbid Access to all users except specific ones

We want to avoid random users to log into the cloned website that’s why we edit moodle/login/index.php

In allowedUsers array we put the user id’s we want to have access. This code is entered right after the authenticate_user_login function

Configure AWS EC2 services

All these changes will be implemented only to the instance that we will be working on until the clone is finished. After we finish we need to take an AMI of the instance we worked with. In load Balancers we need to update the target group and also in Auto Scaling we need to set a new version for Launch template in order to use the latest AMI.

Extra Steps (SMTP, CRONS, Alternate login URL)

For safety reasons since this is a clone instance of another website ( If we want to use it for test ), it’s better if we disable SMTP and Crons so that we don’t send any notifications in the public accidentally.

Alternate login URL

We must change the alternate URL and input the one of the cloned theme (if it was changed).

Go to Site administration → Plugins → Authentication → Manage authentication

Find Alternate login URL and change it eg. dev.courses…

SMTP

Go to Site administration → Server → Email → Outgoing mail configuration

change SMTP hosts, username, password.

CRONS

Go to Site administration → Server → Tasks → Task Processing

Uncheck Enable cron

 

Related content

LMS For Developers
LMS For Developers
More like this
Install libsodium php package in AWS instances
Install libsodium php package in AWS instances
Read with this
Procedure for Updating Moodle
Procedure for Updating Moodle
More like this
AWS Backups
AWS Backups
More like this
Update EC2 instance from Amazon Linux 1 to Amazon Linux 2
Update EC2 instance from Amazon Linux 1 to Amazon Linux 2
More like this