If Tomcat-based Java applications on your cPanel server are running slowly, throwing OutOfMemoryError, or crashing under load, the default JVM heap size (100 MB min / 200 MB max) is likely too small. This guide shows how to increase the Tomcat heap size on cPanel servers.
Step 1 — Edit the Tomcat Options File
# Create or edit the Tomcat options file
vi /var/cpanel/tomcat.options
If the file doesn’t exist, create it. Add the following lines, adjusting values to suit your server’s available RAM:
# Minimum heap size (initial allocation)
-Xms512M
# Maximum heap size (upper limit)
-Xmx1024M
As a rule of thumb, set -Xmx to no more than 50–60% of available server RAM to leave room for the OS and other services. Use free -h to check available memory.
Step 2 — Restart the Tomcat Service
# cPanel servers typically run one of these Tomcat versions:
# Tomcat 8.5 (EasyApache 4)
/scripts/restartsrv_tomcat
# Or restart via service name directly:
systemctl restart ea-tomcat85
# Older servers (Tomcat 7):
/etc/init.d/easy-tomcat7 restart
Step 3 — Verify the New Heap Size
# Check the Tomcat process to confirm new JVM flags are applied
ps aux | grep tomcat | grep -o '-Xm[sx][0-9]*[MmGg]'
# Or check via the Tomcat manager (if enabled):
# http://yourdomain.com:8080/manager/status
Recommended Heap Sizes by Server RAM
| Server RAM | -Xms (min) | -Xmx (max) |
|---|---|---|
| 2 GB | 256M | 768M |
| 4 GB | 512M | 1536M |
| 8 GB | 512M | 3G |
| 16 GB | 1G | 6G |
Troubleshooting: Tomcat Still Out of Memory
- Check GC overhead: If GC is consuming >90% of CPU, the heap may still be too small — increase
-Xmxfurther - PermGen / Metaspace: On Java 8+, add
-XX:MaxMetaspaceSize=256Mto the options file for class metadata - Memory leaks: Use
jmap -heap <tomcat_pid>to inspect heap usage and identify leaking applications
