Guide: Introduction to Openshift hosting Apache Tomcat

To present my Java EE course project in this blog I had to find another
Apache Tomcat hosting service since the one we got during education was
not responding anymore. That’s how my search for a free Apache Tomcat
hosting service started. I contacted with my hosting service where i host
this blog and I was quickly explained that this kind of service is not
supported there. Next i went to the web (Goggled) to search for such free
service just to find out that there are not that many of them at all.
And then I saw that Red Hat offering Apache Tomcat service and much more
with their OpenShift PaaS – Platform as a Service. They basically give you
a platform (clouded resources) to deploy your applications and this platform
supports Node.js, Ruby, Python, PHP, Perl, and Java technologies and much more.

So how is it done?
1. The first thing is to go to http://openshift.com and create an account.
Once you have created an account you can publish 3 application for free.
During the creation of your account you will have to specify you Namespace
that latter on will be used for your application URL’s.

2. Install the OpenShift client tools. For that you need to install Git for Windows
and a Ruby and configure them. This is explained in the following link.
During the configurations of Git you will create an ssh key for connecting
to your repository on Red Hat.

3. Now that you installed the client tools you are ready to create your first
application container on OpenShift. Actually this can be done using their web
interface but it’s faster to do that with the command line. To create your
application container with Apache Tomcat already installed you need to run to
following commands in the command prompt:

rhc app create -a tomcat -t diy-0.1

this will create for you your DIY (do it yourself) application container on
Red Hat’s servers with the name “tomcat” and a local Git repository in your
current location at the command prompt with the same name. now all you need
to do is to edit your local repository and to push changed to the server
uisng git.

Enter your repository folder by entering:

cd tomcat

and then enter the following commands:

1.git remote add upstream -m master git://github.com/openshift/openshift-tomcat-quickstart.git
2.git pull -s recursive -X theirs upstream master
3.git push

what we are doing here is configuring a remote upstream and we pull it’s content from it
to our local git repository. finally we push this changes to our own application container.
at the end of this process we will have a DIY application with Apache Tomcat 7 installed.

4. Now we need to connect to our application container to copy there our application files.
There are 3 way to do that: we can copy the files to our local git repository and push the
changes to the server, we can use an SSH terminal (like PUTTY) and edit the files using
commands from the command line or we can use an SSH based FTP tool (like WinSCP)
to manage files as you would do in a commander interface.

you can download PUTTY from here. You should download the zipped file for all PUTTY package.
you can download WinSCP from here.

putting your project into the webapps folder of your local application repository and pushing
it to the server will put your files in the following location:

/var/lib/openshift/<your openshift userID>/app-root/
runtime/repo/diy/tomcat/webapps

and this is not the right webapps folder for the installed Apache Tomcat.
That is the reason I prefer to use the WinSCP application. So lets open WinSCP and
the first window you will receive is the WinSCP Login window:

enter the following information:

  1. Your full application container URL – you can get it from OpenShift.
  2. Your Username – again you can find it on your application page on OpenShift under the “GIT REPOSITORY” section.
  3. Your OpenShift password.
  4. You have to supply your ssh key, you can create it using puttygen.exe application that you can download from the PUTTY link. Open puttygen.exe:

  1. Click the “Load” button and go to your C:\Users\<your windows username>\.ssh folder. Chose the id_rsa file (without extension) and press Open. you will be notified that this is a security key.
  2. Click the “Save private key” button to save a new private key (.ppk) file.

5. Now you can supply your security key and connect via WinSCP to your machine on Openshift.
When you connected you will receive a commander window. The right pane connected to
your OpenShift repository at the following location:

/var/lib/openshift/<your openshift userID>/

Head to:

/var/lib/openshift/<your openshift userID>/app-root/
data/tomcat/webapps

and copy your project files here.
Head to:

/var/lib/openshift/<your openshift userID>/app-root/
data/tomcat/lib

and copy your project resource files (your Jars necessary for the project).

6. Finally open command prompt again and run:

rhc app restart tomcat

to restart your container and let the changes take affect. now you can access you project
using the application URL you can get on OpenShift.

2 Responses to this entry

  • Robert Says:

    Hi.

    There is a typo in your instructions.

    The -X switch should be Capital -X (as shown). Not small -x as you have it.

    Step 3:
    2.git pull -s recursive -X theirs upstream master

    Posted on July 21st, 2014 at 10:04 pm Reply | Quote
  • Emil Adjiev Says:

    @ Hi, Thanks for your remark, your are right the X should be uppercase, I went to the post edit and it actually written that way, but because the quote paragraph lower cases all the letters I actually don’t have that much to do about it.

    Posted on July 23rd, 2014 at 5:26 am Reply | Quote

Leave a comment