Home > English > Tutorials > How to insatll tomcat on centos

How to insatll tomcat on centos


Link to download tomecat versions from 6 to 9  Click here


Here's the instruction to insatll tomcat 9



Vps installed with java , reference link here click here

Open port 8080 bacause tomcat runs through port 8080

# nano /etc/sysconfig/iptables

Add this line

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

Restart iptables

# service iptables restart


Creat a folder named download 

# mkdir /download 

# cd /download 

Use wget command to download tomcat 

# wget http://mirrors.digipower.vn/apache/tomcat/tomcat-9/v9.0.0.M3/bin/apache-tomcat-9.0.0.M3.tar.gz

Use the command tar -xvf <file .tar> to unzip

# tar -xvf apache-tomcat-9.0.0.M3.tar.gz

After unzipping you'll have the folder apache-tomcat-9.0.0.M3. Move it to the folder local and rename it into 'tomcat 9'

# mv apache-tomcat-9.0.0.M3 /usr/local/tomcat9

Move to the folder bin. Here there are many tomcat configuration files

# cd /usr/local/tomcat9/bin/

type this command to start tomcat

# sh startup.sh

If these lines appear, you've succeeded 

[[email protected] bin]# sh startup.sh
Using CATALINA_BASE:   /usr/local/tomcat9
Using CATALINA_HOME:   /usr/local/tomcat9
Using CATALINA_TMPDIR: /usr/local/tomcat9/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat9/bin/bootstrap.jar:/usr/local/tomcat9/bin/tomcat-juli.jar
Tomcat started.

Try visiting the address http://<ip-vps>:8080 and the result is like this 

If you want to remove the number 8080, follow these steps 

# nano /usr/local/tomcat9/conf/server.xml

Find number 8080 and change them into 80

restart tomcat

# sh shutdown.sh

# sh startup.sh

Open the gateway 80 on iptables 

# nano /etc/sysconfig/iptables

Add this line 

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

Restart iptables

# service iptables restart

Add admin user 

Edit the file tomcat-users.xml

# nano /usr/local/tomcat9/conf/tomcat-users.xml

Close green lines and add yellow lines. Put them between <tomcat-users> </tomcat-users>

<tomcat-users xmlns="http://tomcat.apache.org/xml" 
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary.
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  <!.. ..> that surrounds them.

#  <role rolename="tomcat"/>
#  <role rolename="role1"/>
#  <user username="tomcat" password="tomcat" roles="tomcat"/>
#  <user username="both" password="tomcat" roles="tomcat,role1"/>
#  <user username="role1" password="tomcat" roles="role1"/>

<role rolename="admin-gui" />

<user username="admin" password="_SECRET_PASSWORD_" roles="manager-gui,admin-gui" />

<role rolename="manager-gui" />

<user username="manager" password="_SECRET_PASSWORD_" roles="manager-gui" />