How to deploy spring boot application in cyberpanel?

I have my application developed in spring boot (rest api), and I have cyberpanel installed on my server. I have seen many examples of how to deploy a spring boot application in cyberpanel.
Does anyone have an idea how to do it?

Hello @hamdi

Assuming you want to deploy a RESTful Web Service

  1. Install JDK from Archived OpenJDK GA Releases or https://adoptopenjdk.net/ for example setting up JDK 15.0.2:
# Java Runtime Environment. It is a package of everything necessary to run a compiled Java program, including the Java Virtual Machine (JVM), the Java Class Library, the java command, and other infrastructure.
# Java Development Kit, the full-featured SDK for Java. It has everything the JRE has, but also the compiler (javac) and tools (like javadoc and jdb). It is capable of creating and compiling programs.
# https://jdk.java.net/archive/
$ wget https://download.java.net/java/GA/jdk15.0.2/0d1cfde4252546c6931946de8db48ee2/7/GPL/openjdk-15.0.2_linux-x64_bin.tar.gz
$ tar -zxvf OpenJDK15U-jdk_x64_linux_hotspot_15.0.2_7.tar.gz
$ mv jdk-15.0.2+7  /usr/lib/jvm/ 
$ update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-15.0.2+7/bin/java 1
$ update-alternatives --config java
$ export JAVA_HOME=/usr/lib/jvm/jdk-15.0.2+7
$ export PATH=$PATH:$JAVA_HOME/bin
$ java --version
  1. Install and setup Apache Tomcat
$ wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.0.0-M1/bin/apache-tomcat-10.0.0-M1.tar.gz
$ mv apache-tomcat-10.0.0-M1.tar.gz /usr/share
$ cd /usr/share && tar xvf apache-tomcat-10.0.0-M1.tar.gz
$ rm -f apache-tomcat-10.0.0-M1.tar.gz
$ mv apache-tomcat-10.0.0-M1.tar.gz tomcat10
## SSL configuration - https://tomcat.apache.org/tomcat-10.0-doc/ssl-howto.html
$ keytool -genkey -keyalg RSA -keysize 2048 -alias tomcat -keystore /usr/share/tomcat.keystore
$ nano /usr/share/tomcat10/conf/server.xml

Add the following

...
<Service name="Catalina">

<Connector
protocol="org.apache.coyote.http11.Http11NioProtocol"
port="18443"
maxThreads="200"
scheme="https"
secure="true"
SSLEnabled="true"
keystoreFile="/usr/share/tomcat.keystore"
keystorePass="fTy967"
clientAuth="false"
sslProtocol="TLS"
URIEncoding="UTF-8"
compression="force"
acceptCount="100"
minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
disableUploadTimeout="true"
maxHttpHeaderSize="8192"
compressableMimeType="text/html,text/xml,text/plain,text/javascript,text/css"/>

<Engine name="Catalina" defaultHost="localhost">
...
  1. Add JDBC driver for Drizzle and MySQL
## https://repo1.maven.org/maven2/org/drizzle/jdbc/drizzle-jdbc/
$ cd /usr/share/tomcat10/lib
$ wget https://repo1.maven.org/maven2/org/drizzle/jdbc/drizzle-jdbc/1.4/drizzle-jdbc-1.4.jar
  1. Add MySQL JDBC Connector
$ wget https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-8.0.21.tar.gz
$ tar -xvf mysql-connector-java-8.0.21.tar.gz && mv mysql-connector-java-8.0.21/mysql-connector-java-8.0.21.jar /usr/share/tomcat10/lib/
$ rm -r mysql-connector-java-8.0.21.tar.gz mysql-connector-java-8.0.21
  1. Setup Apache Tomcat Service:
$ nano /etc/init.d/tomcat10
#!/bin/bash
### BEGIN INIT INFO
# Provides:         tomcat
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Auto-starts tomcat
# pidfile: /var/run/tomcat.pid
### END INIT INFO

case $1 in
start)
sh /usr/share/tomcat10/bin/startup.sh
;;
stop)
sh /usr/share/tomcat10/bin/shutdown.sh
;;
restart)
sh /usr/share/tomcat10/bin/shutdown.sh
sh /usr/share/tomcat10/bin/startup.sh
;;
esac
exit 0

Finally:

$ chmod 755 /etc/init.d/tomcat10
$ ln -s /etc/init.d/tomcat10 /etc/rc1.d/K99tomcat
$ ln -s /etc/init.d/tomcat10 /etc/rc2.d/S99tomcat
$ systemctl enable tomcat10
$ systemctl start tomcat10
$ systemctl status tomcat10
  1. Deploy your JAR/WAR projects
# clone your repo here or rsync project from remote server
$ cd /usr/share/tomcat10/webapps/

Go to firewall and add port 18443 to firewall list.

If setup correctly you will see your webapp https://SERVER_URL:18443/springboot-rest-app. To access the REST app from a domain name proceed to create a website

To remove the port number use the guide similar to How to remove port 8090 from CyberPanel to proxy

1 Like

@josephgodwinke
Thanks i will try if i face a problem i will reply her.