<\/span><\/h2>\n\n\n\nSince Tomcat is written in Java, we need to install it with the following command:<\/p>\n\n\n\n
sudo apt install default-jdk -y<\/pre>\n\n\n\nTo verify the installed version, execute the following command:<\/p>\n\n\n\n
java --version<\/pre>\n\n\n\nYou should get output similar to this:<\/p>\n\n\n\n
root@host:~# java --version\nopenjdk 11.0.18 2023-01-17\nOpenJDK Runtime Environment (build 11.0.18+10-post-Debian-1deb11u1)\nOpenJDK 64-Bit Server VM (build 11.0.18+10-post-Debian-1deb11u1, mixed mode, sharing)\n<\/pre>\n\n\n\n<\/span>Step 3. Create Tomcat User<\/span><\/h2>\n\n\n\nTo create a Tomcat user, execute the following command:<\/p>\n\n\n\n
useradd -m -d \/opt\/tomcat -U -s \/bin\/false tomcat<\/pre>\n\n\n\n<\/span>Step 4. Install Tomcat<\/span><\/h2>\n\n\n\nBefore we can install Tomcat and make service files, we need to download it first:<\/p>\n\n\n\n
cd \/opt\n\nwget https:\/\/downloads.apache.org\/tomcat\/tomcat-10\/v10.1.6\/bin\/apache-tomcat-10.1.6.tar.gz \n\ntar -xzvf apache-tomcat-11.0.0-M3.tar.gz -C \/opt\/tomcat --strip-components=1\n\n<\/pre>\n\n\n\nSet the right permissions to the Tomcat directory:<\/p>\n\n\n\n
chown -R tomcat:tomcat \/opt\/tomcat\/<\/pre>\n\n\n\nAlso, set the execute permissions on scripts in the bin directory of the Tomcat installation:<\/p>\n\n\n\n
chmod -R u+x \/opt\/tomcat\/bin<\/pre>\n\n\n\n<\/span>Step 5. Create Tomcat Service File<\/span><\/h2>\n\n\n\nCreate a systemd file:<\/p>\n\n\n\n
nano \/etc\/systemd\/system\/tomcat.service<\/pre>\n\n\n\nPaste the following lines into it:<\/p>\n\n\n\n
[Unit]\nDescription=\"Tomcat Service\"\nAfter=network.target\n\n[Service]\nType=forking\nUser=tomcat\nGroup=tomcat\n\nEnvironment=\"JAVA_HOME=\/usr\/lib\/jvm\/java-1.11.0-openjdk-amd64\"\nEnvironment=\"JAVA_OPTS=-Djava.security.egd=file:\/\/\/dev\/urandom\"\nEnvironment=\"CATALINA_BASE=\/opt\/tomcat\"\nEnvironment=\"CATALINA_HOME=\/opt\/tomcat\"\nEnvironment=\"CATALINA_PID=\/opt\/tomcat\/temp\/tomcat.pid\"\nEnvironment=\"CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC\"\n\nExecStart=\/opt\/tomcat\/bin\/startup.sh\nExecStop=\/opt\/tomcat\/bin\/shutdown.sh\n\n[Install]\nWantedBy=multi-user.target\n<\/pre>\n\n\n\nSave the file, close it and start the service.<\/p>\n\n\n\n
sudo systemctl start tomcat<\/pre>\n\n\n\nTo check the status of the service, execute the following command:<\/p>\n\n\n\n
root@host:\/opt\/tomcat# systemctl status tomcat\n\u25cf tomcat.service - \"Tomcat Service\"\n Loaded: loaded (\/etc\/systemd\/system\/tomcat.service; enabled; vendor preset: enabled)\n Active: active (running) since Fri 2023-03-03 16:05:53 CST; 1min 19s ago\n Main PID: 11146 (java)\n Tasks: 29 (limit: 4675)\n Memory: 166.0M\n CPU: 8.531s\n CGroup: \/system.slice\/tomcat.service\n \u2514\u250011146 \/usr\/lib\/jvm\/java-1.11.0-openjdk-amd64\/bin\/java -Djava.util.logging.config.file=\/opt\/tomcat\/conf\/logging.properties -Djava.util.logging.manager=or>\n\nMar 03 16:05:53 host.test.vps systemd[1]: Starting Tomcat webs servlet container...\nMar 03 16:05:53 host.test.vps startup.sh[11139]: Tomcat started.\nMar 03 16:05:53 host.test.vps systemd[1]: Started Tomcat webs servlet container.\n<\/pre>\n\n\n\nNow, the service is up and running, and you can access Tomcat at http:\/\/YourServerIPAdrress:8080<\/b>.<\/p>\n\n\n\n<\/span>Step 6. Install Apache<\/span><\/h2>\n\n\n\nTo install the Apache Web server execute the following command:<\/p>\n\n\n\n
sudo apt-get install apache2 -y<\/pre>\n\n\n\nAfter installation, start and enable the service:<\/p>\n\n\n\n
sudo systemctl start apache2 && sudo systemctl enable apache2<\/pre>\n\n\n\nTo check the status of the Apache service, execute the following command:<\/p>\n\n\n\n
sudo systemctl status apache2<\/pre>\n\n\n\nYou should get the following output:<\/p>\n\n\n\n
root@host:\/opt\/tomcat# sudo systemctl status apache2\n\u25cf apache2.service - The Apache HTTP Server\n Loaded: loaded (\/lib\/systemd\/system\/apache2.service; enabled; vendor preset: enabled)\n Active: active (running) since Thu 2023-03-02 17:21:52 CST; 23h ago\n Docs: https:\/\/httpd.apache.org\/docs\/2.4\/\n Main PID: 420 (apache2)\n Tasks: 9 (limit: 4675)\n Memory: 27.9M\n CPU: 4.532s\n CGroup: \/system.slice\/apache2.service\n \u251c\u2500 420 \/usr\/sbin\/apache2 -k start\n \u251c\u2500 428 \/usr\/sbin\/apache2 -k start\n \u251c\u2500 429 \/usr\/sbin\/apache2 -k start\n \u251c\u2500 430 \/usr\/sbin\/apache2 -k start\n \u251c\u2500 431 \/usr\/sbin\/apache2 -k start\n \u251c\u2500 432 \/usr\/sbin\/apache2 -k start\n \u251c\u2500 598 \/usr\/sbin\/apache2 -k start\n \u251c\u25003916 \/usr\/sbin\/apache2 -k start\n \u2514\u25005728 \/usr\/sbin\/apache2 -k start\n\nMar 02 17:21:52 host.test.vps systemd[1]: Starting The Apache HTTP Server...\nMar 02 17:21:52 host.test.vps systemd[1]: Started The Apache HTTP Server.\n<\/pre>\n\n\n\n