cPanel

Tomcat: Easy apache 4 How to add/enable on cPanel / Cloudlinux Server.

INSTALLING TOMCAT ON CPANEL SERVER

       PART A

We can install tomcat on cPanel server easily from easyapache 4.

Login to WHM Panel >>> Software >>> EasyApache 4 >>> Then click on “Customize” button present in front of “Currently Installed Packages” >>> Then Click on “Additional Packages” option present at left hand side >>> Select Tomcat and click next >>> Then at Review Page, plz check carefully which packages going to be installed, which packages going to be removed and then only click on “Provision” button.

Before deploying the war file, we need to do some IMP settings on the server like enabling the JAVA support in CloudLinux.

1} We need to add more heap memory in Tomcat which can be done in /opt/cpanel/ea-tomcat85/bin/catalina.sh

export JAVA_OPTS=”-Xms512M -Xmx1024M”
export CATALINA_OPTS=”-Xms512M -Xmx1024M”

{NOTE:Perform below steps only if server has cloudlinux installed on it.}

2} Now we need to enable JAVA support in Cloudlinux
Create /etc/cagefs/conf.d/java.cfg and add proper binary files to it:

vi /etc/cagefs/conf.d/java.cfg

comment=Java-custom
paths=/usr/bin/java, /etc/alternatives/java

3}Update skeleton and remount all:
cagefsctl –force-update
cagefsctl –remount-all

4} Added Tomcat-related rpm’s to CageFS:
cagefsctl –addrpm java-1.8.0-openjdk-headless
cagefsctl –addrpm ea-tomcat85
cagefsctl –addrpm tzdata-java
cagefsctl –force-update
cagefsctl -M


               PART B

DEPLOYING TOMCAT APPLICATION

Before deployin TOMCAT application, we need to activate/enable the tomcat support on cPanel account {Domain}

Login to WHM Panel >>> Software >>> Tomcat Manager >>> Search the cPanel user name for which we want to enable the Tomcat and enable it.

++++++++++++++++++++++++++++++++++++++++

Now Deploy the Tomcat Application using following steps.

1) Build your web app – let’s go with a .war file for example purposes. Rename it to ROOT.war.

2) In your server go to the following location, /home/user-name/ea-tomcat85/webapps

3) Copy your ROOT.war file into the location (Step 2)

4) Go to /home/user-name/ea-tomcat85/conf file. There you should find a server.xml file.

Edit server.xml file and add below lines {Replace “user” with cPanel username}


NOW WE CAN TEST OUR CONFIGURATION


1} Run the following commands, where user represents the username:

su – user
echo “export PATH=$(dirname $(readlink /usr/local/cpanel/3rdparty/bin/perl)):$PATH” >> /home/cpuser/.bashrc
source ~/.bashrc

2}Now edit /home/user-name/ea-tomcat85/conf/server.xml file again and change the following value.


vi server.xml
deployOnStartup=”true”

3}You can Copy cPanel’s test javascript to check whether tomcat is working or not.


cp /opt/cpanel/ea-tomcat85/test.jsp /home/cpuser/ea-tomcat85/webapps/ROOT/

4} Restart Tomcat:


ubic restart ea-tomcat85

5} Check your HTTP connector’s port:


egrep ‘Connector port.*HTTP’ ~/ea-tomcat85/conf/server.xml

Above commands output will look like

6} Now first open Connector port in firewall and browse the website using URL

http://domain.com:10000/test.jsp


NOW IF CLIENT WANTS TO ACCESS HIS TOMCAT APPLICATION WITHOUT USING ANY PORT NUMBER LIKE HTTP://DOMAIN.COM THEN WE NEED TO ENABLE MOD_PROXY CONFIGURATION

1) Use the command vi server.xml to view the server.xml file. Find the Ajp/1.3 connector port. It should look something like this:


Remember the port number is 10001.

OR

