Friday, December 12, 2008

Installing Moodle on Amazon EC2

To reduce the disk cost, I decided to create a separate hard disk volume that you can attach to any Windows AMI instance. Any changes that you make to the Moodle are saved to this separate volume. So when you shutdown your instance, the changes are persistent. The only disadvantage is an extra step of attaching the hard disk after the machine is running. The advantage is that you spend less. 1GB of EBS = 0.10 cents per month, vs 3GB AMI = 3x0.15 cents =0.45 cents per month. It is also easier to create snapshots of the disk in this manner. Just right click the volume and create a snapshot. The snapshot is stored on S3.

I’ve created one snapshot of the initial disk – which can be used for new Moodle installs.

Starting up Moodle.

  1. Start any Windows image (I’ve tried it with ami-ec698d85 Server2003r2-i386-WinAuth-v1.02 and ami-e5698d8c Server2003r2-i386-Win-v1.02) Keep in mind that the Auth server is double the money compared to the vanilla windows.
    IMPORTANT: After you right click to launch an instance; In the dialog box, set the Availability zone =”us-east-1c” for the machine. Your volume is located in that zone. Data transfer is free if machine and volume are in the same zone.
  2. Right click the instance and “Show console output”. Wait till you see a message “Message: Windows is Ready to use”. This usually takes about 10 minutes from when you start.
  3. Once the instance is running, in ElasticFox go to tab “Volumes and Snapshots”. Right click and attach volume (vol-4b9d7922) as “xvdg”.
    The disk is automatically mapped to “E” if you do this after the ready message in the “Show console output”. (The volume initially contains an unzipped version of the Windows package installer from moodle.org.)
    1. If you do it before “Windows is ready to use”; you must manually change the drive letters.
      (Start>Administrative tools>Computer Management)
    2. Click Storage>Disk Management
  4. Right click the instance and “Get Administrator password”.
  5. [optional] If you are going to use an Elastic IP, do that now.
  6. [optional] Modify DNS on your domain nameserver to point to this new instance.
  7. Right click the instance and “Connect to Public DNS name”.
  8. Tip (optional) – when you use your browser, you are in Internet Explorer Enhanced Security mode. To turn off Internet Explorer Enhanced Security:
  9. http://www.windowsreference.com/windows-2003/how-to-disable-internet-explorer-enhanced-security-configuration-ie-esc-in-windows-server-20082003/
  10. Open “E” drive
  11. Edit the files E:\server\moodle\config.php (this is not needed when you haven’t configured Moodle for the first time. The file is created during Moodle configuration.)
  12. Click Start>Run and enter “net stop w3svc”. This stops the IIS server.
  13. Click “Start moodle.exe”
    It should start up. If there is a question about reconfiguration, press 1 and enter to proceed.
    The program will continue running in a DOS box with the message “Run STOP Moodle…..” or a blank DOS box.
  14. Click “My public IP” to get the IP address of your instance. (If you haven’t turned off Internet Enhanced Security, you will see a number of warning dialog boxes which you can ignore.)
  15. From your own PC, use a browser to open that instance. You should see the Moodle page.
    Once you are done, you can close the Remote Desktop window (do not logout, just close the window).

Stopping.

Right click the instance and “Connect to Public DNS name”.
Click “Stop Moodle.exe”.

Shutdown the server.

After the server is terminated, delete any Elastic IP addresses that you had attached.

Appendix: Editing Moodle’s config for EC2.

Once you have finished installation, the setup of moodle hard binds the name of the server in the setup files. You must change this if you want to access Moodle from outside the AMI.

Pre-startup - There are two files that should be modified.

1. D:\server\moodle\config.php
Change the line
$CFG->wwwroot = 'http://nooradel';
to
$CFG->wwwroot = 'http://<new public DNS name or elastic IP>';

2. [Optional] D:\server\apache\conf\httpd.conf
Change the line
Servername = localhost:80
to
Servername = <new public DNS name or elastic IP>:80

Helpful links

Setup instructions for Moodle on Windows

http://docs.moodle.org/en/Complete_install_packages_for_Windows

Command line for Amazon EC2.

http://docs.amazonwebservices.com/AWSEC2/2008-12-01/DeveloperGuide/

If you want to find out your own IP address inside a AMI (http://169.254.169.254/latest/meta-data/public_ipv4)

For more details see http://docs.amazonwebservices.com/AWSEC2/2008-05-05/DeveloperGuide/index.html?AESDG-chapter-instancedata.html

Setup the environment to run EC2 command line control tools. (See section on Configuring your workstation).

http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1827&categoryID=100

Key solutions

The key “amazon_ec2.pem” must be used instead of “amazon_ec2.ppk” to retrieve the Windows Administrator password.

Setup in Tools:

  • SSH Key template: ${home}\ec2-keys\${keyname}.ppk
  • EC2 Private key template: ${home}\ec2-keys\${keyname}.pem

You can re-download the public key by going to the web page. However the private key is not stored on the server. Keep it carefully.

  • Amazon_ec2.ppk (putty version of key pair amazon_ec2. )
  • Amazon_ec2.pem (EC2 version of key pair amazon_ec2.)
  • PK-0…..pem (Amazon account private key)
  • CERT-0…pem (Amazon account public key)

No comments: