Apache Tomcat

    Quick reference card

      Cloud Servers Virtual Machines Native Installers
    Configuration file(s) /opt/bitnami/apache-tomcat/conf/server.xml /opt/bitnami/apache-tomcat/conf/server.xml install_dir/apache-tomcat/conf/server.xml
    Log file(s) /opt/bitnami/apache-tomcat/logs/* /opt/bitnami/apache-tomcat/logs/* install_dir/apache-tomcat/logs/*
    Default port 8080, 8443 (SSL) 8080, 8443 (SSL) 8080, 8443 (SSL)
    AJP port 8009 8009 8009
    System user account tomcat tomcat tomcat
    Service control sudo /opt/bitnami/ctlscript.sh start|stop|restart tomcat sudo /opt/bitnami/ctlscript.sh start|stop|restart tomcat install_dir/ctlscript.sh start|stop|restart tomcat

    How to start/stop the Apache Tomcat server?

    Cloud Server

    Each Bitnami stack includes a control script that lets you easily stop, start and restart servers.

    The script is located at /opt/bitnami/ctlscript.sh. Call it without any arguments to restart all services:

    $ sudo /opt/bitnami/ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument:

    $ sudo /opt/bitnami/ctlscript.sh restart tomcat
    

    Virtual Machine

    Each Bitnami stack includes a control script that lets you easily stop, start and restart servers.

    The script is located at /opt/bitnami/ctlscript.sh. Call it without any arguments to restart all services:

    $ sudo /opt/bitnami/ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument:

    $ sudo /opt/bitnami/ctlscript.sh restart tomcat
    

    Native Installer

    You can use either the graphical manager tool or the command-line tool to start and stop the servers.

    Graphical Tool

    Bitnami stacks include a graphical tool to manage the servers easily (native installers only). Using this tool, you can start, stop and restart the servers and check the log files.

    On Windows:

    • Double-click the "manager-windows.exe" file in your installation directory.  
    • You can also start the Manager tool using the Start Menu path Start -> Program Files -> Bitnami Stack -> Manager.

    On Linux and Mac OS X:

    • Double-click the "manager-osx" or "manager-linux-*" tool in your installation directory. 
    Command-line Tool

    Each Bitnami stack includes a control script that lets you easily stop, start and restart servers.

    The control script is only available for Linux and Mac OS X native installers. The script is located in your installation directory and named ctlscript.sh. Call it without any arguments to restart all services.

    On Linux:
    Call the control script with the ‘start’ argument to start all servers. For example:

    $ cd /home/USER/tomcatstack-VERSION
    $ ./ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument:

    $ cd /home/USER/tomcatstack-VERSION
    $ ./ctlscript.sh restart jboss
    

    On Mac OS X:
    Call the control script with the ‘start’ argument to start all servers. For example:

    $ cd /Applications/tomcatstack-VERSION
    $ ./ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ cd /Applications/tomcatstack-VERSION
    $ ./ctlscript.sh restart mysql
    

    If you find the following error you should delete the catalina.pid file and start the server again.

    PID file (installdir/apache-tomcat/temp/catalina.pid) found. Is Tomcat still running? Start aborted.
    

    Tabs end

    How to configure the Apache Tomcat server?

    Cloud Server

    The main Apache Tomcat configuration file is at /opt/bitnami/apache-tomcat/conf/server.xml.

    Once Apache Tomcat starts, it will create several log files in the /opt/bitnami/apache-tomcat/logs directory. The main log file is the catalina.out file where you can find error messages.

    Virtual Machine

    The main Apache Tomcat configuration file is at /opt/bitnami/apache-tomcat/conf/server.xml.

    Once Apache Tomcat starts, it will create several log files in the /opt/bitnami/apache-tomcat/logs directory. The main log file is the catalina.out file where you can find error messages.

    Native Installer

    The main Apache Tomcat configuration file is at installdir/apache-tomcat/conf/server.xml.

    Once Apache Tomcat starts, it will create several log files in the installdir/apache-tomcat/logs directory. The main log file is the catalina.out file where you can find error messages.

    How to configure the Java memory settings for Tomcat?

    The Java Virtual Machine (JVM) determines the default settings for your Java application:

    JAVA_OPTS="-XX:MaxPermSize=512m -Xms256m -Xmx512m"
    

    Cloud Server

    You can increase these Java settings if it is necessary for your application. The settings are in the /opt/bitnami/java/bitnami/setenv.sh file. Here is an example of how to change the memory settings:

    export JAVA_OPTS="-XX:MaxPermSize=256M -Xms256M -Xmx768M $JAVA_OPTS"
    
    IMPORTANT: This file is a symlink to a configuration file that changes depending on the instance type that you are currently using. The symlink will be automtically changed when you resize your server.

    Virtual Machine

    You can increase these Java settings if it is necessary for your application. The settings are in the /opt/bitnami/java/bitnami/setenv.sh file. Here is an example of how to change the memory settings:

    export JAVA_OPTS="-XX:MaxPermSize=256M -Xms256M -Xmx768M $JAVA_OPTS"
    

    Native Installer

    You can increase these Java settings if it is necessary for your application. On Linux and Mac OS X installers, the settings are in the /installdir/apache-tomcat/bin/setenv.sh file and on Windows installers, the settings are in the /installdir/apache-tomcat/bin/setenv.bat file. Here is an example of how to change the memory settings:

    export JAVA_OPTS="-XX:MaxPermSize=256M -Xms256M -Xmx768M $JAVA_OPTS"
    

    On Windows. remember to reinstall the services after modifying the file, as shown below:

    > cd installdir
    > serviceinstall.bat UNINSTALL
    > serviceinstall.bat INSTALL
    

    How to change the Apache Tomcat port?

    With the default configuration, Apache Tomcat will listen for requests on port 8080. To use a different port, edit the server.xml file and modify the value specified in the Port directive. For Linux and OS X native installers only, install the Stack as the root user to use a port number 1024.

    <Connector port="8080" URIEncoding="UTF-8" protocol="HTTP/1.1"                     
    connectionTimeout="20000" redirectPort="8443" />
    

    Then, restart the Apache Tomcat server for the changes to take effect.

    How to publish my web page?

    Cloud Server

    To serve Web pages with Apache Tomcat, simply copy your files to the default document root directory at /opt/bitnami/apache-tomcat/webapps/ROOT.

    Virtual Machine

    To serve Web pages with Apache Tomcat, simply copy your files to the default document root directory at /opt/bitnami/apache-tomcat/webapps/ROOT.

    Native Installer

    To serve Web pages with Apache Tomcat, simply copy your files to the default document root directory at installdir/apache-tomcat/webapps/ROOT.

    Tabs end

    For further details check How to deploy Java Applications in Tomcat

    How to enable SSL to access through https?

    You can configure Apache Tomcat to enable SSL access to applications using HTTPS. It is necessary to configure Tomcat with the location of the Apache SSL certificate, as described below. If you do not have an SSL certificate, refer to the next section.

    Cloud Server

    1. Check that the certificate file is present at /opt/bitnami/apache-tomcat/conf/ssl/tomcat.cert.pem and the certificate key file is present at /opt/bitnami/apache-tomcat/conf/ssl/tomcat.key.pem.

    2. Uncomment the following line in the /opt/bitnami/apache-tomcat/conf/server.xml file:

    <Connector port="8443"
                   protocol="HTTP/1.1" SSLEnabled="true"
                   maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" disableUploadTimeout="true"
                   acceptCount="100" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS"
                   keystoreFile="conf/myKeystore"
                   keystorePass="your_password"
                   SSLCertificateFile="/opt/bitnami/apache-tomcat/conf/ssl/tomcat.cert.pem"
                   SSLCertificateKeyFile="/opt/bitnami/apache-tomcat/conf/ssl/tomcat.key.pem"/>
    

    3. Restart the Apache Tomcat server

    You should now be able to access your Web applications over HTTPS by browsing to https://[server-IP-address]:8443.

    Virtual Machine

    1. Check that the certificate file is present at /opt/bitnami/apache-tomcat/conf/ssl/tomcat.cert.pem and the certificate key file is present at /opt/bitnami/apache-tomcat/conf/ssl/tomcat.key.pem.

    2. Uncomment the following line in the /opt/bitnami/apache-tomcat/conf/server.xml file:

    <Connector port="8443"
                   protocol="HTTP/1.1" SSLEnabled="true"
                   maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" disableUploadTimeout="true"
                   acceptCount="100" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS"
                   keystoreFile="conf/myKeystore"
                   keystorePass="your_password"
                   SSLCertificateFile="/opt/bitnami/apache-tomcat/conf/ssl/tomcat.cert.pem"
                   SSLCertificateKeyFile="/opt/bitnami/apache-tomcat/conf/ssl/tomcat.key.pem"/>
    

    3. Restart the Apache Tomcat server

    You should now be able to access your Web applications over HTTPS by browsing to https://[server-IP-address]:8443.

    Native Installer

    1. Check that the certificate file is present at installdir/apache-tomcat/conf/ssl/tomcat.cert.pem and the certificate key file is present at installdir/apache-tomcat/conf/ssl/tomcat.key.pem.

    2. Uncomment the following line in the installdir/apache-tomcat/conf/server.xml file:

    <Connector port="8443"
                   protocol="HTTP/1.1" SSLEnabled="true"
                   maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" disableUploadTimeout="true"
                   acceptCount="100" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS"
                   keystoreFile="conf/myKeystore"
                   keystorePass="your_password"
                   SSLCertificateFile="installdir/apache-tomcat/conf/ssl/tomcat.cert.pem"
                   SSLCertificateKeyFile="installdir/apache-tomcat/conf/ssl/tomcat.key.pem"/>
    

    3. Restart the Apache Tomcat server

    You should now be able to access your Web applications over HTTPS by browsing to https://localhost:8443.

    How to create a SSL certificate for Apache Tomcat?

    A detailed guide is available in the official Apache Tomcat documentation at http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html

    How to connect Apache server with Tomcat?

    Bitnami Stacks include the Apache Web server. There are different ways to connect these two servers. One of this is connecting through the AJP protocol.

    The AJP Connector element represents a Connector component that communicates with a web connector via the AJP protocol. This is used to invisibly integrate JBoss into an Apache installation and have Apache handle the static content of the web application and/or to utilize Apache's SSL processing.

    Cloud Server

    To make them work together, enable the mod_proxy.so and mod_proxy_ajp.so modules in /opt/bitnami/apache2/conf/httpd.conf. Then, add the following lines to the file:

    <Location /your_application_url>
      ProxyPass ajp://localhost:8009/your_application_url
    </Location>
    

    If you connect your application through AJP, you will probably want to disable the Tomcat HTTP port. The Bitnami Tomcat and JBoss Stacks have the HTTP server disabled by default. To modify this configuration, uncomment the HTTP section in the /opt/bitnami/apache-tomcat/conf/server.xml file.

    Virtual Machine

    To make them work together, enable the mod_proxy.so and mod_proxy_ajp.so modules in /opt/bitnami/apache2/conf/httpd.conf. Then, add the following lines to the file:

    <Location /your_application_url>
      ProxyPass ajp://localhost:8009/your_application_url
    </Location>
    

    If you connect your application through AJP, you will probably want to disable the Tomcat HTTP port. The Bitnami Tomcat and JBoss Stacks have the HTTP server disabled by default. To modify this configuration, uncomment the HTTP section in the /opt/bitnami/apache-tomcat/conf/server.xml file.

    Native Installer

    To make them work together, enable the mod_proxy.so and mod_proxy_ajp.so modules in installdir/apache2/conf/httpd.conf. Then, add the following lines to the file:

    <Location /your_application_url>
      ProxyPass ajp://localhost:8009/your_application_url
    </Location>
    

    If you connect your application through AJP, you will probably want to disable the Tomcat HTTP port. The Bitnami Tomcat and JBoss Stacks have the HTTP server disabled by default. To modify this configuration, uncomment the HTTP section in the installdir/apache-tomcat/conf/server.xml file.

    How to increase the upload size limit in Tomcat?

    Modify the <max-file-size> and <max-request-size> values in the application's web.xml configuration file (for example, in the webapps/manager/WEB-INF/web.xml file).

    <max-file-size>83886080</max-file-size>
    <max-request-size>83886080</max-request-size>

    Remember to restart your Tomcat server for the changes to take effect.

    How to use an independent Java installation instead of the bundled one?

    Cloud Server

    Change the JAVA_HOME variable in the /opt/bitnami/apache-tomcat/bin/setenv.sh file and the JRE_HOME variable in the /opt/bitnami/apache-tomcat/scripts/ctl.sh to point to your custom Java installation. Then, restart the Tomcat service:

    $ sudo /opt/bitnami/ctlscript.sh restart tomcat
    

    Virtual Machine

    Change the JAVA_HOME variable in the /opt/bitnami/apache-tomcat/bin/setenv.sh file and the JRE_HOME variable in the /opt/bitnami/apache-tomcat/scripts/ctl.sh to point to your custom Java installation. Then, restart the Tomcat service:

    $ sudo /opt/bitnami/ctlscript.sh restart tomcat
    

    Native Installer

    On Windows:

    Uninstall the Apache Tomcat service, edit the JAVA_HOME variable and then reinstall the Apache Tomcat service. For example:

    cd installdir\apache-tomcat\scripts
    serviceinstall.bat UNINSTALL
    
     
    Now change the JAVA_HOME variable in the installdir/apache-tomcat/bin/setenv.bat file to point to your custom Java installation. Then, reinstall the service as shown below:
    cd installdir\apache-tomcat\scripts
    serviceinstall.bat INSTALL
    

    On Linux and Mac OS X:

    Change the JAVA_HOME variable in the installdir/apache-tomcat/bin/setenv.sh file and the JRE_HOME variable in the installdir/apache-tomcat/scripts/ctl.sh to point to your custom Java installation. Then, restart the Tomcat service:

    $ installdir/ctlscript.sh restart tomcat
    

    Comments

    You must login to post a comment.

    Attach file

    Attachments