Private JAVA Hosting Overview
With Java|Pipe's Private 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.
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.
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
Use your web browser via Tomcat Probe to Stop and Restart your container.
Any new packages purchased late October 2007 includes the Tomcat Probe, a valuable free tool that we are adding to your java hosting experience. It is a web based Tomcat manager/probe that provides invaluable information about your web applications. You can even Stop and Restart your container from your web browser. (Probe is excluded from Starter package because 32mb heap is not sufficient).
- First you need to configure your security access to your Probe. Configure tomcat/conf/tomcat-users.xml by removing the word "REMOVE" and entering your desired Username and Password for "Manager".
- Once tomcat-users.xml has been configured you must restart your container using the shell method for changes to take effect.
- Open your browser to the URL: http://yourdomain.com/probe/ and login using the information you entered in tomcat-users.xml file.
- Take a moment to explore the different tabs and links.
- To Restart your container using Probe, click on "System Information" tab and then on the right "Wrapper Control".
- You will see the Restart JVM, Stop JVM and Request Thread Dump upper right just under the tabbed menu.
Note: If you Stop JVM, you will need to use the Shell Method to start your container back up.
How to Start and stop Tomcat using the JAVA Service Wrapper
The Java Service Wrapper now uses the above commands to stop and start your container as of October 2007.
Other useful commands from your bin directory via Shell Method:
$ ./tomcat console (this is similar to ./catalina.sh run, which provides an interactive startup tailing the log)
$ ./tomcat status (This tells you whether your wrapper is running or not and what PID it is running on)
Click here for more information about the Java Service Wrapper
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'?>
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="admin" password="password" roles="admin,manager"/>
</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 encoded 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&password=dbpass"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name"/>
</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.
Click here to find out more about our JAVA hosting packages.
|