How to install and configure Apache Tomcat 7 on Mac OS

Apache is the most widely used web server software which is developed and maintained by the Apache Software Foundation. It is an open source software. Apache Tomcat is used to deploy Java Servlets and JSPs. So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies.

Install Apache Tomcat 7 server

1st Step: Go to http://tomcat.apache.org  ⇒ Download ⇒ Tomcat 7.0 ⇒ 7.0.{xx} (where {xx} denotes the latest release) ⇒ Binary distribution ⇒ Core.

Download the “tar.gz” package (e.g., “apache-tomcat-7.0.{xx}.tar.gz“). Next extract the tar.gz folder to the apache-tomcat-7.0.{xx} folder. Rename the folder to “tomcat” and copy the extracted folder.

Go the Applications folder, and paste the tomcat folder.

Configure the Apache Tomcat server

The following files in the /Applications/tomcat/conf folder will be edited in order to configure the server.

  • web.xml
  • context.xml
  • server.xml

Set the TCP Port number

The /Applications/tomcat/conf/server.xml file will be edited to change the port number which runs the apache tomcat server. The default port number the server runs is 8080. This can be run on the default port number if no other application is running on this port. If not you can change the port number by replacing 8080 as follows in the server.xml file (around Line 69).

<Connector port="9999" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

You may choose any number between 1024 and 65535.

Enabling Directory listing

In order to enable directory listing the /Applications/tomcat/conf/web.xml file needs to be edited as follows. Change the value “false” to “true” in the parameter value under listings (around line 103).

<servlet>
  <servlet-name>default</servlet-name>
  <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
  <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
  </init-param>
  <init-param>
    <param-name>listings</param-name>
    <param-value>true</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

Enabling Automatic Reload

Change the /Applications/tomcat/conf/context.xml file (around line 19) as follows. Insert the reloadable=”true” statement inside the context tag.

<Context reloadable="true">
   ......
   ......
</Context>

The configuration of the Apache Tomcat server is complete.

Start the Apache Tomcat server

To start the Apache Tomcat server, open a new terminal and change the working directory as follows.

cd /Applications/tomcat/bin

Next type the following command in order to start the server.

sudo ./catalina.sh run

If you receive an error saying “command not found” or “cannot start server”, do the following to change the permissions of the catalina.sh file. This should have execute permissions for the server to start.

sudo chmod +x startup.sh
sudo chmod +x catalina.sh

Next run the following command again to start the server.

sudo ./catalina.sh run

Now the server should start correctly and the terminal should display a message saying “Tomcat started”.

 

Thank You!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: