Private Tomcat Hosting Print

  • 283

Private JAVA Hosting Overview

With JavaPipe's cheap Java hosting packages, you get your own dedicated RAM to run your own private Apache Tomcat container. This means that you have total control over your development platform. You can stop, start and configure your Tomcat when needed. Your container will run in your own process which allows you to run Struts and other frameworks, such as Spring.

To start and stop your container you have 2 options.

You can stop and start your container the using Apache Tomcat's ./startup.sh and ./shutdown.sh commands via shell or you can use Tomcat Control within your SiteWorx control panel.

Click here to find out more about Tomcat Control.

How to Start or shutdown Tomcat directly via Shell Method:

First you connect to your account via SSH.

1) Start Tomcat:

$ cd yourdomain.com/tomcat/bin
$ ./startup.sh

Note: ALWAYS do shutdown.sh before startup.sh to make sure you don't already have an instance running.

2) Stop Tomcat:

$ cd yourdomain.com/tomcat/bin
$ ./shutdown.sh

Where to Upload Your WebApps

Where to place your files:

When you sftp or scp to your site you will see yourdomain.com and var. Tomcat is in yourdomain.com directory (symbolic link to actual tomcat dir in that folder) Also ignore the public_html folder. This folder is used shared Tomcat packages.

Default jsp context is yourdomain.com/tomcat/webapps/ROOT/
Full ROOT Path: /home/username/yourdomain.com/tomcat/webapps/ROOT/

You do not have to use the ROOT webapp, you are welcome to create your own webapp and deploy it from the tomcat/webapps/ directory.

ALL files will be served by Tomcat unless you specify that you would like to seperate html from your jsp. Or if you wish to run PHP, just create a folder called php and upload your php files there.

Deploying War Files

To deploy a War file, simple place the file in the webapps directory and restart the container. Or you may use the Tomcat manager to turn on and off webapps.

Tomcat Administrator

Tomcat Administrator is a web based interface for configuring your container. It provides an easy way to setup webapps, context directories and manage your Realm settings.

Be very careful when using the Tomcat Administrator because it will overwrite your existing server.xml file. Do not change the port numbers, or your site will stop working.

Tomcat Manager

What is Tomcat Manager? Its a web based interface for montoring your tomcat stats. It also includes tools for deploying your war files and stopping and starting individual applications.

Realm

A Users Realm is a "database" of usernames and passwords that identify valid users of a web application (or set of web applications), plus an enumeration of the list of roles associated with each valid user. You can think of roles as similar to groups in Unix-like operating systems, because access to specific web application resources is granted to all users possessing a particular role (rather than enumerating the list of associated usernames). A particular user can have any number of roles associated with their username.

First you need to decide which Realm method that you wish to use. Memory Realm, JDBC or JNDI and so on. Then you will need to ssh into your server.xml file and uncomment the appropriate Realm that suites your needs.

Memory Realm uses a text file in tomcat/conf/ called tomcat-users.xml

(these roles and passwords can be updated using the Tomcat Administrator)

<!--?xml version='1.0' encoding='utf-8'?--><br>
<tomcat-users><br>
<role rolename="manager"/>
<user username="admin" password="PASS" roles="manager,admin"/>
</tomcat-users>

Roles identify the protected directory in the web.xml in the WEB-INF directory. So if a role is added under roles for the user, they are granted access with that user and password.

To protect the directory in a webapp, you add the requirements in the web.xml deployment descriptor of that webapp:

    <security-constraint>
<display-name>Example Security Constraint</display-name>

<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>

<!-- Define the context-relative URL(s) to be protected -->
<url-pattern>/jsp/security/protected/*</url-pattern>

<!-- If you list http methods, only those methods are protected -->
<http-method>DELETE</http-method>

<http-method>GET</http-method>

<http-method>POST</http-method>

<http-method>PUT</http-method>

</web-resource-collection>

<auth-constraint>

<!-- Anyone with one of the listed roles may access this area -->
<role-name>tomcat</role-name>

<role-name>role1</role-name>

</auth-constraint>

</security-constraint>

The role to protect the directory 'secret' is 'protect. Using login admin/passwd or user2/tomcat can access that directory.

Type of login is set to BASIC for popup HTTP Auth, others are DIGEST for digest enpred string which is also HTTP and FORM for web page type form requesting authentication.

JDBCRealm uses database for user login information instead of a text file like MemoryRealm. You can use either MySQL or PostgreSQL. There are examples in the server.xml. Just uncomment the one you want and enter your database login details.

    <realm debug="99" classname="org.apache.catalina.realm.JDBCRealm">
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost/authority?user=dbuser&amp;password=dbpass"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name"/&gt;
</realm>

Everything else is set the same way except the roles and login information is stored in your database:

    create table users (
user_name varchar(15) not null primary key,
user_pass varchar(15) not null
);

create table user_roles (
user_name varchar(15) not null,
role_name varchar(15) not null,
primary key (user_name, role_name)
);

As they say there is more than one way to skin a cat. There is more than one way to protect a cat using Realm. JNDIRealm, JAASRealm and different methods of authentication. For more information on Realm - apache.tomcat.org

MySQL

You can find jdbctest.jsp in your ROOT webapp for example configuration for connecting to your MySQL database.

ConnectorJ is installed in the shared tomcat classpath. If you decide to install your own driver, please be sure to take out the shared version in common/lib/

To connect to MySQL with JSP you will need the Class.forName path to the MySQL Driver:

Class.forName("com.mysql.jdbc.Driver").newInstance()

To test your connection: Use the testjdbc.jsp file included in your ROOT directory.

  Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection conn;
conn = DriverManager.getConnection
("jdbc:mysql://localhost:3306/DATABASENAME","Username","PASSWORD");

For more information about connector|J click here: mysql.com

Will My Site Work on Port 80?

Yes, once your have entered our nameservers for your domain to point to our server and it has propagated fully, it will then work with port 80. The preview link with special port number that we provide to you in your Tomcat Setup Email is only to be used in the beginning until your domain name begins working. There on after, you no longer need to provide that special port in the url.


Was this answer helpful?

« Back