Deploying Frontend and Backend Projects on Linux: A Complete Implementation Guide

JDK Installation

Verifying Existing JDK

java -version

Extracting the JDK Package

Navigate to the opt directory where the package was uploaded, then extract it to the designated location:

cd /opt/
tar -zxvf jdk-8u151-linux-x64.tar.gz -C /usr/local/java

Creating the Target Directory

cd /usr/local/
mkdir java
cd /opt
tar -zxvf jdk-8u151-linux-x64.tar.gz -C /usr/local/java

Configuring Environment Variables

Edit the system profile to add Java-related environment variables:

vim /etc/profile

Add the following lines at the end of the file:

export JAVA_HOME=/usr/local/java/jdk1.8.0_151
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

Apply the changes:

source /etc/profile

Verifying Installation

java -version

Tomcat Installation

Extracting Tomcat

cd /opt/
tar -zxvf apache-tomcat-8.5.20.tar.gz -C /usr/local/java

Starting Tomcat

cd /usr/local/java/apache-tomcat-8.5.20/bin/
./startup.sh

Firewall Configuration

Open port 8080 for external access:

firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports

Creating an Init Script for Auto-Start

Copy the startup script to the init directory:

cd /usr/local/java/apache-tomcat-8.5.20/bin/
cp /usr/local/java/apache-tomcat-8.5.20/bin/catalina.sh /etc/init.d
cd /etc/init.d/
mv catalina.sh tomcat

Edit the script to add required configurations at the beginning:

vim tomcat

Add these lines:

JAVA_HOME=/usr/local/java/jdk1.8.0_151
CATALINA_HOME=/usr/local/java/apache-tomcat-8.5.20
#chkconfig:23456 10 90
#description: tomcat service

Register the service with chkconfig:

chkconfig --add tomcat

Testing the Setup

Reboot the server to verify Tomcat starts automatically:

reboot

MySQL Installation

Checking for Exissting MariaDB

RPM-based distributions often include MariaDB, which must be removed first:

rpm -qa|grep mariadb

Remove any found packages:

rpm -e --nodeps <package-name>

Extracting MySQL Package

cd /opt/
tar -xvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

Initializing and Configuring MySQL

cd /usr/local/mysql
mkdir data
useradd mysql
chown -R mysql:mysql /usr/local/mysql
cd /usr/local/mysql/bin
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

Creating the MySQL Service File

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

Starting the MySQL Service

service mysqld start

Setting Root Password

mysql -u root -p

Execute the following SQL command:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123';

Enabling Auto-Start

systemctl enable mysqld

Nginx Installation

Installing Dependencies

yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel -y

Extracting and Building Nginx

cd /opt/
tar -zxvf nginx-1.20.2.tar.gz
cd nginx-1.20.2
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install

Configuring SSL for HTTPS

Generate SSL certificates in /usr/local/nginx/cert/:

mkdir -p /usr/local/nginx/cert

Edit the Nginx configuration:

vim /usr/local/nginx/conf/nginx.conf

Add SSL configuration within the server block:

server {
    listen 443 ssl;
    server_name yourdomain.com;
    ssl_certificate cert/server.pem;
    ssl_certificate_key cert/server.key;
    
    location / {
        root html;
        index index.html;
    }
}

Opening Required Ports

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload

Starting Nginx

/usr/local/nginx/sbin/nginx

Enabling Auto-Start

Create a systemd service file:

vim /etc/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Enable and start the service:

systemctl enable nginx
systemctl start nginx

Tomcat Load Balancing with Nginx

Why Use Load Balancing

When deploying multiple backend instances, Nginx distributes requests across Tomcat servers, improving performance and providing redundancy.

Configuring Nginx for Load Balancing

Edit the Nginx configuration file:

vim /usr/local/nginx/conf/nginx.conf

Add an upstream block and modify the server configuration:

upstream tomcat_cluster {
    server 127.0.0.1:8081 weight=1;
    server 127.0.0.1:8080 weight=2;
}

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://tomcat_cluster;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Opening Backend Ports

firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --reload

Starting Additional Tomcat Instance

Deploy another Tomcat instance on port 8081:

cd /usr/local/tomcat2/bin/
./startup.sh

Restarting Nginx

/usr/local/nginx/sbin/nginx -s reload

Deploying Backend Application

Building the WAR Package

Package your Java application as a WAR file using Maven or your build tool:

mvn clean package

Deploying to Tomcat Instances

Copy the WAR file to both Tomcat webapps directories:

cp target/your-app.war /usr/local/java/apache-tomcat-8.5.20/webapps/
cp target/your-app.war /usr/local/tomcat2/webapps/

Tomcat automatically deploys WAR files on access.

Verifying Deployment

curl http://localhost:8080/your-app/health
curl http://localhost:8081/your-app/health

Frontend Deployment

Preparing the Build

Build the frontend project:

npm run build

Extracting the Build Package

Upload and extract the frontend package:

cd /opt/
tar -zxvf frontend-build.tar.gz -C /usr/local/nginx/html

Configuring Nginx for Frontend

Edit the Nginx configuration:

vim /usr/local/nginx/conf/nginx.conf
server {
    listen 80;
    server_name yourdomain.com;
    root /usr/local/nginx/html/dist;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location /api {
        proxy_pass http://tomcat_cluster;
        proxy_set_header Host $host;
    }
}

Configuring API Endpoints

Update the frontend configuration to point to the correct API endpoints:

// config.js
window.API_BASE_URL = 'https://yourdomain.com/api';

Reloading Nginx

/usr/local/nginx/sbin/nginx -s reload

Testing the Deployment

Access the application through the domain or server IP to verify both frontend and backend communication work correctly.

Environment Variable Quick Reference

Variible Value
JAVA_HOME /usr/local/java/jdk1.8.0_151
CATALINA_HOME /usr/local/java/apache-tomcat-8.5.20
NGINX_HOME /usr/local/nginx
MYSQL_HOME /usr/local/mysql

Tags: Linux JDK Tomcat MySQL nginx

Posted on Wed, 04 Nov 2026 16:39:41 +0000 by illuz1on