Apache Tomcat is an open-source implementation of the Java Servlet, JavaServer Pages, and Java Expression Language technologies. This guide will walk you through installing Apache Tomcat on Ubuntu 12.04.

1. Install Java Development Kit (JDK)

Apache Tomcat requires Java to run. First, ensure that the Java Development Kit (JDK) is installed:

sudo apt-get update
sudo apt-get install default-jdk

2. Download Apache Tomcat

Download the latest version of Apache Tomcat from the official website. At the time of writing, version 7 is commonly used for Ubuntu 12.04:

wget https://downloads.apache.org/tomcat/tomcat-7/v7.0.109/bin/apache-tomcat-7.0.109.tar.gz

3. Extract the Tomcat Archive

Extract the downloaded archive to the /opt directory:

sudo tar xzf apache-tomcat-7.0.109.tar.gz -C /opt

4. Create a Symlink to the Tomcat Directory

Create a symbolic link for easier access:

sudo ln -s /opt/apache-tomcat-7.0.109 /opt/tomcat

5. Set Up Environment Variables

Set up environment variables for Tomcat. Edit the /etc/profile file:

sudo nano /etc/profile

Add the following lines to the end of the file:


export CATALINA_HOME="/opt/tomcat"
export CATALINA_BASE="/opt/tomcat"
export PATH="$PATH:$CATALINA_HOME/bin"
    

Save and close the file (press Ctrl+X, then Y, and Enter).

Apply the changes:

source /etc/profile

6. Configure Tomcat

Set the correct permissions for Tomcat:

sudo chown -R $USER:$USER /opt/tomcat
sudo chmod +x /opt/tomcat/bin/*.sh

7. Start Tomcat

Start Tomcat using the startup script:

cd /opt/tomcat/bin
./startup.sh

8. Verify Tomcat Installation

Open a web browser and navigate to http://localhost:8080. You should see the Tomcat welcome page, indicating that Tomcat is running.

9. Configure Tomcat to Start on Boot (Optional)

Create a systemd service file for Tomcat:

sudo nano /etc/systemd/system/tomcat.service

Add the following configuration:


[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking
User=your_user
Group=your_user
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='JAVA_OPTS=-Xms512M -Xmx1024M'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target
    

Replace your_user with your actual username. Save and close the file.

Reload the systemd configuration and start Tomcat:

sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl enable tomcat

10. Troubleshooting

If Tomcat does not start or you encounter issues, check the Tomcat logs located in the /opt/tomcat/logs directory for errors.

11. Further Configuration

Refer to the Tomcat documentation for further configuration options and optimizations.

Was this answer helpful? 0 Users Found This Useful (0 Votes)