{"id":11470,"date":"2024-02-27T14:31:13","date_gmt":"2024-02-27T14:31:13","guid":{"rendered":"https:\/\/myprojects.advchaweb.com\/?p=11470"},"modified":"2024-02-27T15:51:55","modified_gmt":"2024-02-27T15:51:55","slug":"install-java-and-tomcat-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/myprojects.advchaweb.com\/index.php\/2024\/02\/27\/install-java-and-tomcat-on-ubuntu-22-04\/","title":{"rendered":"Install Java and Tomcat on Ubuntu 22.04"},"content":{"rendered":"<p>READ: https:\/\/tecadmin.net\/how-to-install-tomcat-on-ubuntu-22-04\/<br \/>\nALSO READ: https:\/\/myprojects.advchaweb.com\/index.php\/2021\/09\/27\/install-tomcat-on-ubuntu-20-04\/<\/p>\n<p>INSTALL OPENJDK 11<\/p>\n<pre class=\"lang:default decode:true \">sudo apt install openjdk-11-jdk<\/pre>\n<p>CHECK JAVA VERSION<\/p>\n<pre class=\"lang:default decode:true \">satria@teddy:~$ java --version\r\nopenjdk 11.0.22 2024-01-16\r\nOpenJDK Runtime Environment (build 11.0.22+7-post-Ubuntu-0ubuntu222.04.1)\r\nOpenJDK 64-Bit Server VM (build 11.0.22+7-post-Ubuntu-0ubuntu222.04.1, mixed mode, sharing)<\/pre>\n<p>CREATE A TOMCAT USER<\/p>\n<pre class=\"lang:default decode:true \">sudo useradd -r -m -U -d \/opt\/tomcat -s \/bin\/false tomcat<\/pre>\n<p>DOWNLOAD TOMCAT 10<br \/>\nAT THE TIME, THE LATEST STABLE VERSION IS 10.1.19. DOWNLOAD THE BINARY (https:\/\/dlcdn.apache.org\/tomcat\/tomcat-10\/v10.1.19\/bin\/apache-tomcat-10.1.19.tar.gz)<\/p>\n<p>EXTRACT IT TO \/opt\/tomcat DIR<\/p>\n<pre class=\"lang:default decode:true \">satria@teddy:~\/Downloads$ sudo tar xzf apache-tomcat-10.1.19.tar.gz -C \/opt\/tomcat<\/pre>\n<p>SET THE PERMISSION<br \/>\nFirst, we\u2019ll change the directory ownership to tomcat.<\/p>\n<pre class=\"lang:default decode:true \">satria@teddy:~\/Downloads$ sudo chown -R tomcat: \/opt\/tomcat<\/pre>\n<p>Next, make all scripts within the bin directory executable.<\/p>\n<pre class=\"lang:default decode:true \">satria@teddy:~\/Downloads$ sudo sh -c 'chmod +x \/opt\/tomcat\/apache-tomcat-10.1.19\/bin\/*.sh'<\/pre>\n<p>Create Tomcat Application Accounts<br \/>\nNow, configure your tomcat with user accounts to secure access of admin\/manager pages. To do this, edit\u00a0conf\/tomcat-users.xml\u00a0file in your editor and paste the following code inside &lt;tomcat-users&gt; &lt;\/tomcat-users&gt; tags. We recommend changing the password in the below configuration with high secured password.<\/p>\n<pre class=\"lang:default decode:true \">sudo gedit \/opt\/tomcat\/apache-tomcat-10.1.19\/conf\/tomcat-users.xml<\/pre>\n<p>ADD THE ROLES<\/p>\n<pre class=\"lang:default decode:true \">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n...\r\n&lt;tomcat-users xmlns=\"http:\/\/tomcat.apache.org\/xml\"\r\n              xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n              xsi:schemaLocation=\"http:\/\/tomcat.apache.org\/xml tomcat-users.xsd\"\r\n              version=\"1.0\"&gt;\r\n  ...\r\n  &lt;!-- user manager can access only the manager section --&gt;\r\n  &lt;role rolename=\"manager-gui\" \/&gt;\r\n  &lt;user username=\"manager\" password=\"Admin@123\" roles=\"manager-gui\" \/&gt;\r\n   \r\n  &lt;!-- user admin can access manager and admin section both --&gt;\r\n  &lt;role rolename=\"admin-gui\" \/&gt;\r\n  &lt;user username=\"admin\" password=\"Admin@123\" roles=\"manager-gui,admin-gui\" \/&gt;\r\n&lt;\/tomcat-users&gt;<\/pre>\n<p>Allow Remote Hosts to Access Tomcat<br \/>\nThe default Tomcat manager and host-manager applications are accessible for localhost only. To allow access to these pages from the remote system, you need to modify the following configuration files.<\/p>\n<p>You can either allow a specific remote system or allow all. Edit the\u00a0context.xml\u00a0file for manager and host manager application:<\/p>\n<pre class=\"lang:default decode:true\">sudo gedit \/opt\/tomcat\/apache-tomcat-10.1.19\/conf\/tomcat-users.xml<\/pre>\n<p>Comment out the section added for IP address restriction to allow connections from anywhere.<\/p>\n<pre class=\"lang:default decode:true \">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n...\r\n&lt;Context antiResourceLocking=\"false\" privileged=\"true\" &gt;\r\n  &lt;CookieProcessor className=\"org.apache.tomcat.util.http.Rfc6265CookieProcessor\"\r\n                   sameSiteCookies=\"strict\" \/&gt;\r\n  &lt;!--&lt;Valve className=\"org.apache.catalina.valves.RemoteAddrValve\"\r\n         allow=\"127\\.\\d+\\.\\d+\\.\\d+|::1|0:0:0:0:0:0:0:1\" \/&gt;--&gt;\r\n  &lt;Manager sessionAttributeValueClassNameFilter=\"java\\.lang\\.(?:Boolean|Integer|Long|Number|String)|org\\.apache\\.catalina\\.filters\\.CsrfPreventionFilter\\$LruCache(?:\\$1)?|java\\.util\\.(?:Linked)?HashMap\"\/&gt;\r\n&lt;\/Context&gt;<\/pre>\n<p>Similarly edit\u00a0context.xml\u00a0for host manager application in text editor:<\/p>\n<pre class=\"lang:default decode:true\">sudo gedit \/opt\/tomcat\/apache-tomcat-10.1.19\/webapps\/manager\/META-INF\/context.xml<\/pre>\n<p>Create a Systemd Service File<br \/>\nWe\u2019ll now create a systemd service file to manage the Tomcat service. Open a new service file in a text editor:<\/p>\n<pre class=\"lang:default decode:true \">sudo gedit \/etc\/systemd\/system\/tomcat.service<\/pre>\n<p>Paste in the following configuration:<\/p>\n<pre class=\"lang:default decode:true\">[Unit]\r\nDescription=Apache Tomcat 10 Web Application Server\r\nAfter=network.target\r\n \r\n[Service]\r\nType=forking\r\n \r\nUser=tomcat\r\nGroup=tomcat\r\n \r\nEnvironment=\"JAVA_HOME=\/usr\/lib\/jvm\/java-11-openjdk-amd64\"\r\nEnvironment=\"CATALINA_HOME=\/opt\/tomcat\/apache-tomcat-10.1.19\"\r\nEnvironment=\"CATALINA_BASE=\/opt\/tomcat\/apache-tomcat-10.1.19\"\r\nEnvironment=\"CATALINA_PID=\/opt\/tomcat\/apache-tomcat-10.1.19\/temp\/tomcat.pid\"\r\nEnvironment=\"CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC\"\r\n \r\nExecStart=\/opt\/tomcat\/apache-tomcat-10.1.19\/bin\/startup.sh\r\nExecStop=\/opt\/tomcat\/bin\/apache-tomcat-10.1.19\/shutdown.sh\r\n \r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n<p>Start and Enable Tomcat<br \/>\nAfter creating the service file, reload the systemd daemon to read the new file:<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl daemon-reload<\/pre>\n<p>Next, start the Tomcat service with:<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl start tomcat<\/pre>\n<p>CHECK Tomcat service status<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl status tomcat\r\n\u25cf tomcat.service - Apache Tomcat 10 Web Application Server\r\n     Loaded: loaded (\/etc\/systemd\/system\/tomcat.service; disabled; vendor prese&gt;\r\n     Active: active (running) since Tue 2024-02-27 22:00:28 WIB; 12s ago\r\n    Process: 20153 ExecStart=\/opt\/tomcat\/apache-tomcat-10.1.19\/bin\/startup.sh (&gt;\r\n   Main PID: 20160 (java)\r\n      Tasks: 29 (limit: 57572)\r\n     Memory: 138.3M\r\n        CPU: 3.931s\r\n     CGroup: \/system.slice\/tomcat.service\r\n             \u2514\u250020160 \/usr\/lib\/jvm\/java-11-openjdk-amd64\/bin\/java -Djava.util.lo&gt;\r\n\r\nFeb 27 22:00:28 teddy systemd[1]: Starting Apache Tomcat 10 Web Application Ser&gt;\r\nFeb 27 22:00:28 teddy startup.sh[20153]: Tomcat started.\r\nFeb 27 22:00:28 teddy systemd[1]: Started Apache Tomcat 10 Web Application Serv&gt;\r\nlines 1-14\/14 (END)\r\n<\/pre>\n<p>If everything went well, enable Tomcat to start on boot:<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl enable tomcat<\/pre>\n<p>Open the Firewall<br \/>\nYou also need to check if the firewall is not blocking the incoming connections to Tomcat\u2019s port (default is 8080). This depends on what firewall you are using:<\/p>\n<p>For UFW (Uncomplicated Firewall) in Ubuntu:<\/p>\n<pre class=\"lang:default decode:true \">satria@teddy:~\/Downloads$ sudo ufw allow 8080\r\nRules updated\r\nRules updated (v6)<\/pre>\n<p>Test the Installation<br \/>\nThe default Tomcat server runs on port 8080. As you have configured Tomcat on your system, you can access web interface from your system. You can access tomcat interfaces by entering your server\u2019s IP address or a domain name pointed to that server, followed by port 8080 in your browser:<\/p>\n<p>http:\/\/localhost:8080\/<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11474\" src=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2024\/02\/screenshot-localhost_8080-2024.02.27-22_04_10.png\" alt=\"\" width=\"1026\" height=\"882\" srcset=\"https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2024\/02\/screenshot-localhost_8080-2024.02.27-22_04_10.png 1026w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2024\/02\/screenshot-localhost_8080-2024.02.27-22_04_10-300x258.png 300w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2024\/02\/screenshot-localhost_8080-2024.02.27-22_04_10-1024x880.png 1024w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2024\/02\/screenshot-localhost_8080-2024.02.27-22_04_10-768x660.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p>Tomcat Manager App is a web application packaged with the Tomcat server application. The Manager interface provides us with the basic functionality we need to manage our deployed web applications.<\/p>\n<p>Click the\u00a0Manager App\u00a0button home page or directly type\u00a0\/manager\u00a0in the browser URL of the main Tomcat server to access it.<br \/>\nhttp:\/\/localhost:8080\/manager\/html<br \/>\nuser: admin<br \/>\npass: Admin@123<\/p>\n<p>TOMCAT LOG<br \/>\nTHE DEFAULT LOG FILE IS IN \/opt\/tomcat\/apache-tomcat-10.1.19\/logs\/ DIR!<br \/>\nTHE LOG FILE IS \/opt\/tomcat\/apache-tomcat-10.1.19\/logs\/catalina.out<br \/>\nTo change the default location of the log file, edit the startup.sh file and locate the entry:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>READ: https:\/\/tecadmin.net\/how-to-install-tomcat-on-ubuntu-22-04\/ ALSO READ: https:\/\/myprojects.advchaweb.com\/index.php\/2021\/09\/27\/install-tomcat-on-ubuntu-20-04\/ INSTALL OPENJDK 11 sudo apt install openjdk-11-jdk CHECK JAVA VERSION satria@teddy:~$ java &#8211;version openjdk 11.0.22 2024-01-16 OpenJDK Runtime Environment (build 11.0.22+7-post-Ubuntu-0ubuntu222.04.1) OpenJDK 64-Bit Server VM (build 11.0.22+7-post-Ubuntu-0ubuntu222.04.1, mixed mode, sharing) CREATE A TOMCAT USER sudo useradd -r -m -U -d \/opt\/tomcat -s \/bin\/false tomcat DOWNLOAD TOMCAT 10 AT THE TIME, &hellip; <a href=\"https:\/\/myprojects.advchaweb.com\/index.php\/2024\/02\/27\/install-java-and-tomcat-on-ubuntu-22-04\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Install Java and Tomcat on Ubuntu 22.04&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[122,132],"tags":[],"class_list":["post-11470","post","type-post","status-publish","format-standard","hentry","category-java","category-ubuntu-22-04"],"_links":{"self":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/11470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/comments?post=11470"}],"version-history":[{"count":5,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/11470\/revisions"}],"predecessor-version":[{"id":11477,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/11470\/revisions\/11477"}],"wp:attachment":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/media?parent=11470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/categories?post=11470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/tags?post=11470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}