Applicable to:
- Plesk for Linux
Question
How to set up .JSP (JavaServer Pages) to run from domain's DocumentRoot directory with the following requirements:
- The JSP application should be accessible by the root domain link (via the http://example.com/ address).
- The application must be able to save its data.
- The application must have configurable settings and code.
Answer
Warning: Tomcat is no longer provided starting from Plesk Onyx 17.8
Ensure that Tomcat Java is installed and running in Tools & Settings > Services Management.
A typical application in a .war format, uploaded via the Plesk interface in Domains > example.com > Java Applications, may meet all the requirements above.
The .war
application will not be unpacked to persistent storage, and therefore, its files will not be alterable. However, some non-Plesk integrated solution or database may be used to save the application's data and settings (even multimedia files).
To modify the application code, it will be necessary to reinstall the package completely (remove the old .war file and upload the new one). During the maintenance procedure, the application will be unavailable.
Note: This method has the following weak points:
It is required to have administrative access to configure context files and provide necessary permissions to the application files.
The Tomcat user must be added to the 'psaserv' group, and this may cause some security issues. In the case of backing up Plesk sites, the custom Tomcat configuration will not be saved. It will be necessary to restore the configuration manually (including the tomcat user configuration).
-
Connect to the server via SSH.
-
Check the name of installed Tomcat service (e.g. Tomcat, Tomcat7 etc.) and ensure that it is running.
For SysV or Upstart-based OSes:
# service --status-all | grep tomcat
tomcat6 (pid 7080) is running...For SystemD-based OSes:
# systemctl | grep tomcat
tomcat.service loaded active running Apache Tomcat Web Application Container -
Check the name of Tomcat user, using the name of the service from the previous step:
# grep tomcat6 /etc/passwd
tomcat:x:91:91:Apache Tomcat:/usr/share/tomcat6:/sbin/nologinFurther in the instruction Tomcat user will be named "tomcat", and Tomcat service - "tomcat6".
-
Add the Tomcat system account to 'psaserv' group to allow the user to access the httpdocs directories:
# usermod -a -G psaserv tomcat
Check that user was successfully added using:
# id tomcat
uid=91(tomcat) gid=91(tomcat) groups=91(tomcat),502(psaserv) -
Rename
.war
file to.zip
, or create a ZIP archive containing the application.
Using Plesk file manager upload application archive to httpdocs folder and unpack it. -
Set the following ownership and permissions (use the username from step 3):
# chgrp -R psaserv /var/www/vhosts/example.com/httpdocs/
# chmod 0750 /var/www/vhosts/example.com/httpdocs/
# find /var/www/vhosts/example.com/httpdocs/ -type f -name "*.jsp" -exec chown tomcat {} \;
# find /var/www/vhosts/example.com/httpdocs/ -type f -name "*.jsp" -exec chmod 664 {} \;Note: if writing access to application folder is required for Plesk file manager or other scripts from the subscription, set the following permissions as well:
# find /var/www/vhosts/example.com/httpdocs/ -type f -exec chmod 664 {} \;
# find /var/www/vhosts/example.com/httpdocs/ -type d -exec chmod 775 {} \; -
Forward all requests with the http://example.com/ URL to Tomcat: go to Plesk > domains > example.com > Apache & Nginx Settings and paste the following into Additional directives for HTTP section:
CONFIG_TEXT: <IfModule mod_jk.c>
JkMount /* ajp13
</IfModule> -
Create virtual host base options in
/etc/**tomcat6**/server.xml
, paste the following into it right after one of the</Host>
lines in the end of the file:CONFIG_TEXT: <Host name="example.com" appBase="/var/www/vhosts/example.com/httpdocs" />
<Context crossContext="false" reloadable="false" useNaming="true" debug="0" privileged="true" docBase="/var/www/vhosts/example.com/httpdocs" cookies="true" path="" cachingAllowed="true" />Note: to make the website accessible using the URL http://example.com/ path parameter value should be empty.
For example:
# tail -n5 /etc/tomcat6/server.xml
<Host name="example.com" appBase="/var/www/vhosts/example.com/httpdocs" />
<Context crossContext="false" reloadable="false" useNaming="true" debug="0" privileged="true" docBase="/var/www/vhosts/example.com/httpdocs" cookies="true" path="" cachingAllowed="true" />
</Engine>
</Service>
</Server> -
Restart Tomcat service:
# service tomcat6 restart
In case of any issues, check log messages of Tomcat located in
/var/log/tomcat/catalina*.log
. -
Add
index.jsp
to Index files in Domains > example.com > Apache & Nginx Settings:
Comments
2 comments
Hi,
I follow your tutorial but not working for me...
This is my information system:
Product version: Plesk Onyx 17.5.3 Update #35
Update date: 2017/12/27 13:16
Build date: 2017/03/17 16:00
OS version: CentOS 7.4.1708
Revision: 55d1b49a272f44666e1920eca8b6e4da449a38cd
Architecture: 64-bit
Wrapper version: 1.2
--------
When put the java app on javaApp folder and check by url not load the page. I have 404 and blank page...
Please help me!
Thanks in advance.
@Pol Alegria
Hello,
It is required to add index.jsp to Index files in Plesk > Domains > example.com > Apache & Nginx Settings
I have added this information in the article.
Please sign in to leave a comment.