Deploying Java Web Projects on Linux with JDK, Tomcat, and MySQL Setup

JDK Installation and Environment Configuration

Create a target directory for installation packages and transfer the compressed JDK archive into it via the virtual machine's shared folder interface. Verify the upload using:

cd javaCloudJun/software
pwd
ll

Edit the system-wide profile to expose the JDK binaries:

vim /etc/profile

Append these lines at the file's end:

# Java runtime configuration
export JDK_ROOT=/root/javaCloudJun/software/jdk1.8.0_151
export JDK_JRE=$JDK_ROOT/jre
export CLASSPATH=.:$JDK_ROOT/lib:$JDK_JRE/lib
export PATH=$JDK_ROOT/bin:$PATH

Save with Esc, then :wq. Confirm changes:

cat /etc/profile

Installing Apache Tomcat

Place the Tomcat archive, e.g., apache-tomcat-8.5.20.tar.gz, into /opt. Extract it to a chosen location:

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

Start the server:

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

Expose port 8080 through the firewlal:

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

To integrate Tomcat with system services, copy its control script:

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

Modify tomcat to include necessary environment variables and comments, then regisetr it:

chkconfig --add tomcat

MySQL Setup and Configuration

Remove conflicting MariaDB libraries:

rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
rpm -qa | grep mariadb

Move the MySQL bundle, e.g., mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar, into /opt and unpack it:

mkdir -p /usr/local/java/mysql-5.7
cd /opt
tar -xvf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar -C /usr/local/java/mysql-5.7

Install required RPMs sequentially:

cd /usr/local/java/mysql-5.7
rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm

Enable and launch the database service:

systemctl start mysqld
systemctl enable mysqld.service

Retrieve the temporary root password and log in:

grep "password" /var/log/mysqld.log
mysql -uroot -p

Inside the session, adjust security constraints and set a new password:

set global validate_password_policy=0;
set global validate_password_length=4;
set password = password('123456');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit

Open MySQL's default port in the firewall:

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

Deploying a Java Web Application

Prepare a database matching the project's schema requirements. Stop Tomcat before proceeding:

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

Copy the application WAR file into Tomcat's webapps directory:

cp myapp.war /usr/local/java/apache-tomcat-8.5.20/webapps/

Restart the servlet container:

./startup.sh

Tags: Linux JDK Tomcat MySQL Java Web Deployment

Posted on Mon, 14 Sep 2026 16:22:12 +0000 by adnanhb