Setup XNET on AWS Ubuntu EC2 Instance

Abhishek Kumar Gupta
5 min readOct 23, 2024

--

Hope you have already created the AWS Ubuntu EC2 Instance. Now without wasting the time let’s jump upone the xnat setup. Before setup the xnat firstly let’s setup all the required dependency of xnat.

Java 8 Setup

$ sudo apt update
$ sudo apt-get install openjdk-8-jdk also install sudo apt install openjdk-8-jre
#Check for java version using
$ java -version

Apache TomCat SETUP

Before setup the tomcat on Ubuntu EC2 firstly lets create the separate user for tomcat.

$ sudo groupadd tomcat
$ sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

Install TomCat

  1. Firstly copy the link as seen on screenshot

2. Download tomcat from the official site https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.96/bin/ using this command.

3. Better to create new directory at your home path for keeping the downloaded tomcat zip file. Here I have created a tmp directory at root or home location. Now change directory using cd /tmp.

$ curl -O https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.96/bin/apache-tomcat-9.0.96.tar.gz

Note: here you can replace your if this version is not available. But as per the XNAT tomcat9 is storngly recommended
4. Now create new directory for tomcat install.

$ sudo mkdir /opt

5. Go inside /opt directory
6. Install and Extract Tomcat

$ sudo tar -xvzf apache-tomcat-9.0.96.tar.gz -C /opt/

7. Rename the extracted folder for simplicity

$ sudo mv /opt/apache-tomcat-9.0.96 /opt/tomcat

8. Configure Environment Variables

$ sudo nano /etc/environment

9. Add the following lines at the end. Check the attached image for more clear understanding.

CATALINA_HOME="/opt/tomcat"
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
CATALINA_OPTS="-Xms1024m -Xmx4096m -server -XX:+UseParallelGC -Dxnat.home=/data/xnat/home"

Note: Be careful while adding the java-8-openjdk-8-jdk. Please go and check inside the JAVA_HOME path and check it is present or not. If java-8-openjdk-8-jdk not present then check for the correct path if not available then install this. (As per the official doc of xnat only java 8 is supported)

10. Save and close the file. Then, reload the environment. And run the blow command to reload the environment variable.

$ source /etc/environment

11. Set Tomcat as a Service (Linux Only)

$ sudo nano /etc/systemd/system/tomcat.service

12. Copy and paste the below code on above file.

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_Home=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms1024M -Xmx4096M -server -XX:+UseParallelGC -Dxnat.home=/data/xnat/home'
Environment='JAVA_OPTS.awt.headless=true -Djava.security.egd=file:/dev/v/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

13. Reload the systemd daemon

$ sudo systemctl daemon-reload

14. Enable and start Tomcat service

$ sudo systemctl enable tomcat
$ sudo systemctl start tomcat

15. Ensure that your firewall allows traffic on port 8080 (Add 80 and 8080 as inbound security group). After adding the inbound port add the below command.

$ sudo ufw allow 8080/tcp

16 Now open your ip or ec2 domain name with port 8080 suffix:
for ex: 16.171.36.14:8080.

Setup of Postgres 12

Setup postgres 12 on ubuntu (With this version it was easy for me to connect you can also try another versions as well.)

  1. Ensure your system’s package index is up-to-date.
$ sudo apt update

2. Install the prerequisites

$ sudo apt install -y wget ca-certificates

3. Add the PostgreSQL APT repository

$ wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

4. Next, add the repository to your system’s package source list

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

5. Update the package lists again

$ sudo apt update

6. Install PostgreSQL 10 (You can install any other version upto 12 but I found 10 as most supportable version for xnat.

sudo apt install -y postgresql-10

7. PostgreSQL should start automatically after installation. You can verify this with:

$ sudo systemctl status postgresql

8. If it’s not running, you can start it manually

$ sudo systemctl start postgresql

9. To enable PostgreSQL to start on boot:

$ sudo systemctl enable postgresql

10. Verify the installation

psql --version

11. Access the PostgreSQL shell
Firstly run sudo -i -u postgres
And then run psql

$ sudo -i -u postgres
$ psql

12. Now prepart the database, username and password for xnat. (Run the below command one by one)

create database xnat;
CREATE USER xnatuser WITH PASSWORD 'xnat_admin';
grant all privileges on database xnat to xnatuser;

Setup Of XNAT

Reference Link (https://wiki.xnat.org/documentation/xnat-installation-guide) Directly start from step 3 (in reference link) if you are also following the reference document of xnat.

  1. Create the XNAT_HOME set of folders
$ sudo mkdir -p /data/xnat/home/config
$ sudo mkdir /data/xnat/home/logs
$ sudo mkdir /data/xnat/home/plugins
$ sudo mkdir /data/xnat/home/work

2. Create the XNAT data folders

$ sudo mkdir /data/xnat/archive
$ sudo mkdir /data/xnat/build
$ sudo mkdir /data/xnat/cache
$ sudo mkdir /data/xnat/fileStore
$ sudo mkdir /data/xnat/ftp
$ sudo mkdir /data/xnat/inbox
$ sudo mkdir /data/xnat/prearchive

3. Grant ownership to the Tomcat service user

$ sudo chown -R tomcat:tomcat /data

4. Configure XNAT for Initial Startup
4.1. Create the xnat-conf.properties file

$ sudo nano /data/xnat/home/config/xnat-conf.properties

4.2 Now paste the below lines on this file

datasource.driver=org.postgresql.Driver
datasource.url=jdbc:postgresql://localhost:5432/xnat
datasource.username=xnatuser
datasource.password=xnat_admin

#Ignore other lines if you are following the document. Only these 4 are the reqired lines.

4.3. Save and close the file.

5. Download the war file from XNAT official site https://www.xnat.org/download/
and then move this file to /opt/tomcat/webapps (Check attached image)

Note: Better if you can download it directly inside webapps or directly move the xnat-web-1.9.0.war or the lates one inside webapps using FTP(FileZilla) by providing adequate permission and the after transfer revoke this using following command.

$ sudo chown -R tomcat:tomcat /opt/tomcat/webapps

Thank you for going through the article. If you are looking for any assistance related to Html, css, React, React Native, Next.js, Node.js, GraphQl, Python, Django, Flask, Panda. Please let me know. I will be glad to help you.
To tell us about your concern please fill the form: https://docs.google.com/forms/d/1uh343ab8uwVhCpozi_etFyV67f6zVoIiMlrYKLwOgnE/prefill or visit and mail your concern by visiting my blog page.

--

--

Abhishek Kumar Gupta
Abhishek Kumar Gupta

Written by Abhishek Kumar Gupta

Web and Native Mobile App Developer.

No responses yet