Month: February 2016

CGI TASK

CGI TASK

HOW TO RUN C++ PROGRAM ON WEB BROWSER THROUGH CGI

There are two methods to do it.

  1. Without a script.
  2. With a script.

As you can see, I have explained first method in detail in the previous blog.

Now, we will discuss the second method i.e. with a script.

29

Here, I have made two files

  1. “new.cpp”.
  2. “new”.

Both these files should be in the same directory “/usr/lib/cgi-bin”.

Give permissions to both the files with

“sudo chmod 777 new.cpp”.
“sudo chmod 777 new”.

Make sure all permissions are given to the folder and files.

The file with name “new” is a script file.

Here is the explanation of the code.

1. In the line “#!/bin/sh” #!(i.e. hash bang) means to include the shell “sh” to interpret the following code and execute the script. In place of “sh” we can write “bash”, “dash”. All these are shells to interpret the code.

2.  The word “echo” is used to output status text to the screen or a file. It is used to get the feedback.

3.   The HTML <pre> element (or HTML Preformatted Text) represents preformatted text. Text within this element is typically displayed in a non-proportional font exactly it is laid out in a file. Here “new.cpp” is the file with output filename “n”. Whitespace inside this element is displayed as typed.

4.   The HTML </pre> is the closing element.

Now compile the c++ program through “sudo g++ new.cpp -o n”,where “n” is the output filename.

At web browser search the URL “localhost/cgi-bin/new”.

44.png

And you will get the output of c++ program  on browser.

 

 

 

Advertisements
Task 2

Task 2

How  To Install Apache Web Server And How To Run C++ Program On A Web Browser

We make our computer a Web server because it allows us to host our own website from our comp and will let us to make web pages with buttons.

For making our comp a web server we need to install apache.

Now without wasting any time lets seee how to install apache

STEP 1:-Install apache2

Search on your computer for the terminal (terminal is command line interpreter just like command prompt but little modified).

  1. Write a command “sudo apt-get update”.It will update all your recent apps and will take few time1.png
  2. then write”sudo apt-get install apache2″.It will install the apache web server successfully.
  3. To check whether it is installed write”service apache2 status”.

1

STEP 2:-Default page

  1. Go to the web browser and search “localhost”.It will show default page of ubuntu.
  2. Instead of “localhost” you can also type inet address i.e. “127.0.0.1”.This can be configured by writing command “ifconfig” on terminal.

4.png

2

2.png

B.NOW, THE 2nd PART…

BY DEFAULT, apache2 folder is saved in etc folder under user in UBUNTU..

IMPORTANT:

For giving PERMISSIONS to your cgi bin and to your saved program you need to give these commands other wise you can not save your program under CGI-BIN

sudo a2enmod cgi

sudo/etc/init.d/apache2 restart

sudo service apache2 restart

CGI: It stands for common gateway interface.Its a standard way for web server to pass web user’s request to an application program and to receive data back to forward to the user

STEP1: PROGRAM

U need to save your program in cgi-bin folder so that it can run on LOCALHOST……..

The common MIME(multipurpose internet mail extensions) types are text/plain for unformatted text and text/html for HTML formated content.

Short for Multipurpose Internet Mail Extensions, a specification for formatting messages so that they can be sent over the Internet. Many e-mail clients now support MIME, which enables them to send and receive graphics, audio, and video files via the Internet mail system.

9

this is a simple program written using html content too.

  • The line “Content-type:text/html \n\n” means that the type of the content used is html.
  • A blank line separates the HTTP response Header from the HTTP response body.

now , i had saved this program with name ab.cpp..so

in terminal type these commands now

STEP2: EXECUTION

44.png

While giving permissions to file remember you should be in the directory cgi-bin .

45.png

 

STEP3: DISPLAY THROUGH CGI

Now ,to show the output in the web browser search the URL “localhost/cgi-bin/ab.cgi”.

8

 

What’s new here is the part after the “?”. The information after the “?” character is known as a query string. When the server is passed a URL with a query string, it calls the CGI program identified in the first part of the URL (before the “?”) and then stores the part after the “?” in the environment variable QUERY_STRING. A Query String, by its name suggest that it is a string used to ‘Query’ or parse the thing. The query string begins after the first ‘?’ character. Query strings are usually used to pass a list of variables and value pairs

The following is a CGI program called second.cpp that uses query information supplied by the form. (form is dicussed after this)

1

