APR for Apache Tomcat on Ubuntu

Ubuntu 20.04 focal fossaUbuntu 22.04 jammy jellyfish
Tomcat 8
Tomcat 9
Tomcat 10
Reason: configure: error: Your version
of OpenSSL is not compatible
with this version of tcnative
Compatibility table for this guide. Let me know if you find otherwise.
apt update
apt install gcc make libapr1-dev libssl-dev
mkdir -p /system/compile
cd /system/compile

Folder to put the APR lib is /system/server/apr (you can specify any folder you like).
This example is using Tomcat 10 on Ubuntu 22.

tar -zxvf /system/server/tomcat/bin/tomcat-native.tar.gz
cd tomcat-native-2.0.5-src/native
./configure --prefix /system/server/apr --with-java-home=/system/jdk
make
make install

At this point you should see files in /system/server/apr. Now run Tomcat without APR.

export JAVA_HOME=/system/jdk
/system/server/tomcat/bin/startup.sh

Then look at/system/server/tomcat/logs/catalina.out. You probably see this. Which is expected.

08-Oct-2023 05:30:35.083 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib]

Shutdown the server first.

/system/server/tomcat/bin/shutdown.sh

Now run using CATALINA_OPTS, telling Tomcat where the APR library is installed.

export CATALINA_OPTS="-Djava.library.path=/system/server/apr/lib"
/system/server/tomcat/bin/startup.sh

Check that our CATALINA_OPTS is being read. After startup.sh you should see this.

Using CATALINA_BASE:   /system/server/tomcat
Using CATALINA_HOME:   /system/server/tomcat
Using CATALINA_TMPDIR: /system/server/tomcat/temp
Using JRE_HOME:        /system/jdk
Using CLASSPATH:       /system/server/tomcat/bin/bootstrap.jar:/system/server/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   -Djava.library.path=/system/server/apr/lib
Tomcat started.

And you should be able to see /system/server/apr/lib in ps fauxgww.

# ps fauxgww
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root        6372  3.5  9.8 2800064 95232 pts/1   Sl   05:33   0:04 /system/jdk/bin/java -Djava.util.logging.config.file=/system/server/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED -Djava.library.path=/system/server/apr/lib -classpath /system/server/tomcat/bin/bootstrap.jar:/system/server/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/system/server/tomcat -Dcatalina.home=/system/server/tomcat -Djava.io.tmpdir=/system/server/tomcat/temp org.apache.catalina.startup.Bootstrap start

Do a tail on catalina.out again. You should expect to see this.

08-Oct-2023 05:33:42.117 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [2.0.5] using APR version [1.7.0].
08-Oct-2023 05:33:42.123 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 3.0.2 15 Mar 2022]

Congratulations, you have now enabled APR on your Tomcat.

Leave a Reply

Your email address will not be published. Required fields are marked *