Building a Virtual Ubuntu Server for OpenMRS

This tutorial is designed for users who are not so familiar with Linux, but need to have a platform to practice installing OpenMRS on such a system, and a general introduction to building a Ubuntu server.

Introduction

Ubuntu is a distribution of the Linux operating system which is relatively easy to use and well supported, and thus is a common choice for sites that require a dedicated OpenMRS server. Conveniently the Ubuntu Server Edition installation CD includes MySQL and Apache Tomcat.

For users who are unfamiliar with Linux it can be very useful to practice setting up both the operating system and OpenMRS on a virtual machine. Sun's VirtualBox software is flexible virtualization software package which can be installed on Windows, Linux, OS/X or Solaris. With regard to virtual machines, the term host refers to the system (usually physical) which is running the virtual machine, and guest refers to the system being run within the virtual machine. VirtualBox allows users to run Linux guests on Windows hosts, or vice versa.

Requirements

Creating the virtual machine

  1. In VirtualBox, click on New to start the New Virtual Machine Wizard, and then press Next.
  2. Give the new machine a name, and specify the type of operating system (Linux), and the version (Ubuntu).
  3. Use the default base memory size value value of 512MB.
  4. Select Create new disk and press Next to start the Create New Virtual Disk Wizard.
  5. Select Dynamically expanding storage.
  6. Specify a suitable path for Location, and use the default size of 8.00GB.
  7. Press Finish to complete that wizard, and Finish again to complete the previous wizard.
  8. Right-click on the machine and goto Settings... > System > Processor and select "Enable PAE/NX". This is required for the Ubuntu server kernel.

Installing Ubuntu Server Edition

  1. Start the virtual machine, and assuming this is the first time it has been started, you will see the First Run Wizard:
    1. Under Media Source select Image File.
    2. Click the folder icon beside the image list to open the Virtual Media Manager.
    3. Select Add from the top menu, and browse to the Ubuntu Server ISO (e.g. ubuntu-11.04-server-i386.iso).
    4. Double-click the ISO file in the list to select it and close the wizard.
  2. Press Finish and the virtual machine will boot from the installation CD.
  3. Select your language by using the arrow keys and then the enter key (this is only used for the initial menu).
  4. Select Install Ubuntu Server.
  5. Select the language for the installation.
  6. Select your location.
  7. If you know your keyboard layout (most likely USA) skip auto-detection and select it from the list.
  8. The installer will try to automatically configure the networking settings, if you have disabled network access then this will fail. If so, select Do not configure networking at this time.
  9. Enter a suitable hostname.
  10. Next the partitioner dialog will be displayed. Linux operating systems require separate partition for swap space, but the installer can configure this for you:
    1. Select "Guided - use entire disk" to use the entire virtual hard disk for Ubuntu.
    2. Select SCSI1 (0,0,0) (sda) - 8.6GB ATA VBOX HARDDISK.
    3. Select Yes for Write changes to disk to finish the partitioning task.
  11. Provide a user name, and password for the administrator account.
  12. Allow installer to update list of packages, or cancel to update later
  13. Choose an update management strategy
  14. Using the arrow keys and spacebar, select LAMP Server, OpenSSH Server and Tomcat Java Server.
  15. Provide a root password for MySQL which you will need later.
  16. The installer will finish by rebooting into Ubuntu. If you mounted the installation ISO yourself, then you should unmount it (see the Devices menu) to avoid re-running the installer.

Configuring Apache Tomcat

For this step and some subsequent steps we need to edit files on the guest. If you are familiar with editors such as vi or vim you can use one of them, but if not then

is recommended as it easy to use and already installed. The sudo command causes the command following it to be run as root.

  1. Login and type:
    sudo nano /etc/tomcat6/tomcat-users.xml
    
  2. Create a user with the manager and admin roles. Don't forget to remove the XML comments (<!- ->), so the result should look like:
    <tomcat-users>
      <user username="admin" password="XXXXXX" roles="admin,manager"/>
    </tomcat-users>
    
  3. Save (Ctrl+O) and exit (Ctrl+X).
  4. Restart Tomcat using the initialization script:
    sudo /etc/init.d/tomcat6 restart
    

Configuring Port Forwarding to the Guest

VirtualBox's NAT option allows network requests to the host to be forwarded to the guest, which means other computers can access services such as Tomcat which are running on the guest, as if they were running on the host. This step forwards requests on port 8090 on the host, to port 8080 on the guest, which is Tomcat's default port.

  1. Shutdown the virtual machine if it is still running
    sudo shutdown -h 0
    
  2. Right-click on the machine and goto Settings... > Network > Port Forwarding
    1. Add a new rule
      1. Name: Tomcat
      2. Protocol: TCP
      3. Host port: 8090
      4. Guest port: 8080
  3. Restart the virtual machine.
  4. On the host, browse to http://localhost:8090 to verify that the port is being forwarded correctly

Install OpenMRS

  1. On the guest machine, type the following to create the OpenMRS runtime directory:
    sudo mkdir /usr/share/tomcat6/.OpenMRS
    sudo chown -R tomcat6:root /usr/share/tomcat6/.OpenMRS
    
  2. On the host, browse to http://localhost:8090/manager/html to access the Tomcat Managment webapp.
  3. Under the heading Deploy > WAR file to deploy, browse to the OpenMRS WAR file, and then press "Deploy".
  4. Tomcat should report that the deployment succeeded.
  5. Browse to http://localhost:8090/openmrs/ to begin the step-by-step installation of OpenMRS.
    1. Step 1: Select No under Do you currently have an OpenMRS database... and then enter the MySQL root password. Press Continue.
    2. Step 2:
      1. Select Yes under Do you want to add demo data... (assuming you want common concepts and some sample patients)
      2. Select No under Do you currently have a database user... and again enter the MySQL root password. Press Continue.
    3. Step 3: Leave default values, and press Continue.
    4. Step 4: Specify a suitable admin password, and press Continue.
    5. Step 5: Leave values blank, and press Continue.
    6. Step 6: Press Finish to start the OpenMRS installation process, which will take a few minutes.

Conclusion

You should now have a working OpenMRS server, which being a virtual machine, can be paused and resumed whenever it is needed. Additional tasks that you might want to try are:

  • Configure port forwarding to the guest on port 22 to allow SSH connections to the guest system:
    1. Shutdown the machine
    2. Goto Settings... > Network > Port Forwarding
    3. Add a new rule to map the host port 2222 to the guest port 22
    4. Try connecting from host
      ssh localhost -p 2222