This program is placed in /usr/lib/cgi-bin
Compile it using the command :
g++ second.cpp -o second.cgi
This creates an executable file second.cgi in /usr/lib/cgi-bin
Make sure, second.cgi has executable permissions. If not, Change the permissions of this file as :
chmod 777 second.cgi
Make sure the cgi-bin directory has executable permissions. If not, change them by executing the chmod command in the directory /usr/lib as:
chmod 777 cgi-bin

Form supplies the query string to this CGI program. The following is the program, named as form.cpp that contains the form in CGI format.

2

This program is also placed in /usr/lib/cgi-bin
Compile it using the command :
g++ form.cpp -o form.cgi
This creates an executable file form.cgi in /usr/lib/cgi-bin
Make sure, form.cgi has executable permissions. If not, Change the permissions of this file as :
chmod 777 form.cgi
Some of these commands may require root permissions. For this, use sudo before the command.

2

NOTE..

GIVE DATATYPE LONG OR DOUBLE INSTEAD OF INT . SO, THAT UA PROGRAM CAN SHOW OUTPUT UPTO MORE NUMBERS……

After compiling both files. Now ,go to browser and search the URL “localhost/cgi-bin/form.cgi” as shown below.

5

Now press “submit” button.After submitting it,the control will goes through another file second.cgi that is “factorial of a number” .

Screenshot from 2016-02-19 18:51:54

heres,s the example of another program i.e to display the table of an number entered by user.The procedure is same.

7

933

55

Task 1

Task 1

 

How to Dual boot Windows 7 and Ubuntu 14.04 and run c++ program in ubuntu

STEP   1 :-If windows is already installed on your PC then take backup of  your windows by

  1. click control panel
  2. click backup or restore your files
  3. click set up backup displaying at the side of your console and follow the wizard

1

STEP 2:-Disk  Partition

  1. Click Windows key +X and press disk management
  2. select the disk you want to partition
  3. right click on it and select shrink volume
  4. If you have 500 Gb harddisk then partition  around 60 Gb for ubuntu

2

It will create a free space.

  1. Then make your pendrive bootable and insert it to usb port.
  2. Shut down your computer
  3. Start  your computer and press corresponding function key of Bootup settings.

Click on USB drive option

3.jpg

STEP 3 :- Install OS

4.jpg

Click on install Ubuntu, then it will show..

5

Click on something else option…

6

Select the FREE SPACE option created by you. AND, click on + sign shown at th bottom.

7

8

Ext4 journaling file system is for LINUX  as  ntfs is for WINDOWS.Its for storing, retrieving data. Adjust size of your choice, or don’t change it.

On Mount point ,Select /

Then, go ahead. Enter your name, password etc. on the next screen complete some simple steps and finally click install.

Ubuntu-on-VirtualBox-16

10

STEP 4:- Change Boot Device

11

Set your BIOS boot order such that once again the hard drive is the primary boot device.

Restart your system and again go to BOOT SETUP as you did in step 3 and now select hard drive.
Note that if you skip this step, your system will try to load an operating system from removable media before looking for Windows. If there is not a disk in the drive, it should proceed to boot into Windows.

Step 6: Reboot and Configure

13

You will now see a choice between Windows and Ubuntu Linux. Go ahead and select Linux, and get yourself familiarized with this great OS.

WELCOME TO THE WORLD OF UBUNTU…..

14

 

NOW,THE Next Part……………

HOW TO RUN A C++ PROGRAM ON UBUNTU THROUGH CLI(COMMAND LINE INTERFACE i.e TERMINAL

Screenshot from 2016-02-01 16:35:27

$tep 1: Go to TERMINAL

make a directory let named ,test and then change the directory using commands

mkdir test

cd test

then, go to GEDIT OR VIM …these are the text editors for ubuntu there are
many more also..

you can install these via net or through UBUNTU SOFTWARE CENTER
furthur, write a c++ program in gedit and save it in test.

$tep 2: I AM HERE SHOWING A PROGRAM TO FIND FACTORIAL OF A NO.

Screenshot from 2016-02-07 18:48:55

here, ls command is for seeing list of programs in a particular selected directory…

.cpp is the extension on c++ file…….. I HAD SAVED THE PROGRAM BY NAME fact.cpp

g++ fact.cpp is for compilation

./a.out is for executing the program

…… YOU CAN RUN ANY OF your c++ program in this way, there is another example i m showing you here…

Screenshot from 2016-02-07 18:59:33

NOTE:

TERMINAL is CASE-SENSITIVE…

there is a command, clear used to clear the terminal