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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s