Collapse

Announcement

Collapse
No announcement yet.

How to install Tomcat on Cpanel ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to install Tomcat on Cpanel ?

    Can anybody guide me on how to install Tomcat on Cpanel latest edition ? I don't see any option to install tomcat.

  • #2
    Hi,

    Unfortunately, the latest cPanel build are shipped with EasyApache 4 and it does not support tomcat installation in it..

    Comment


    • #3
      You should try the following steps to install tomcat 8 manually on the cpanel server.

      Tomcat requires having java installed on your machine, you can install it using the below command from shell:-

      ```
      yum install java
      ```

      You can verify the java using the following command:-

      ```
      java -version
      ```

      Output:

      ```
      [root@tomcat ~]# java -version
      openjdk version "1.8.0_151"
      OpenJDK Runtime Environment (build 1.8.0_151-b12)
      OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
      ```

      You will need to create a normal tomcat user for running the Tomcat service using the following commands from shell:-

      ```
      groupadd tomcat
      useradd -g tomcat -d /opt/tomcat -s /bin/nologin tomcat
      ```

      Download the latest version of the Apache Tomcat from the website and save it to your home directory.

      Code:
      wget http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.0.48/bin/apache-tomcat-8.0.48.tar.gz
      Extarct the file and move the content under /opt/tomcat/ folder.

      ```
      tar -zxvf apache-tomcat-*.tar.gz
      mv apache-tomcat-8.0.48/* /opt/tomcat/
      ```

      Change the ownership of the directory so that tomcat user can write files in it.

      ```
      chown -R tomcat:tomcat /opt/tomcat/
      ```

      Apache Tomcat can be started and stopped using the script within the package:-

      Start Tomcat
      ```
      [root@tomcat src]# cd /opt/tomcat/bin/
      [root@tomcat bin]# sh startup.sh
      Using CATALINA_BASE: /opt/tomcat
      Using CATALINA_HOME: /opt/tomcat
      Using CATALINA_TMPDIR: /opt/tomcat/temp
      Using JRE_HOME: /usr
      Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
      Tomcat started.
      ```

      Stop tomcat:-
      ```
      [root@tomcat bin]# cd /opt/tomcat/bin/
      [root@tomcat bin]# sh shutdown.sh
      Using CATALINA_BASE: /opt/tomcat
      Using CATALINA_HOME: /opt/tomcat
      Using CATALINA_TMPDIR: /opt/tomcat/temp
      Using JRE_HOME: /usr
      Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
      ```


      You can create a tomcat systemd service file by adding a below code in the file:-

      ```
      [root@tomcat tomcat]# cat /etc/systemd/system/tomcat.service
      [Unit]
      Description=Apache Tomcat 8.x Web Application Container
      Wants=network.target
      After=network.target

      [Service]
      Type=forking

      Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-5.b12.el7_4.x86_64/jre
      Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
      Environment=CATALINA_HOME=/opt/tomcat
      Environment='CATALINA_OPTS=-Xms512M -Xmx1G -Djava.net.preferIPv4Stack=true'
      Environment='JAVA_OPTS=-Djava.awt.headless=true'

      ExecStart=/opt/tomcat/bin/startup.sh
      ExecStop=/opt/tomcat/bin/shutdown.sh
      SuccessExitStatus=143

      User=tomcat
      Group=tomcat
      UMask=0007
      RestartSec=10
      Restart=always

      [Install]
      WantedBy=multi-user.target
      ```


      Reload systemd daemon.
      systemctl daemon-reload

      To start the Tomcat service; run:
      systemctl start tomcat

      Check the status of Tomcat, run:
      systemctl status tomcat

      Enable the auto start of Tomcat service on system start, run:
      systemctl enable tomcat

      Output:

      [root@tomcat tomcat]# systemctl enable tomcat
      Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /etc/systemd/system/tomcat.service.

      ```
      [root@tomcat tomcat]# systemctl status tomcat.service
      ● tomcat.service - Apache Tomcat 8.x Web Application Container
      Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: disabled)
      Active: active (running) since Mon 2018-01-01 08:27:05 UTC; 5s ago
      Process: 2663 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
      Main PID: 2670 (java)
      CGroup: /system.slice/tomcat.service
      └─2670 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-5.b12.el7_4.x86_64/jre/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.proper...

      Jan 01 08:27:05 tomcat.testname.com systemd[1]: Starting Apache Tomcat 8.x Web Application Container...
      Jan 01 08:27:05 tomcat.testname.com startup.sh[2663]: Tomcat started.
      Jan 01 08:27:05 tomcat.testname.com systemd[1]: Started Apache Tomcat 8.x Web Application Container.
      [root@tomcat tomcat]# systemctl enable tomcat
      Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /etc/systemd/system/tomcat.service.
      ```

      Verify Apache Tomcat in working fine or not. Tomcat runs on port no 8080. You can check whether the service is listening on port 8080 or not.

      ```
      [root@tomcat tomcat]# netstat -antup | grep 8080
      tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 2670/java
      ```

      You may need to allow port 8080 in the firewall:-

      ```
      firewall-cmd --permanent --add-port=8080/tcp
      firewall-cmd --reload
      ```

      OR

      ```
      iptables -A INPUT -p tcp -s IPaddress -m tcp --dport 8080 -j ACCEPT
      service iptables savae
      service iptables restart
      ```


      The Web and Host Manager are password protected, requires user name and password to access. Only the user with the “manager-gui” and “admin-gui” role is allowed to access.

      These users and roles are defined in tomcat-users.xml.

      nano /opt/tomcat/conf/tomcat-users.xml

      You will need to add the following two lines just above the last line.

      <role rolename="admin-gui,manager-gui"/>
      <user username="admin" password="tomcat" roles="manager-gui,admin-gui"/>

      Restart the Tomcat.
      systemctl restart tomcat


      Open the tomcat URL in the browser, you can see the Tomcat’s default page.

      Click image for larger version  Name:	tomcat default.PNG Views:	1 Size:	159.7 KB ID:	415

      Web Host Manager required Login to connect:-


      Code:
      http://ipaddress:8080
      Username : admin
      Password : tomcat
      ```

      Now, you can deploy a new application, deploy an application on specified context, start, stop, reload, and un-deploy an application.

      Click image for larger version

Name:	image1.png
Views:	9
Size:	123.8 KB
ID:	419

      That's it.
      Last edited by santosh; 01-01-2018, 04:35 PM.

      Comment

      Working...
      X