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).
- Write a command “sudo apt-get update”.It will update all your recent apps and will take few time
- then write”sudo apt-get install apache2″.It will install the apache web server successfully.
- To check whether it is installed write”service apache2 status”.
STEP 2:-Default page
- Go to the web browser and search “localhost”.It will show default page of ubuntu.
- 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.
B.NOW, THE 2nd PART…
BY DEFAULT, apache2 folder is saved in etc folder under user in UBUNTU..
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 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
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.
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
While giving permissions to file remember you should be in the directory cgi-bin .
STEP3: DISPLAY THROUGH CGI
Now ,to show the output in the web browser search the URL “localhost/cgi-bin/ab.cgi”.
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)
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.
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.
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.
Now press “submit” button.After submitting it,the control will goes through another file second.cgi that is “factorial of a number” .
heres,s the example of another program i.e to display the table of an number entered by user.The procedure is same.