# Linux Installation

## Software Requirements for UgandaEMR

```
- Java JDK 8 
- Tomcat 7 or higher
- Mysql 5.6 or 5.7
```

## Installation of Java

1. Login as root in the linux environment
2. Download the JDK 8(jdk-8u361-linux-x64.tar.gz) from this official site:![Download JDK](https://www.oracle.com/java/technologies/downloads/#java8)
3. Open the terminal and enter the following command to create the parent directory to deploy the JDK.\
   `sudo mkdir /usr/lib/jvm`
4. Enter the following command to change the directory `cd /usr/lib/jvm`
5. Extract the jdk-8u361-linux-x64.tar.gz file in the jvm directory using this command

   `sudo tar -xvzf /YourHomeDirectory/jdk-8u361-linux-x64.tar.gz`
6. Enter the following command to open the environment variables file. According to your personal preference, you can choose any text editor instead of nano. `sudo nano /etc/environment`
7. In the opened file, add the following bin folders to the existing PATH variable. Note that the PATH variables must be separated by a colon.

   `/usr/lib/jvm/jdk1.8.0_361/bin`

   `/usr/lib/jvm/jdk1.8.0_361/db/bin`

   `/usr/lib/jvm/jdk1.8.0_361/jre/bin`

   Append the following environment variable to the end of the file.

   ```
   J2SDKDIR="/usr/lib/jvm/jdk1.8.0_361" 

   J2REDIR="/usr/lib/jvm/jdk1.8.0_361/jre"

   JAVA_HOME="/usr/lib/jvm/jdk1.8.0_361"
   ```

   A sample environment file before making these changes would look like the following:

   ```
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
   ```

   The same file after making the changes should look like this:

   ```
   PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
   /usr/lib/jvm/jdk1.8.0_361/bin:/usr/lib/jvm/jdk1.8.0_361/db/bin:/usr/lib/jvm/jdk1.8.0_361/jre/bin"

   J2SDKDIR="/usr/lib/jvm/jdk1.8.0_361"

   J2REDIR="/usr/lib/jvm/jdk1.8.0_361/jre"

   JAVA_HOME="/usr/lib/jvm/jdk1.8.0_361"
   ```
8. Save the changes and close the editor
9. Sometimes an existing JDK installation might have a shortcut added to the /usr/bin directory. Therefore setting the PATH environment variable alone may not change the default Java compiler and runtime. To update these alternative shortcuts, run the following commands:

   `sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_351/bin/java" 0sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_351/bin/javac" 0sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_351/bin/java`

   `sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_351/bin/javac`
10. To verify the setup enter the following commands and make sure that they print the location of java and javac as you have provided in the previous step.

    `update-alternatives --list java`

    `update-alternatives --list javac`
11. Test version on terminal with command
12. `java -version`
13. If you are not able to see the version install missing linux libraries

    `sudo apt-get install libc6-i386`

## Installation of Tomcat

Tomcat installation will require java which were previously installed as shown above

1. `sudo apt update`
2. Set up a Tomcat user `sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat`
3. Download tomcat

`wget -c https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.109/bin/apache-tomcat-7.0.109.tar.gz` 4. Install on linux `sudo tar xf apache-tomcat-7.0.109.tar.gz -C /opt` 5. Rename apache-tomcat-7.0.109 to tomcat

`cd /opt`

`mv apache-tomcat-7.0.109 tomcat`

6. Now we need to provide the user Tomcat with access for the Tomcat installation directory

   `sudo chown -R tomcat: /opt/tomcat/*`
7. Finally, we will use the chmod command to provide all executable flags to all scripts within the bin directory.

   `sudo sh -c 'chmod +x /opt/tomcat/bin/*.sh'`
8. Configure Tomcat serice `sudo nano /etc/systemd/system/tomcat.service`

   Now enter the following in your file and save it. Note that you need to update the value of JAVA\_HOME if your Java installation directory is not the same as given below.

```

    [Unit]
    Description=Apache Tomcat Web Application Container
    After=network.target
   
    [Service]
    Type=forking
      
    Environment="JAVA_HOME=/usr/lib/jvm/jdk1.8.0_361"
    Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
    Environment="CATALINA_HOME=/opt/tomcat/"
    Environment="CATALINA_BASE=/opt/tomcat/"
    Environment="CATALINA_OPTS=-Xms1024M -Xmx2048M -server -XX:+UseParallelGC"
    Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom"
      
    ExecStart=/opt/tomcat/bin/startup.sh
    ExecStop=/opt/tomcat/bin/shutdown.sh
      
    User=tomcat
    Group=tomcat
    UMask=0007
    RestartSec=10
    Restart=always
      
    [Install]
    WantedBy=multi-user.target
```

9. Now we reload the daemon to update the system about the new file.

   `sudo systemctl daemon-reload`
10.
11. Start tomcat service `sudo systemctl start tomcat`
12. Now we can enable the Tomcat service to run on startup using this command. `sudo systemctl enable tomcat`
13. After you install Tomcat, you need to allow it to use the 8080 port through the firewall to be able to communicate outside your local network. `sudo ufw allow 8080/tcp`
14. Once we install Tomcat on Linux, we need to verify our installation. To do so, simply enter the following in your browser.
15. `http://YourIPAddress:8080`

If your installation and configuration were successful, you should see this page. ![Tomcat Home Page](https://2263683135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4YKhNOQtSxoP0vCjuG%2Fuploads%2Fgit-blob-2438ed48f85afee81262f0fae289a8604c4c59e8%2Ftomcat_home.png?alt=media)

14. To enable tomcat to write in /var/lib , create the OpenMRS folder and make tomcat to own it using the commands below

    `cd /var/lib`

    `mkdir OpenMRS`

    `sudo chown tomcat:tomcat OpenMRS/*`
15. Done.

## Mysql 5.6 Installation

Guide for mysql installation is provided in link here [Mysql Installation](https://gist.github.com/dbaluku/f7014c2dcc9f184d5628c132282fa834)

Remember to create mysql user 'openmrs'

## Deploying UgandaEMR on Linux

1. Stop tomcat service `sudo service tomcat stop`
2. copy war file to /opt/tomcat/webapps folder
3. Start tomcat service `sudo service tomcat start`
4. Access the system on browser via `http://YourIPAddress:8080/openmrs`
5. You should see OpenMRS Installation Wizard page as below

   ![Intial page](https://2263683135-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4YKhNOQtSxoP0vCjuG%2F-M4YKl1FNTJE2aTLk1-a%2F-M4YKrV__zNUTpAdcvB9%2Fintital_setup_screen.PNG?generation=1586509618192706\&alt=media)
6. Select your preferred language and click the “=>” button.
7. On the Installation Type screen, choose the Advanced installation type you want and click the “=>” button.

   ![Intial page](https://2263683135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4YKhNOQtSxoP0vCjuG%2Fuploads%2Fgit-blob-361247ca897a74285e4dfd75e785b4942f5f9aec%2Fmanual_install_guide_1.png?alt=media)
8. Fill in your MySQL root password as shown below, and click the “=>” button.

   ![page2](https://2263683135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4YKhNOQtSxoP0vCjuG%2Fuploads%2Fgit-blob-c6a3d0884b3e75112179edecf444f5048b4ac5a6%2Fmaunal_installation_guide_2.png?alt=media)
9. Fill the Next form as shown below and click the “=>” button.

   ![page2](https://2263683135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4YKhNOQtSxoP0vCjuG%2Fuploads%2Fgit-blob-40198619f6beb3393f256bb5a7dd04ba9b0167aa%2Fmanual_install_guide_3.png?alt=media)
10. Fill in options as shown below and click the “=>” button.

    ![page3](https://2263683135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4YKhNOQtSxoP0vCjuG%2Fuploads%2Fgit-blob-58782e4422f7abaf6798f44e46c06ae97f364ac4%2Fmanual_install_guide_4.png?alt=media)
11. Fill in admin password as shown below and click the “=>” button.

    ![page3](https://2263683135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M4YKhNOQtSxoP0vCjuG%2Fuploads%2Fgit-blob-332c77718739c944851406f8e19ebc04247db8ed%2Fmanual_install_guide_5.png?alt=media)
12. Skip next form click the “=>” button.
13. And continue to finish the installation
14. Drop openmrs database dump to openmrs database and restart tomcat service.
15. Done Click the “=>” button to create a database for OpenMRS and complete the installation. Log in to OpenMRS using the default username “admin” and password “Admin123”.
