{"id":6265,"date":"2015-05-21T18:35:16","date_gmt":"2015-05-21T10:35:16","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=6265"},"modified":"2023-06-01T14:34:32","modified_gmt":"2023-06-01T14:34:32","slug":"how-to-install-and-setup-apache-tomcat-8-on-centos-7-1-rhel-7","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-install-and-setup-apache-tomcat-8-on-centos-7-1-rhel-7\/","title":{"rendered":"How to Install and Setup Apache Tomcat 8 on CentOS 7 \/ RHEL 7"},"content":{"rendered":"<p><a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-tomcat-explained\/\">Apache Tomcat<\/a> is an open-source Java Servlet and JavaServer Pages implementation that provides a pure Java HTTP web server environment for running Java code. It is widely used for deploying and running Java-based web applications. In this step-by-step guide, we will show you how to install and set up Apache Tomcat 8 on CentOS 7 or RHEL 7.<\/p>\n<h2>Step 1: Install Java Development Kit (JDK)<\/h2>\n<p>Apache Tomcat requires the Java Development Kit (JDK) to run. First, install the JDK using the following commands:<\/p>\n<pre>\r\nsudo yum install -y java-1.8.0-openjdk-devel\r\n<\/pre>\n<p>After installation, verify the installed JDK version:<\/p>\n<pre>\r\njava -version\r\n<\/pre>\n<h2>Step 2: Create Tomcat User<\/h2>\n<p>For security reasons, it&#8217;s recommended to create a separate user to run the Tomcat service:<\/p>\n<pre>\r\nsudo useradd -m -U -d \/opt\/tomcat -s \/bin\/false tomcat\r\n<\/pre>\n<h2>Step 3: Download and Install Apache Tomcat<\/h2>\n<p>Download the latest version of Apache Tomcat 8 from the official website (replace the version number if needed):<\/p>\n<pre>\r\nwget http:\/\/www-eu.apache.org\/dist\/tomcat\/tomcat-8\/v8.5.73\/bin\/apache-tomcat-8.5.73.tar.gz\r\n<\/pre>\n<p>Extract the downloaded archive and move it to the \/opt\/tomcat directory:<\/p>\n<pre>\r\nsudo tar xf apache-tomcat-8.5.73.tar.gz -C \/opt\/tomcat --strip-components=1\r\n<\/pre>\n<h2>Step 4: Configure Tomcat User Permissions<\/h2>\n<p>Set the proper ownership and permissions for the Tomcat directory:<\/p>\n<pre>\r\nsudo chown -R tomcat:tomcat \/opt\/tomcat\r\nsudo chmod -R g+r \/opt\/tomcat\/conf\r\nsudo chmod g+x \/opt\/tomcat\/conf\r\n<\/pre>\n<h2>Step 5: Create a Systemd Service File<\/h2>\n<p>To manage the Tomcat service easily, create a systemd service file:<\/p>\n<pre>\r\nsudo vi \/etc\/systemd\/system\/tomcat.service\r\n<\/pre>\n<p>Add the following content to the file:<\/p>\n<pre>\r\n[Unit]\r\nDescription=Apache Tomcat 8 Servlet Container\r\nAfter=network.target\r\n\r\n[Service]\r\nType=forking\r\nUser=tomcat\r\nGroup=tomcat\r\nEnvironment=\"JAVA_HOME=\/usr\/lib\/jvm\/jre\"\r\nEnvironment=\"CATALINA_BASE=\/opt\/tomcat\"\r\nEnvironment=\"CATALINA_HOME=\/opt\/tomcat\"\r\nEnvironment=\"CATALINA_PID=\/opt\/tomcat\/temp\/tomcat.pid\"\r\nEnvironment=\"CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC\"\r\nExecStart=\/opt\/tomcat\/bin\/startup.sh\r\nExecStop=\/opt\/tomcat\/bin\/shutdown.sh\r\nRestart=on-failure\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n<\/pre>\n<p>Save and close the file.<\/p>\n<h2>Step 6: Start and Enable Tomcat Service<\/h2>\n<p>Reload the systemd daemon and start the Tomcat service:<\/p>\n<pre>\r\nsudo systemctl daemon-reload\r\nsudo systemctl start tomcat\r\nsudo systemctl enable tomcat\r\n<\/pre>\n<h2>Step 7: Adjust Firewall Rules<\/h2>\n<p>If you have a firewall enabled, allow traffic to the default Tomcat port (8080):<\/p>\n<pre>\r\nsudo firewall-cmd --zone=public --permanent --add-port=8080\/tcp\r\nsudo firewall-cmd --reload\r\n<\/pre>\n<h2>Step 8: Verify Tomcat Installation<\/h2>\n<p>To verify that the Tomcat installation was successful, open a web browser and access the Tomcat server using the following URL:<\/p>\n<pre>\r\nhttp:\/\/your_server_ip:8080\r\n<\/pre>\n<p>You should see the Apache Tomcat default welcome page.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-6285 img-fluid lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/05\/setup-tomcat-centos7-1.png\" alt=\"setup-tomcat-centos7-1\" width=\"600\" height=\"438\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/05\/setup-tomcat-centos7-1.png 1013w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/05\/setup-tomcat-centos7-1-300x219.png 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/05\/setup-tomcat-centos7-1-768x560.png 768w\" data-sizes=\"(max-width: 600px) 100vw, 600px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 600px; --smush-placeholder-aspect-ratio: 600\/438;\" \/><\/p>\n<h2>Step 9: Secure the Tomcat Manager<\/h2>\n<p>By default, the Tomcat Manager and Host Manager web applications are not secured. To restrict access, edit the tomcat-users.xml file:<\/p>\n<pre>\r\nsudo vi \/opt\/tomcat\/conf\/tomcat-users.xml\r\n<\/pre>\n<p>Add the following lines before the closing &lt;\/tomcat-users&gt; tag:<\/p>\n<pre>\r\n&lt;role rolename=\"manager-gui\"\/&gt;\r\n&lt;role rolename=\"admin-gui\"\/&gt;\r\n&lt;user username=\"your_username\" password=\"your_password\" roles=\"manager-gui,admin-gui\"\/&gt;\r\n<\/pre>\n<p>Replace your_username and your_password with your desired credentials.<\/p>\n<p>Save and close the file. Restart the Tomcat service for the changes to take effect:<\/p>\n<pre>\r\nsudo systemctl restart tomcat\r\n<\/pre>\n<p>Now, you can access the Tomcat Manager and Host Manager using the following URLs:<\/p>\n<pre>\r\nhttp:\/\/your_server_ip:8080\/manager\/html\r\nhttp:\/\/your_server_ip:8080\/host-manager\/html\r\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>In this guide, we have shown you how to install and set up Apache Tomcat 8 on a CentOS 7 or RHEL 7 system. You can now deploy and manage your Java-based web applications using the Tomcat servlet container.<\/p>\n<p>Remember to keep your system and Tomcat installation up-to-date with the latest security patches and updates. Additionally, maintain good security practices by regularly reviewing and updating user access, permissions, and credentials.<\/p>\n<p>If you have any questions, comments, or suggestions for improvement, please feel free to share your thoughts in the comments section below. Your feedback is invaluable to us, and it helps us create better and more informative content for our users.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache Tomcat is an open-source Java Servlet and JavaServer Pages implementation that provides a pure Java HTTP web server environment for running Java code. It is widely used for deploying&#8230;<\/p>\n","protected":false},"author":6,"featured_media":6286,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1103,2055],"tags":[1199,1260,1975,1536,1839],"class_list":["post-6265","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache","category-centos","tag-apache","tag-centos-7-1","tag-install","tag-linux","tag-tomcat"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/6265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=6265"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/6265\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/6286"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=6265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=6265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=6265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}