Skip to main content

Platform as a Service (PaaS)

Platform as a Service

In simple words in this project we are going to develop a online coding webapp where you can just choose the programming language in which you want to code and Execute your code in the website itself.
The magic of using webserver and docker technology in PaaS is 
you can just connect all your device with the server and anyone connected with it will have access to the Coding Website we will develop.

1. First we will Develop the Web Page and Save it as  paas.html in the html folder of you apache server.

Write the Following code in that--

<form action ="">

    <h2>Select the Language</h2>   
<select name="languages">

  <option value="java">Java</option>
  <option value="python">Python</option>
  <option value="c">C</option>
  <option value="cpp">C++</option>


<h2>Enter the name of Program</h2>
<input type=text name="n">

<h2>Enter your code here</h2>
 <textarea name="message" rows="50" cols="80">


 <textarea name="input" rows="10" cols="30">

 <input type=submit value="Start">


We can see the Form used in the html file tranfers the inputs from the user to the which is stored in the cgi-bin folder of your apache server.
The html coding done above is very simple.
The python file is explained below. is as follows--


print "Content-type:text/html\r\n\r\n"

import os
import cgi,commands,re,cgitb
import mysql.connector as mariadb



f = open("{}.java".format(name),"w")

f = open("i{}.txt".format(name),"w")

d=commands.getstatusoutput("sudo docker run --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp java:7 javac {}.java".format(name))

e=commands.getstatusoutput("sudo docker run --rm -v \"$PWD\":/usr/src/myapp -w /usr/src/myapp java:7 cat i{}.txt | java {}".format(name,name))

f = open("{}.txt".format(name),"w")

print "<META HTTP-EQUIV=refresh CONTENT=\"0; URL={}.txt\">".format(name)

a=commands.getstatusoutput("rm {}.java {}.class

This looks complicated but yet simple. The python programming used here can be understand even you use some other programming language.
Only the commands written inside  commands.getstatusoutput() do the real magic.

The working of the python file is as follows:-

The selected language is stored in the lang varialble. The name of class or the program is stored in name variable and the whole program written by user  in the textarea field of html page is stored in the mes variable.
First we go to /var/www/html directory of our apache server on rhel by the command os.chdir("path").
We write all the command that are to be executed by rhel server(or redhat commands) inside the   commands.getstatusoutput() method and the store the output of these commands in a variable.

At first by using python file handling features, we create a file naming The name is provided by the user. Then we write the written program which is stored in mes variable in the file if the language selected is java. Then we close the file.
The sign {} is used for a variable like we use %d or %s in printf in c language. It is later defines by the content in .format() function.

The two main command used here are-  
sudo docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp java:7 javac {}.java".format(name)  
sudo docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp java:7 java {}".format(name)
 Note that in python file we have used \ sign before the " to remove conflicts.

The two are docker commands 
This will add your current directory as a volume to the container, set the working directory to the volume, and run the command javac which will tell Java to compile the code in and output the Java class file to name.class.
Download the java dockerfiles from:- 

cat i{}.txt | java {}

In this code cat iname.txt | java name, We redirect the java programs standard input to the iname.txt file. Whenever in the program user writes some code to take input from the standard input, it get redirected to this text file.

We then stored the output of java in variable e and save it in a file name.txt.
In the last print command we redirect the output of html page to the name.txt file which stores the output of the java file.
Enjoy you PaaS. Ask any problems in comments.    


  1. how to install and set path for the docker image of openjdk?..please can u give me the full details..

    1. Hello,
      The simplest method is, if you have latest version of Docker 1.9.1 installed just make a java program and save it( and connect to internet
      and then try to run the following command-

      sudo docker run --rm -v $PWD:/usr/src/myapp -w /usr/src/myapp java:7 javac

      This should automatically search for needed files and will download and install them as needed...
      Hope this works, if some problem still exists please mention...


Post a comment

Popular posts from this blog

Share applications with ssh (SaaS)

We are going to share our server's application programs to client system without actually installing it to client's pc. In this example we are going to use firefox as application program but any installed application(on server side) can be used for SaaS . Server- RHEL7.2 Client- Windows or any linux based OS For any type of service we need server applications which defines protocols that tells how the communication to client is going to happen. For SaaS we will use SSH protocol- Secure Shell ( SSH ) is a cryptographic network protocol for operating network services securely over an unsecured network. The server will be open-ssh -- OpenSSH is the connectivity tool for remote login with the SSH protocol. It encrypts all traffic to eliminate eavesdropping, connection hijacking. Step 1- Installing SSH server -- Open terminal and type- [root@www Desktop]# yum  install openssh-server This will install the open-ssh server to your rhel7.2 server. In case you don

Software as a service(Saas)

Software as a service (SaaS)-- ============================ You probably have seen Google docs or any web app, well in all web apps there is one common thing that they run on some remote servers and use their resources but still you can use them as they or we can say they will create the feeling that they are installed in our own system. In cloud computing you can say that there are web apps are SaaS but as cloud computing is just a marketing term. All there web app providers were present even before cloud computing name came into market, now they are just changing name of their services by adding cloud to it or adding taglines like Into the cloud! but in real cloud computing the implementation of saas is bit different. As we earlier said cloud computing is also on-demand computing... Suppose there is some CRM software which is very high cost and you need such a software for your company. But you don't want to pay for the times when you are not using the software or you may