You know, Tomcat is a popular, free and open-source Java web server developed by the Apache Software Foundation. Developers use Tomcat to run web applications built on Java EE platform.

In this article, I’d like to guide you how to setup Apache Tomcat running on Mac operating system (macOS).

Why Tomcat version 8.5???

The branch 8.5 requires Java 7 or later, and supports the following Java EE technologies: Servlet 3.1, JSP 2.3, EL 3.0, WebSocket 1.1, Authentication (JASPIC) 1.1,… that means you should use Tomcat 8.5 for running Java web applications using Java 7 or later and Servlet 3.1 or older.

NOTE: You must have Java Development Kit (JDK) installed on your macOS in order to run Apache Tomcat server. If not, follow this article for JDK setup on macOS.

 

1. Download binary distribution of Tomcat 8.5

There’s no Tomcat installer for macOS, so you need to download an archive file (zip or tar.gz) and install manually. Click this link to head over to the official download page of Tomcat 8.5. Look at the Binary Distributions section:

download Tomcat 8.5 distribution

Click the “zip” link (1) to download. You’ll get the file apache-tomcat-8.5.x.zip downloaded on your computer.



NOTE: You may choose another mirror site for download, so checking SHA512 of the downloaded file is recommended.


2. Install Tomcat 8.5 on macOS

It’s strongly recommended verify integrity of the downloaded zip file to make sure it is not tampered by hackers. Open a new Terminal window, change the current directory to where the zip file is stored. Then type the following command:

shasum -a 512 apache-tomcat-8.5.95.zip

You should get the following SHA512 checksum of the file:

checksum tomcat 8 zip file

Compare this hash value against the one published on the download page (click the “sha512” link (2) next to download link). If both are identical, that means the download file is safe to use.

Then extract the zip file into a specific folder, e.g. user home directory, using the following command:

tar -xf apache-tomcat-8.5.95.zip -C $HOME

Then perform some cd and ls commands to see the files extracted:

listing tomcat dir

Go to bin directory and you see some shell script files (.sh) which can be used to control the server (start and stop). Here I name the primary ones:

  • catalina.sh: the general purpose script. Used this to check version, start, stop, debug the server…
  • version.sh: a shortcut to see version of the server, OS, JVM
  • startup.sh: a shortcut to start the server
  • shutdown.sh: a shortcut to stop the server
Next, let’s see how to start and stop Tomcat using shell scripts.


3. Start Tomcat server

Make sure that bin is the current directory, type the following command in terminal to start Apache Tomcat server:

sh catalina.sh start

This will run Tomcat in a separate thread other than the Terminal window thread. You should see the following output:

start tomcat command

That means Tomcat started, is listening on port 8080 (default) and is ready to receive requests. Open your web browser, and enter http://localhost:8080 into the address bar, you’ll see the server’s home page as shown below:

testing tomcat localhost

This web interface allows you to deploy, manage, monitor Java web applications running on the server. Learn more: How to deploy a Java web application on Tomcat.

NOTES:

You can use the following commands in Terminal to start Tomcat:

  • ./catalina.sh start
  • sh startup.sh
  • ./startup.sh
If you get permission denied error when running these scripts, you need to grant execute permission to the current user using the following command:

chmod u+x startup.sh


4. Stop Tomcat server

To shut down the running server, you can run the following command:

sh catalina.sh stop

Tomcat will be stopped, as shown below:

stop tomcat command

NOTES:

You can use the following commands in Terminal to start Tomcat:

  • ./catalina.sh stop
  • sh shutdown.sh
  • ./shutdown.sh
If you get permission denied error when running these scripts, you need to grant execute permission to the current user using the following command:

chmod u+x shutdown.sh


5. Add a user to access Tomcat Web Application Manager

The Tomcat Web Application Manager allows us to deploy and manage Java web applications. It can be accessed by clicking the Manager App button on the localhost page. You will be asked for username and password:

sign in manager app

But we have not configured any users yet, right? So click Cancel button. You will see 401 Unauthorized error page as shown below:

unauthorized error

Read this page and you can see it instructs how to add a user in order to get access to the Tomcat web application manager. Change the current directory to conf and edit the tomcat-users.xml file using the following commands:

cd ../conf

open -a TextEdit tomcat-users.xml

open tomcat users xml file

This will open the TextEdit program to edit the file. Remove the XML comments around <user> tags and keep only one username admin with desired password, as shown below:

edit tomcat users xml file

Close the program to save the change. Stop and start the server, then you will be able to access the Tomcat Web Application Manager using the specified username and password:

tomcat web application manager

You can use this interface to deploy and manage Java applications running on the server. Check this article to learn about deployment of Java applications on Tomcat.

Watch the following video to see the steps of setup Tomcat 8 on macOS in action:

 

Other Tomcat Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment