Skip to content

4. Installation: Deploying to Tomcat

Glen Mazza edited this page Jan 1, 2020 · 3 revisions

Deploying TightBlog to the Tomcat servlet container involves creating a TightBlog configuration file, adding some jars to Tomcat and then deploying the TightBlog WAR file. Apache Tomcat needs to be installed and configured before TightBlog, and it's assumed you're aware of how to deploy a WAR archive on Tomcat. See the Tomcat documentation for more information if needed.

Create TightBlog Configuration File

Normally, just a application-tbcustom.properties file, overriding any default values desired from the distribution's application.properties file (which specifies the name of the custom file given above) is sufficient. Rarely if ever needed, but some configuration can be done by overriding Spring configuration settings with a application-tbcustom.xml file. For Tomcat, these files can simply be placed at the top-level apache-tomcat-X.Y.Z\lib folder and will be detected and used by the TightBlog war.

The below provides a sample application-custom.properties file. Good to review the application.properties file for additional fields you may wish to override, however, many (especially lesser-overridden) properties are defined within individual Java files with their defaults (for example the overridable properties in the constructor for the CommentSpamChecker.) Note you'll just need one of the three blocks shown below for database access:

installation.type=auto

mediafiles.storage.dir=/home/gmazza/tbfiles/mediafiles

search.enabled=false
#search.index.dir=/home/gmazza/tbfiles/searchindex

# Requiring Google Authentication (MFA) for logins, enabled is default
#mfa.enabled=false

#MySQL sample
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/tightblogdb?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8
spring.datasource.username=scott
spring.datasource.password=tiger

#PostgreSQL sample
#spring.datasource.driverClassName=org.postgresql.Driver
#spring.datasource.url=jdbc:postgresql://localhost:5432/pgsqltightblog
#spring.datasource.username=scott
#spring.datasource.password=tiger

#Derby sample
#spring.datasource.driverClassName=org.apache.derby.jdbc.ClientDriver
#spring.datasource.url=jdbc:derby://localhost:1527//home/gmazza/work/tightblog-dbs/MYTIGHTBLOGDB
#Derby doesn't use authentication, any values below would be fine.
#spring.datasource.username=app
#spring.datasource.password=app

# EclipseLink debugging (if needed for troubleshooting)
# eclipselink.logging.file=/home/gmazza/work/apache-tomcat-x.y.z/logs/eclipselink-tomcat.log
# eclipselink.logging.level=FINE

# Mail config sample for a gmail account, uncomment config once filled in with real data.
#If using Gmail, only the following two properties need be defined (rest configured in parent tightblog.properties)
#spring.mail.username=blah.blah@gmail.com
#spring.mail.password=blahspassword
#If not using Gmail, configure these values additionally
#spring.mail.host=smtp.gmail.com
#spring.mail.port=587
#spring.mail.properties.mail.smtp.auth = true
#spring.mail.properties.mail.smtp.starttls.enable = true
#spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
#spring.mail.properties.mail.smtp.connectiontimeout = 60000
#spring.mail.properties.mail.smtp.timeout = 60000

Notes:

  • TightBlog uses EclipseLink by default as its JPA implementation.
    By default, EclipseLink's connection pool uses a minimum and maximum of 32 connections. This can be customized if desired, by adding eclipselink.connection-pool.* properties to the above configuration.

  • The above installation.type=auto results in TightBlog conveniently creating (and on subsequent upgrades, updating) the database tables for you on initial startup, overriding the default of "manual". If you wish to create the tables yourself using the script for your database in src/main/resources/dbscripts, just remove this option.

  • The Java mail properties are explained in this Baeldung article. Note the email account defined above will appear in the “From:” line of notification email messages sent to blog owners (and, if they select “Notify me of further comments”, blog commenters) so take care not to use a email account you wish to keep private.

Add JDBC Driver JARs to Tomcat

  • Normally mysql-connnector-java-xxx-bin.jar if you're using MySQL, postgresql-xxxx.jar for PostgreSQL, or derbyclient.jar for Derby. Once they are in your classpath, TightBlog's database subsystem will be able to find and use them. Download them from your database vendor/provider.

Tomcat: Set URI Encoding

TightBlog supports internationalization (I18N), but on Tomcat some additional configuration is necessary. You must ensure that Tomcat's URI encoding is set to UTF-8. You can do this by editing the Tomcat configuration file conf/server.xml and adding URIEncoding=”UTF-8” to each connector element, as shown below:

   <Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
      enableLookups="false" redirectPort="8443" debug="0" acceptCount="100"
      connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8" />

Make sure you do this for every connector through which you use TightBlog. For example, if you use the AJP connector or HTTPS connector you need to add the URIEncoding="UTF-8" attribute to those connectors as well.

Tomcat: Setup SSL

TightBlog's WAR is configured to use SSL on every page by default, make sure you follow the Tomcat Guide to activate SSL on the container.

Tomcat: Deploy TightBlog

Refer to the Tomcat documentation for information on the various ways to deploy a WAR. By renaming the TightBlog WAR to tightblog.war and placing it in the webapps directory of a running Tomcat instance (one method), you should be able to access TightBlog at https://mydomain:port/tightblog. Or, rename it to ROOT.war to access the application from https://mydomain:port/` alone. Another way to deploy is to use the Tomcat Manager application.

Start TightBlog!

Finally, navigate to https://localhost:8443/tightblog to complete the installation: create the database tables, set up the admin account, set server runtime config options, and create your first blog.