root@12548703 ~]# egrep “Connector port.*AJP” /home/CPANEL-USER/ea-tomcat85/conf/server.xml

Output of above command will be like this,

{NOTE: NOW REMEMBER, THERE ARE 2 DIFFERENT CONNECTOR PORT. ONE IS WITH HTTP PROTOCOL AND ANOTHER ONE WITH AJP PROTOCOL. CONNECTOR PORT WITH HTTPD PROTOCOL IS USE TO ACCESS THE TOMCAT APPLICATION USING PORT NUMBER}

2) Now go to the location /etc/apache2/conf.d/userdata/std/2/ and run below command.
mkdir -p cPanel-user/your-domain-name

{Replace “cPanel-user” with actual cPanel username and “your-domain-name” with actual domain name}

6) Now go to following location: /etc/apache2/conf.d/userdata/std/2/cPanel-user/your-domain-name/

Now create a file named custom.conf.

Write the below code:

ProxyPass “/” “ajp://127.0.0.1:10001/”

Finally, save it. “10001” is connector AJP port which we found in server.xml file

This gives your website HTTP access.

7) Now got to the following location: /etc/apache2/conf.d/userdata/ssl/2/
mkdir -p cPanel-user/your-domain-name

{Replace “cPanel-user” with actual cPanel username and “your-domain-name” with actual domain name}

Now go to following location: /etc/apache2/conf.d/userdata/ssl/2/cPanel-user/your-domain-name

Create a file named custom.conf.

Write the below code:

ProxyPass “/” “ajp://127.0.0.1:10001/”

Finally, save it. “10001” is connector AJP port which we found in server.xml file

This gives your server HTTPS access

8) Now you need to rebuild the HTTPD, so use the below command

/scripts/rebuildhttpdconf

And now restart the HTTPD by using the below command:

/scripts/restartsrv_httpd


JUST FOR YOUR INFORMATION,

We can set the heap memory for User in setenv.sh file and location of setenv.sh file is /home/CPANEL-USER/ea-tomcat85/bin/setenv.sh

In order to increase the heap memory, edit setenv.sh file and paste below code in it.

export CATALINA_OPTS=”$CATALINA_OPTS -Xms512m”
export CATALINA_OPTS=”$CATALINA_OPTS -Xmx8192m”

And if you want to increase the heap memory to 1 GB then paste below code in setenv.sh file.

export CATALINA_OPTS=”$CATALINA_OPTS -Xms1g”
export CATALINA_OPTS=”$CATALINA_OPTS -Xmx1g”

JUST MAKE SURE THAT YOU WILL TAKE THE BACKUP OF SETENV.SH FILE BEFORE EDITING IT.

Also read:-


Amit Jadhav
Amit Jadhav is working in Hostripples since years he is a passionate engineer... He is working as a senior technical support engineer, as it's a responsible position because it's a lifeline to our customers... Moreover he is dealing in troubleshooting server problems and is always ready to assist our customers in technical issues... Hostripples is glad to have Amit Jadhav on the board...

Recent Posts

The Ultimate Showdown: Linux vs Windows for VPS Hosting

As the demand for virtual private servers (VPS) continues to grow, businesses and individuals are faced with a crucial decision:…

2 weeks ago

Questions to Ask Your Web Hosting Support Team

Web hosting is a large industry, as many other factors help any web hosting provider to form a company. The…

2 weeks ago

How to Secure Your WordPress Site in 2025

Welcome to the complete guide to WordPress security best practices in 2024. As technology evolves rapidly, implementing strong security measures…

3 weeks ago

Unlocking the Secrets of Hosting: Essential Questions to Ask Hostripples

Hey, wanted to learn about web hosting? Or do you want to start a new website and need hosting? Questions…

3 weeks ago

DDoS Attacks: What You Need to Know for Protection

In today's digital world, the threat of DDoS attacks has become increasingly prevalent. These types of attacks have the power…

1 month ago