Apache Tomcat 9 requires Java 8 or newer to be installed on the server. Java 8 packages are available in the default CentOS 7 repositories. Run the following command to install Java 8<\/p>\n
yum install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64<\/pre>\nThis will install Java 8 and all its dependencies. Once the installation is completed, you can check the installed version using the following command<\/p>\n
java -version<\/pre>\nYou should get the following output:<\/p>\n
openjdk version \"1.8.0_161\"\r\nOpenJDK Runtime Environment (build 1.8.0_161-b14)\r\nOpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)<\/pre>\n<\/span>3. Install Tomcat 9<\/strong><\/span><\/h2>\nGo to the official Apache Tomcat website and download the most recent version of the software to your server. At the moment the most recent release is version 9.0.7.<\/p>\n
wget http:\/\/ftp.wayne.edu\/apache\/tomcat\/tomcat-9\/v9.0.7\/bin\/apache-tomcat-9.0.7.zip<\/pre>\nDownload the sha512 checksum of the apache-tomcat-9.0.7.zip file<\/p>\n
wget https:\/\/www.apache.org\/dist\/tomcat\/tomcat-9\/v9.0.7\/bin\/apache-tomcat-9.0.7.zip.sha512<\/pre>\nRun the following command to generate the sha512 checksum of the apache-tomcat-9.0.7.zip file<\/p>\n
sha512sum apache-tomcat-9.0.7.zip\r\n72e042d28e4ac43310047bdb07a2b761656d4216b8702904e2878dcd6e1b659f92e322420f844f5e76109df9c70ac87ca6f4762cdf3a11100680cc2f9db9fdb5 apache-tomcat-9.0.7.zip<\/pre>\nAnd compare if the sha512 checksum is the same as the checksum the file apache-tomcat-9.0.7.zip.sha512 contains<\/p>\n
cat apache-tomcat-9.0.7.zip.sha512\r\n72e042d28e4ac43310047bdb07a2b761656d4216b8702904e2878dcd6e1b659f92e322420f844f5e76109df9c70ac87ca6f4762cdf3a11100680cc2f9db9fdb5 *apache-tomcat-9.0.7.zip<\/pre>\nIf the checksums are the same like in the output above, unpack the downloaded zip archive<\/p>\n
unzip apache-tomcat-9.0.7.zip -d \/opt<\/pre>\nThis will create a new directory named ‘apache-tomcat-9.0.7’. We will rename it to something simpler<\/p>\n
cd \/opt\r\nmv apache-tomcat-9.0.7\/ tomcat<\/pre>\nRun the following commands to set the CATALINA_HOME environment variable<\/p>\n
echo \"export CATALINA_HOME='\/opt\/tomcat\/'\" >> ~\/.bashrc\r\nsource ~\/.bashrc<\/pre>\nIt is not recommended to run Apache Tomcat as user root, so we will create a new system user which will run the Tomcat server<\/p>\n
useradd -r tomcat --shell \/bin\/false<\/pre>\nand change the ownership of all Tomcat files<\/p>\n
chown -R tomcat:tomcat \/opt\/tomcat\/<\/pre>\nCreate the a systemd file with the following content<\/p>\n
nano \/etc\/systemd\/system\/tomcat.service\r\n\r\n[Unit]\r\nDescription=Apache Tomcat 9\r\nAfter=syslog.target network.target\r\n\r\n[Service]\r\nUser=tomcat\r\nGroup=tomcat\r\nType=forking\r\nEnvironment=CATALINA_PID=\/opt\/tomcat\/tomcat.pid\r\nEnvironment=CATALINA_HOME=\/opt\/tomcat\r\nEnvironment=CATALINA_BASE=\/opt\/tomcat\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<\/pre>\nSave the file and run the following command to reload the systemd manager configuration<\/p>\n
systemctl daemon-reload<\/pre>\n