Create Your First Application on Openshift

Hello guys,in the recent post we have been seen some very basic stuff in order to start working with openshift cloud service.
If you have not read the last post on cloud, then you need to read it before reading this one.
Click Here.
Now we will see how to create an application on cloud in order to access it from any where by reffering your own domain name like,
now,log in to your account we hasn’t created any application on openshift so it will ask you to create your first application click onto that link and it will take you to page where you have to specify application name and domain name for your application,

here in the first text field you have to give name for your application like i will give “myfirstapp” after that in next text field we have to give domain name like i gave here “mydomain” you can give any thing here.

like my own personal domain on openshift looks something like this,”“.

ok,now below it will ask you to wheather you want to scale your application,if you select scale then the openshift will automatically manages all the traffic that comes to your site.In this case it automatically applies the load balancer to your application whenever required.
now click onto the add application button below, and that’s how you have created your very first application on cloud.

On next page it will allow you to select in what language/environment you want to create your application for convinience we will create our first app in java so select tomacat 6 or you can choose the latest version of tomact as well.
here we will create a simple web site using JSP.after that click onto create app button below and it will take you to your main setting page of your account.

here you can see the application that you have created just before some time ago click onto it.
you will enter into main section of your account.
Now, we have to do some important things as follows:
first in order to access the remote shell and remote repository of your application you have to create pair of public/private keys.
now open your terminal and do as follows:

Generating DSA/RSA Keys

The first step involves creating a set of DSA/RSA keys for use in authentication.

This should be done on the client.

To create your public and private SSH keys on the command-line:

first create a directory in your home directory and name it as “.ssh” this will be an hidden directory in home directory we will keep our public key which is required every time when we access ssh or remote repo of our application.And one more important thing the key should
be stored in the .ssh folder,and this is important.
mkdir ~/.ssh

after that give some essential permissions to the directory as follows:
chmod 700 ~/.ssh

Now cd into .ssh directory,
cd ~/.ssh

and now type the following command in order to create pair of public/private keys:
ssh-keygen -t dsa
in above command we choose dsa type for public key, you can also choose rsa type for your public key as well.

after that it will ask a name of the file for your public key like we will give redhat here.
Generating public/private rsa key pair.
Enter file in which to save the key (/home/b/.ssh/id_rsa):redhat

now it will ask for the passphrase this will be like a password for your public key every time you access ssh of openshift it will ask you for the
authentication then you have to specify your passphrase at that time.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

now it will show you following message:
Your identification has been saved in redhat.
Your public key has been saved in

Your public key is now available as ~/.ssh/ in your home folder.
Congratulations! You now have a set of keys. Now it’s time to make your systems allow you to login with them.

Now,Here we need to tell the openshift about our newly created public key this is required because when we access the openshift using ssh then the openshift must know about your public key.Now all you have to do is see into the right hand side of your account,and click onto it there it will ask you for entering the contents of your public key, in that case simply edit your newly created public key file like we just created is in ~/.ssh directory.

And copy entire contents of this file and paste it into the text field given in your openshift account in this way we tell the openshift about our newly created public key.this is required for doing ssh handshaking when establishing connection with remote ssh on openshift server.

now we have created public key, now it’s show time,
create a directory in your home directory and let’s name it as openshift simply.
now cd into this directory.
cd ~/openshift

now we have to clone the directory structure of our source code from remote repository into our local system this can be done using git utility for more information on git please visit this site

now, in simple i will tell you what this git does the git simply copies the source code for your application onto your local system, and also it allows you to push the code from your local system onto the remote server(openshift in our case).It means that git is simply a stupid source code management system.

now the following command will clone the source code from openshift server into your current working directory like:

git clone “path to your remote repository”.

this will ask you to enter the private key code, that is the passprhse that you had entered during the creation of public key.
now onto your openshift account see into top right corner where the path to your git repository is given simply copy it and,

git clone “paste it here”.

now after this you will see a new directory in ~/openshift directory which will be same as your application name.
now as we are creating a simple JSP page, so browse to following path.
here you will see index.html file this will be your default file for your web site so now simply test wheather your web site is working or not.
by going to this URL:

after typing the appropriate URL you will see the content of your index.html page.
you can modify the content of this page simply by modifying the file from your system.
now if you are a good java programmer then you can put all your .jsp files in this webapp directory on your system.
now suppose you have just modified the index.html file in this directory.
now in order to see the output of this file by typing the URL, you have to push this modified code onto the cloud,yes you are right by using git, this can be done as follows:

cd ~/openshift/your-app-directory

then type following commands,
git commit -a -m “type any thing here”.

in above command we are going to commit the changes that we have done so far onto remote repository.
after this type the following command as:

git push

this command will push the code that you have cloned from openshift repository again back to it.
now this will take some time because it restarts all the cartridges that you are using for your application.
so if everything wents good then it will show you “success”.

now it is time to test it, again go to the URL of your site and see the changes has taken place.
that’s how you can create any type of application using openshift. as you remember we have been taken tomecat 6 web server so you can
simply host your JSP and servlet programmes on openshift by simply following the above steps.

now here is one more thing that is worth important to be mentioned over here, if you wanted to access the remote shell for your account on openshift for doing some tasks like configuring the environmental variables for your server instance or suppose you are using mysql
as a database for your application then in that case how will you create the database on remore server this is where the concept of ssh comes you can access the remote shell of openshift by simply typing the following command:

but first copy the URL of ssh that is given to you by openshift, for this see into the right side of you account where you can see “access your account remotely” click on “see” button and copy that path and enter it in your terminal, like mine is:

ssh 52e671c65973ca4*******

so by using above command you will be able to access the shell of your openshift account.

ha ha ha ha,that’s it guys you are all done now you are free to create any kind of application on this mind freaking cloud service
that’s why i just love’in it.
redhat openshift Rocks.
Hope you enjoyed this post, thank you.



  1. This info is very very useful for to make your own web application not at local machine also at web site by the help of OpenShift which is open source best and just i create my own web application in jsp with mysql tools.

    Thanks Swapnil its a best way to learn about open source and other info.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s