Download Linux installation

Document related concepts
no text concepts found
Transcript
Ex. No:
LINUX INSTALLATION
Date:
AIM
To study about the open source operating system (Linux) and its installation.
PROCEDURE
INTRODUCTION TO LINUX OPERATING SYSTEM
Linux refers to the family of Unix-like computer operating systems using the Linux
kernel. Linux can be installed on a wide variety of computer hardware, ranging from mobile
phones, tablet computers and video game consoles, to mainframes and supercomputers.
Linux is a leading server operating system, and runs the 10 fastest supercomputers in the
world. Use of Linux by end-users or consumers has increased in recent years, partly owing to
the popular Ubuntu, Fedora, and openSUSE distributions and the emergence of netbooks
with preinstalled Linux systems and smartphones running embedded Linux. The
development of Linux is one of the most prominent examples of free and open source
software collaboration; typically all the underlying source code can be used, freely modified,
and redistributed, both commercially and non-commercially, by anyone under licenses such
as the GNU General Public License. Typically Linux is packaged in a format known as a
Linux distribution for desktop and server use. Linux distributions include the Linux kernel
and all of the supporting software required to run a complete system, such as utilities and
libraries, the X Window System, the GNOME and KDE desktop environments, and the
Apache HTTP Server. Commonly used applications with desktop Linux systems include the
Mozilla Firefox web-browser, the OpenOffice.org office application suite and the GIMP
image editor.
The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus
Torvalds. The main supporting user space system tools and libraries from the GNU Project
(announced in 1983 by Richard Stallman) are the basis for the Free Software Foundation's
preferred name GNU/Linux.
STANDARD INSTALLATION OF FEDORA 14
Fedora is an RPM-based, general purpose collection of software including an
operating system based on the Linux kernel, developed by the community supported Fedora
Project and sponsored by Red Hat. The Fedora Project's mission is to lead the advancement
of free and open source software and content as a collaborative community.
One of Fedora's main objectives is not only to contain software distributed under a
free and open source license, but also to be on the leading edge of such technologies. Fedora
developers prefer to make upstream changes instead of applying fixes specifically for
Fedora—this ensures that their updates are available to all Linux distributions. In 2008,
Linus Torvalds, author of the Linux kernel, started that he used Fedora because it had fairly
good support for the PowerPC processor architecture which he favored at the time.
1
Fedora Features
There are some really neat, new features in Fedora that do work well. they're going to
be more exiting for system administrators and developers than they are someone just running
Fedora at home. Easily the most important of these is the arrival of Simple Protocol for
Independent Computing Environment (SPICE). This is a desktop presentation service
protocol, like Microsoft's RDP (Remote Desktop Protocol) and Citrix's ICA (Independent
Computing Architecture), that you use to run thin-client desktops. SPICE will let you support
remote desktops from a Fedora server, and eventually a Red Hat Enterprise Linux (RHEL)
server. Each remote desktop will run as a Kernel Virtual Machine (KVM). SPICE is being
very useful in schools or anywhere that needs centralized control or inexpensive desktops. It
may prove a new and interesting way to get users on a Linux "desktop." Fedora also includes
a new interface: MeeGo. This is the interface for the MeeGo operating system, which is
meant for netbooks, Mobile Internet Devices (MID) and embedded devices. While not as
well known or as mature as Android, MeeGo shows great promise. By making it available on
Fedora, developers can develop applications for MeeGo. Distribution Package Kit, the
default package manager front-end on Fedora.
The Fedora Project distributes Fedora in several different ways:
Fedora DVD/CD set – a DVD or CD set of all major Fedora packages at time of
shipping; Live images – CD or DVD sized images that can be used to create a Live CD or
boot from a USB flash drive and optionally install to a hard disk; Minimal CD – used for
installing over HTTP, FTP or NFS. The Fedora Project also distributes custom variations of
Fedora which are called Fedora spins. These are built from a specific set of software
packages and have a combination of software to meet the requirements of a specific kind of
end user. Fedora spins are developed by several Fedora special interest groups. It is also
possible to create Live USB versions of Fedora using Fedora Live USB creator.
Fedora Core
Fedora Core 1 was the first version of Fedora and was released on November 6, 2003. It was
codenamed Yarrow. Fedora Core 1 was based on Red Hat Linux 9 and shipped with version
2.4.19 of the Linux kernel, version 2.4 of the GNOME desktop environment, and K Desktop
Environment 3.1.
Fedora Core 2 was released on May 18, 2004, codenamed Tettnang. It shipped with Linux
2.6, GNOME 2.6, KDE 3.2, and SELinux. XFree86 was replaced by the newer X.org, a
merger of the previous official X11R6 release, which additionally included a number of
updates to Xrender, Xft, Xcursor, fontconfig libraries, and other significant improvements.
Fedora Core 3 was released on November 8, 2004, codenamed Heidelberg. This was the first
release of Fedora Core to include the Mozilla Firefox web browser, as well as support for the
Indic languages. Fedora Core 3 shipped with GNOME 2.8 and KDE 3.3. It was the first
release to include the new Fedora Extras repository. Fedora Core 4 was released on June 13,
2005, with the codename Stentz. It shipped with Linux 2.6.11, KDE 3.4 and GNOME 2.10.
This version introduced the new Clearlooks theme. It also shipped with the OpenOffice.org
2.0 office suite, as well as Xen, a high performance and secure open source virtualization
framework.
2
Fedora Core 5 was released on March 20, 2006, with the codename Bordeaux, and
introduced the Fedora Bubbles artwork.It was the first Fedora release to include Mono and
tools built with it such as Beagle, F-Spot and Tomboy. It also introduced new package
management tools such as pup and pirut (see Yellowdog Updater, Modified).
Fedora Core 6 was released on October 24, 2006, codenamed Zod. This release introduced
the Fedora DNA artwork, replacing the Fedora Bubbles artwork used in Fedora Core 5. This
version introduced support for the Compiz compositing window manager and AIGLX.
Fedora 7, codenamed Moonshine, was released on May 31, 2007. The biggest difference
between Fedora Core 6 and Fedora 7 was the merging of the Red Hat "Core" and
Community "Extras" repositories, and the new build system put in place to manage those
packages. Fedora 7 featured GNOME 2.18 and KDE 3.5, a new theme entitled Flying High,
OpenOffice.org 2.2 and Firefox 2.0. Fast user switching was fully integrated and enabled by
default. Also, there were a number of updates to SELinux. Fedora 8, codenamed Werewolf,
was released on November 8, 2007.
Some of the new features and updates in Fedora 8 included:
 PulseAudio
 system-config-firewall
 Codeina
 IcedTea NetworkManager
 Better laptop support
Fedora 8 also included a new desktop artwork entitled Infinity, and a new desktop theme
called Nodoka. A unique feature of Infinity is that the wallpaper can change during the day
to reflect the time of day. Fedora 9, codenamed Sulphur, was released on May 13, 2008.
Some of the new features of Fedora 9 included:
 GNOME 2.22.
 KDE 4.0 , which is the default interface as part of the KDE spin.
 OpenJDK 6 has replaced IcedTea.
 Data Persistence in USB images.
Fedora 9 featured a new artwork entitled Waves which, like Infinity in Fedora 8, changes the
wallpaper to reflect the time of day. Fedora 10, codenamed Cambridge, was released on
November 25, 2008. It flaunts the new Solar artwork. Its features include:
 Faster startup using Plymouth
 Support for ext4 filesystem
 LXDE Desktop Environment (LXDE Spin)
 GNOME 2.24
 KDE 4.1 (KDE Spin)
Fedora 11, codenamed Leonidas, was released on June 9, 2009. This was the first release
whose artwork is determined by the name instead of by users voting on themes.
Some of the features in Fedora 11 are:
 ext4 as the default file system
 GCC 4.4
 GNOME 2.26
 KDE 4.2 (KDE Spin)
 2.6.29 Linux kernel
3

fprint - support for systems with fingerprint readers
Fedora 12, codenamed Constantine, was released on November 17, 2009.
Some of the features in Fedora 12 are:
 Optimized performance.
 Improved WebCam support (Cheese)
 Automatic bug reporting tool (abrt)
 Bluetooth on demand
 Many virtualization enhancements (KVM, libvirt, libguestfs)
 GCC 4.4, GNOME 2.28 & GNOME Shell preview
 KDE 4.3, KDE 4.4
Fedora 13, codenamed Goddard, was released on May 25, 2010. During early development,
Fedora project-leader Paul Frields anticipated "looking at the fit and finish issues. We have
tended to build a really tight ship with Fedora, but now we want to make the décor in the
cabins a little more sumptuous and to polish the deck chairs and railings."







Automatic printer-driver & Automatic language pack installation
Redesigned user-account tool
A new way to install Fedora over the Internet
Updates to NFS
Inclusion of Zarafa Open Source edition
KDE PulseAudio Integration
New command-line interface for NetworkManager
Fedora 14, codenamed Laughlin, was released on November 2, 2010.
Features of Fedora 14 include:
 Updated Boost to the upstream 1.44 release
 Addition of the D compiler (LDC) and D standard runtime library (Tango)

 Inclusion of virt-v2v tool
 Inclusion of Spice framework for VDI deployment
 NetBeans IDE updated to the 6.9 release
 Inclusion of a tech preview of the GNOME Shell environment
4
BASIC INSTALLATION STEPS
1. Boot from the DVD.
2. Skip the media test by pressing the tab and return keys on the
keyboard.
5
3. Click the "Next" button on the welcome screen.
4. Select the appropriate language, then click the "Next" button.
6
5. Select the appropriate keyboard layout, then click the "Next" button.
6. When prompted, click the "Re-initialize drive" button.
7
7. When prompted, click the "Re-initialize" button.
8. Enter a fully qualified hostname, then click the "Next" button.
8
9. Select the appropriate timezone by clicking on the nearest city on the map, then click
the "Next" button.
10. Enter the root password, then click the "Next" button.
9
11. Select the "Use All Space" option, uncheck the "Encrypt system"
option and check the "Review and modify partitioning layout" option,
then click the "Next" button.
12. The current partitioning layout is presented. If the OS is to be used for an Oracle
installation, make sure the swap partition is at least 2G
(2048M) in size. Once you are happy with the partition structure, click
the "Next" button followed by the "Format" and "Write changes to disk" button.
10
13. Accept the default boot loader settings by clicking the "Next" button.
14. Select the appropriate packages to install and check all three
additional repositories.
11
15. Selecting the repositories will require you to enter your network Configuration.
Select the appropriate network interface, highlight the "System eth0" adapter and click
the "Edit" button. Click on the "IPv4 Settings" tab, select the appropriate method and
enter the required information. When complete, click the "Apply" and "Close"
buttons.
16. Once the repositories are selected, select the "Customize Now" option and click the
"Next" button.
12
17. Select the appropriate package groups and optional packages for your installation
and click the "Next" button.
18. Wait while the installation completes.
13
19. When the installation is complete, restart the machine as instructed. When the
machine has restarted, click the "Forward" button on the welcome screen.
20. Accept the license agreement by clicking the "Forward" button.
14
21. Enter login user details, then click the "Forward" button.
22. Set the appropriate date-time information, then click the "Forward"
button.
15
23. Decide if you want to send a hardware profile to the Fedora project, then click the
"Finish" button.
24. Click the username you defined previously.
16
25. Enter the password and click the "Log In" button.
26. After you've logged in, you are presented with the default Fedora desktop.
17
RESULT:
Thus the installation of the Linux using the open source has been made successfully.
18
Ex. No:
MYSQL INSTALLATION
Date:
AIM:
To study about the installation and working in MySql using the open source environment.
PROCEDURE
To install MySql from the existing open source operating systems the following steps
have to be performed
[root@server root]# cd /root
[root@server root]# mkdir /root/files /data /data/mysql
[root@server root]# cd files
[root@server root]# wget http://www.d9x.net/downloads/unix/mysql-4.0.12.tar.gz
[root@server root]# tar xzvf mysql-4.0.12.tar.gz
[root@server root]# cd mysql-4.0.12
if your using FreeBSD use "adduser" instead of "useradd".
[root@server root]# groupadd mysql
[root@server root]# useradd -g mysql mysql
[root@server root]# ./configure --prefix=/usr/local/mysql--datadir=/data/mysql
DataDir is where your mysql databases will be stored including the database which
contains all mysql user accounts, you can easily backup all databases/users by saving
the contents of this folder. /data/mysql
NOTE:
If you see ERROR: No curses/termcap library found" find where
libncurses.so.5 is installed on your system and add the following flag to your
configure statement : --with-named-curses-libs=/usr/lib/libncurses.so.5 (or
where ever it may be) if you get a "mod_auth_dbm" Error Copy the ndbm.h file from
/usr/include to the /usr/include/db1 directory (or install db1-devel) if you get a "no acceptable
C compiler found in $PATH" Error Install a c compiler, example: gcc
if you get "libmysql.c:1349: warning: passing arg 5 of `gethostbyname_r'
from incompatible pointer type" Error you need to install a c++ compiler, install: libstdc++devel, gcc-c++ (same version as gcc)
19
[root@server root]# make
[root@server root]# make install
[root@server root]# ./scripts/mysql_install_db
[root@server root]# ln -s /usr/local/mysql/share/mysql/mysql.server/sbin/mysqld
[root@server root]# chown -R mysql:mysql /data/mysql
[root@server root]# chown -R mysql:mysql /usr/local/mysql
START, STOP & RESTART MySQL
[root@server root]# mysqld start
[root@server root]# mysqld stop
[root@server root]# mysqld restart
USING MySQL
EXPORT DATABASE:
[root@server root]# /usr/local/mysql/bin/mysqldump -u root -p
database_name > database_name.sql
IMPORT DATABASE:
[root@server root]# /usr/local/mysql/bin/mysql -u root -p database_name <
database_name.sql
SET ROOT PASSWORD:
[root@server root]# /usr/local/mysql/bin/mysqladmin -u root -p password
NEW_PASS
NOTE: When it prompts you to enter the password, just hit Enter
if you don't see an error, the password was successfully changed.
UNINSTALLING MySQL
[root@server root]# rm -rf /usr/local/mysql
[root@server root]# rm -rf /data/mysql
[root@server root]# rm -rf /sbin/mysqld
RESULT:
Thus the installation is completed and now MySql is ready to work on successfully.
20
Ex. No:
APACHE INSTALLATION
Date:
AIM:
To study about the installation of Apache and its uses under the open source software.
PROCEDURE:
INTRODUCTION
The Apache Web server is arguably the most popular Web server in use on the
Internet today. Here are some of the reasons why Apache is so popular; you don't have to be
running Windows to run Apache. It was developed on various Unix/Linux/BSD platforms,
and then recently ported to Win32. Internet Information Server, a Web server made by
Microsoft for the Windows NT platform, is made for use in the "Windows-only" world.
While IIS has many features, it’s lack of portability limits it’s market share. Another reason
for Apache's widespread acceptance is its overall stability. While you can slow down an
Apache Web server, you can rarely, if ever, kill one. The Apache Web server service is near
bulletproof. Lastly, it's relatively fast. I say "relatively" as it's relative to what you're doing
with it. If you're hosting a pretty plain Web site with mostly static content, Apache is a
fireball. If you throw tons of CGI scripts at it, while making database calls at the same time,
you're going to slow it down. Though much of the slowdown will come from your scripts
themselves, and not from Apache. Apache evolved out of the NCSA https project to its
current status as one of the fastest, most efficient, and most functional web servers in
existence today. Apache has been shown to be substantially faster, more stable, and more
feature-full than many other web servers. Although certain commercial servers have claimed
to surpass Apache's speed (it has not been demonstrated that any of these "benchmarks" are a
good way of measuring WWW server speed at any rate). The developers of Apache feel that
it is better to have a mostly-fast free server than an extremely fast server that costs thousands
of dollars. Apache is run on sites that get millions of hits per day, and they have experienced
no performance difficulties. Apache is run on over 10 million Internet servers (as of May
2002). It has been tested thoroughly by both developers and users. The Apache Group
maintains rigorous standards before releasing new versions of their server, and their server
runs without problems on over one half of all WWW servers available on the Internet. When
bugs do show up, they release patches and new versions as soon as they are available.
21
INSTALLATION OPTIONS
I’ll cover three methods of installing Apache under Linux. The three methods are:
·Binary installation
·Using an RPM (Red Hat Package Manager) – recommended for people running Red Hat
Linux
·Building from source
APACHE INSTALLATION GUIDE
We recommend using the RPM installation method. This is the easiest way to install
Apache for people that are new to Linux.
DOWNLOAD THE SOFTWARE
You can download Apache from the Apache Software Foundation web site located at
http://www.apache.org, in source and binary forms. While your downloading Apache, you
may want to browse over the documentation.
WHAT YOU NEED
To install Apache, you will need the following things:
1. A computer running Linux
2. Root access on this computer
3. For binary and source installations, the tar and gunzip Unix utilities
BINARY INSTALLATION
A binary is pre-configured, which means someone else has gone to the trouble of
configuring and building the software for you. There are, however, a few things you should
keep in mind:
1. Binaries are compiled for a particular operating system. In other words, you must use a
binary built specifically for FreeBSD on your FreeBSD machine and a Linux binary on your
Linux machine. You need to be sure to grab the correct binary; if you don't see a binary for
your particular operating system, you must choose a different method of installation.
2. Apache binaries are usually a version or two behind the current source distribution. This
means you don't reap the benefits of the latest bug fixes and feature enhancements.
3. Because binaries are pre-configured, you don't have much opportunity to alter the way the
software works. If you're a newcomer, you may not care about this loss of flexibility.
Fortunately most Apache binaries include a full source distribution, providing you with the
best of both worlds - play now, learn later. Now let's install a binary. Point your browser at
http://www.apache.org/dist/httpd/binaries/ and download the binary for your operating
system (in our case, Linux). You'll most likely be presented with a directory containing
multiple versions of Apache in various compressed forms. For the purposes of this guide, I'll
22
assume you've downloaded the gzip'd form of the latest 2.0.x Apache binary (currently that's
httpd-2.0.35-i686-pc-linux-rh72.tar.gz). If there is a README associated with the file you're
downloading, you may want to review it for any interesting installation tidbits or possible
bugs. If you can't find a binary for your operating system, choose either the RPM Installation
(if you are running Red Hat Linux) or Build from Source method. Now let's uncompress the
archive using the handy combination of gunzip and tar. You should replace the "httpd2.0.35-i686-pc-linuxrh72. tar.gz" text below with the name of the gzip'd file you
downloaded. gunzip < httpd-2.0.35-i686-pc-linux-rh72.tar.gz | tar xvf – Some of you may be
lucky enough to have a version of tar that is capable of taking care of both tasks. tar xvzf
httpd-2.0.35-i686-pc-linux-rh72.tar.gz Either way, you should end up with an httpd-2.0.x
directory, with x being the particular subversion of Apache you downloaded. Move into the
newly
created directory. cd httpd-2.0.x As of Apache 1.3.11, binary distributions contain an install
script called install.bindist.sh. If your binary does not seem to contain such an install script,
take a look at the README.bindist and/or INSTALL.bindist documents for further
information; if these documents don't outline a simple installation method, you'll probably
want to use one of the other methods I cover in this guide. If you've not already done so,
you'll need to become root. You can become root by typing su, then the root password. Then
go ahead and run the install script../install.bindist.sh This command should install the various
bits of the Apache distribution into the appropriate locations; the default is usually to install
everything under /usr/local/apache (confirm this by consulting your README.bindist and/or
INSTALL.bindist documents). That's all there is to it on installing binaries.
RPM INSTALLATION
Those of you running Red Hat Linux may want to take advantage of Red Hat's RPM
("RedHat Package Manager") system. Almost identical to a binary, an RPM is further
customized to play nicely with other RPMs and provide a consistent interface to installing,
updating, and removing binaries. For Linux newcomers or when installing a small standard
component, RPMs are simple and reliable. Bear in mind that an Apache RPM may already
be installed on your system depending on how Linux was originally installed on your
computer. To find out, at the shell prompt, type: rpm -qa | grep apache If you see something
like apache-1.3.9xxx, an Apache RPM has already been installed. You can also type that
command typing httpd instead of apache to see if it’s installed. If you don't have an Apache
RPM, you must obtain one. Red Hat 7.3 ships apache-1.3.23- 11.src.rpm in the
RedHat/RPMS directory on the installation CD. Or, point your browser at
ftp://ftp.redhat.com/pub/redhat/redhat-7.3-en/os/i386/RedHat/RPMS and download it. If
you've not already done so, you'll need to become root. Navigate to the same directory as the
.rpm file you obtained, and then type the following command, substituting the name of the
.rpm you're using for example: apache-1.3.23-11.src.rpm. rpm -ivh apache-1.3.23-11.src.rpm
RPM should grind away, displaying its progress with a primitive ####### progress bar.
Barring any errors, you're done.
23
BUILD FROM SOURCE
Building Apache from source may seem like a daunting task to newcomers, but the
Apache developers have done a wonderful job of making the task about as simple as could
be. Just three more commands than a binary installation and you skip the arduous task of
figuring out which binary is the right one for your particular operating system. Point your
browser at http://www.apache.org/dist/httpd/ and download the gzip'd form of the current
version of Apache (2.0.36 at the time of this writing). Now let's uncompress that archive
using gunzip and tar. You should replace the httpd- 2.0.36.tar.gz below with the name of the
gzip'd file you downloaded. gunzip < httpd-2.0.36.tar.gz | tar xvf – You should end up with
an httpd-2.0.x directory, x being the particular subversion of Apache you downloaded. Move
into the newly created directory.
cd httpd-2.0.x
Now we'll use the configure and make commands to configure, make, and install Apache. If
you've not already done so, now would be the time to become root../configure Your screen
should look something like:
# ./configure
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
Configuring Apache Portable Runtime library ...
...
config.status: executing default commands
Unless errors were reported (not warnings), your Apache installation is now configured and
we can move on. This is where things get a bit ugly. Making Apache produces screenfulls of
output.
Make Your screen should look something like:
#make Making all in srclib make[1]:
Entering directory `/home/ryan/dl/apache_guide/httpd 2.0.36/srclib'
Making all in apr
make[2]: Entering directory `/home/ryan/dl/apache_guide/httpd2.0.36/srclib/apr'
...
make[1]: Leaving directory `/home/ryan/dl/apache_guide/httpd-2.0.36'#
Finally, you're ready to install your Apache build.
# make install
Now Apache is installed.
Starting Apache
24
Let's take your new Apache installation out for a spin. If you installed Apache using a binary
or from scratch, as root, type: /usr/local/apache/bin/apachectl start If you used an RPM, as
root, type: /sbin/service httpd start Point your browser at your brand new Web server,
http://localhost/. If everything worked you should see the default home page. Customize
Apache uses some rather easy to understand text files for configuration. On a Red Hat
system,you'll find them in /etc/httpd/conf. Quite a few Linux distributions place them in this
same place, but if you can't find such a directory, do a search for "httpd.conf". Once you find
these, you've found the main config files.
If you're new to Linux, and need help finding this file, here's how you can find it.
1.Login as root
2.Type: cd /
3.Type: find -name httpd.conf
Now you should see where the file is located. When you move into the
directory containing httpd.conf, you should see these three files:
·httpd.conf – This has the settings for the overall configuration for the server.
·access.conf – This file contains all the security settings for Apache.
·srm.conf – This file contains the MIME definitions and default document names for files on
the server.
RESTARTING APACHE
Whevever you make changes to the server configuration files, such as httpd.conf,
they won't take effect until the server is restarted. In Linux, Apache can be restarted
depending on how you installed it. If you installed Apache using a binary or from scratch, as
root, type:
/usr/local/apache/bin/apachectl start
If you used an RPM, as root, type:
/sbin/service httpd start
After being restarted the changes will have taken effect.
RESULT
Thus the installation process for Apache was successful and now it is ready for the
processing.
25
Ex. No:
CONNECT PHP WITH MYSQL
Date:
AIM:
To study about the MySQL connectivity with PHP to create a student database and
add values into it using the connectivity.
ALGORITHM:
Step 1: Create an HTML program to get the details of the student dynamically.
Step 2: Open the gedit and type the PHP script.
Step 3: Run the PHP script program.
Step 4: Check the database to see whether the detail have been updated.
Step 5: Stop the program.
PROCEDURE
[jkkmct@localhost ~]$ su
Password: admin123
[root@localhost jkkmct]# cd /var/www/html
[root@localhost html]# gedit
Type the following in gedit and save it as form.html
26
PROGRAM
<html>
<head>
<title>LOGIN</title></head>
<body>
<form action="connect.php" method="post">
<p>
"Enter course no"<input type="text" name="cid"></p>
<p>"enter the coursename"<input type="text" name="cname"></p>
<p>"click here to submit"<input type="submit" name="submit"></p>
</form>
</body>
27
SCRIPT
Type the following in gedit and save it as connect.php
<?php
$cid=$_POST['cid'];
$cname=$_POST['cname'];
$con=@mysql_connect("localhost","root","")or die (mysql_error());
echo "connected to database";
$db=@mysql_select_db("student",$con)or die(mysql_error());
echo "selected database";
$str="insert into courses values($cid,'$cname')";
$res=@mysql_query($str) or die(mysql_error());
if($res>0)
{
echo "Record created";
}
?>
28
OUTPUT
TYPE THE FOLLOWING IN THE BROWSER
NOW GO TO TERMINAL
[jkkmct@localhost ~]$ mysql -u root -p\
> > Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 5.1.45 Source distribution
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| student |
| test |
+--------------------+
4 rows in set (0.11 sec)
mysql> use student ;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
29
mysql> connect
Connection id: 29
Current database: student
mysql> show tables;
+-------------------+
| Tables_in_student |
+-------------------+
| course |
| courses |
| students |
+-------------------+
3 rows in set (0.00 sec)
mysql> select * from courses;
+------+-------+
| cid | cname |
+------+-------+
| 1 | java |
| 1 | java |
+------+-------+
2 rows in set (0.02 sec)
RESULT:
Thus the connectivity is established between PHP and My SQL and details of
students are created in the database.
30
Ex. No:
CREATING AND VALIDATING THE LOGIN
PAGE USING PHP
Date:
AIM:
To create a login page and validate that login page by using PHP.
ALGORITHM:
Step 1: Create a login page by using HTML.
Step 2: Open the gedit and type the PHP script.
Step 3: Run the login page and provide the login details and click login to run PHP script.
Step 4: Check the database to see whether the username is available or not.
Step 5: If username and password matches display the welcome screen, else display as “login
incorrect” .
Step 6: Stop the program.
PROCEDURE
[jkkmct@localhost ~]$ su
Password: admin123
[root@localhost jkkmct]# cd /var/www/html
[root@localhost html]# gedit
Type the following in gedit and save it as HomePage.php.
31
Create Login Page (HomePage.php)
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1"
bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1"
bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text"
id="myusername"></td>
</tr>
<tr> <td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr> <td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
32
Create Validation Page (checklogin.php)
<?php
$host="localhost"; // Host name
$username="root"; // Mysql default username
//$password=""; // Mysql No password
$db_name="my_db"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$sql="SELECT * FROM $tbl_name WHERE
username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
echo "Welcome To Our Web Page";
else
echo "Wrong Username or Password";
?>
33
OUTPUT:
RESULT:
Thus the login page is created and validation is done by using php.
34
Ex. No:
PROGRAMMING IN PYTHON- PROGRAM TO
PERFORM FUNCTIONS IN LIST & TUPLE
Date:
AIM:
To study about the programming methods in python to perform the functions in list
type.
ALGORITHM:
Step 1: Start the program
Step 2: Type the program in the gedit and save it with the extension of .py
Step 3: Run the program in the terminal window as python filename.py
Step 4: Stop the program
PROCEDURE
1. Write a Hello World Python Program
Create helloworld.py program as shown below.
$ vim helloworld.py
#!/usr/bin/python
# Hello world python program
print "Hello World!";
2. Verify Python Interpreter Availability
Make sure python interpreter is installed on your system as shown
below.
$ where is python
python: /usr/bin/python /usr/bin/python2.5 /usr/bin/python2.6
/etc/python
/etc/python2.5 /etc/python2.6 /usr/lib/python2.4 /usr/lib/python3.0
/usr/lib/python2.5 /usr/lib/python2.6 /usr/local/lib/python2.5
/usr/local/lib/python2.6 /usr/include/python2.5
/usr/include/python2.6
/usr/share/python /usr/share/man/man1/python.1.gz
$ which python
/usr/bin/python
35
3. Execute Python Program
You can either execute using “python helloworld.py” or
“./helloworld.py”.
$ python helloworld.py
Hello World!
( or )
$ chmod u+x helloworld.py
$ ./helloworld.py
Hello World!
Note: As python is an interpreted language, you don’t have the compilation
step similar to the C program.
PROGRAM:
1. Write a sample program in python programming
#Sample python program
x=5;
y=5;
print "x:",x;
print "y:",y;
z=x+y;
print "z:",z;
output:
X= 5
Y= 5
Z=10
2. String Concatenation in python programming
#String concatenation
worda = "Computer";
wordb = "Science";
print "Word A = ",worda;
print "Word B = ",wordb;
36
wordc = worda +" "+ wordb;
print "Wordc is = ",wordc;
wordd = worda * 3;
print "Word D = ",wordd;
str = "Hello world!"
length = len(str);
print "Str : ",str;
print "Length = ",length;
print "First character is : ",str[0];
print "Print Character from 2nd to 6th : ",str[2:7];
print "Print Character starting from 3rd character : ",str[2:];
print "Prints String two times : ",str*2;
print "Prints concated string : ",str+" TEST";
print str[-1]; #print last character
print str[-6]; # print character from last 6th position
print str[:-2]; # Everything except the last two characters
output:
[jkkmct@localhost ~]$ python concat.py
\\To see output type “python programname.py”
Word A = Computer
Word B = Science
Wordc is = Computer Science
Word D = ComputerComputerComputer
Str : Hello world!
Length = 12
First character is : H
Print Character from 2nd to 6th : llo w
Print Character starting from 3rd character : llo world!
Prints String two times : Hello world!Hello world!
Prints concated string : Hello world! TEST
!
w
Hello worl
37
3. Write a python program to perform function in Lists
#Python Lists
#!/usr/bin/python
print "\t \t \t Python Lists";
list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']
print "Prints complete list:",list
print "Prints first element of the list : ",list[0]
print "Prints elements starting from 2nd to 4th:",list[1:4]
print "Prints elements starting from 3rd element:",list[2:]
print "Prints list two times:", tinylist * 2
print "Prints concatenated lists: ", list + tinylist
#modify the 4th elements in the list
print "\nBefore modifying the 4th element in list :",list[4]
list[4] = 'efgh';
print "After modifying the 4th element in list :",list[4]
print "\ncomplete list:",list
#Appending new elements
list.append('ijkl');
print "\nAfter appending list:",list
#deleting an element in list
del list[2];
print "\nAfter deleting an element in List :",list
print"\n"
output:
[jkkmct@localhost ~]$ python func_lists.py
Python Lists
Prints complete list: ['abcd', 786, 2.23, 'john', 70.200000000000003]
Prints first element of the list : abcd
38
Prints elements starting from 2nd to 4th: [786, 2.23, 'john']
Prints elements starting from 3rd element: [2.23, 'john', 70.200000000000003]
Prints list two times: [123, 'john', 123, 'john']
Prints concatenated lists: ['abcd', 786, 2.23, 'john', 70.200000000000003, 123, 'john']
Before modifying the 4th element in list : 70.2
After modifying the 4th element in list : efgh
complete list: ['abcd', 786, 2.23, 'john', 'efgh']
After appending list: ['abcd', 786, 2.23, 'john', 'efgh', 'ijkl']
After deleting an element in List : ['abcd', 786, 'john', 'efgh', 'ijkl']
4. Write a python program to perform functions in tuples
#Python Tuples
print("\t \t \t Python tuples");
tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )
tinytuple = (123, 'john')
print("\ncomplete tuple :",tuple);
print("Prints first element of the tuple:", tuple[0]);
print("Prints elements starting from 1nd to 3th:", tuple[1:4]);
print("Prints elements starting from 3rd element:", tuple[2:]);
print("Prints tuple two times:", tinytuple * 2 );
output:
[jkkmct@localhost ~]$ python tuples.py
Python tuples
complete tuple : ('abcd', 786, 2.23, 'john', 70.200000000000003)
Prints first element of the tuple: abcd
Prints elements starting from 1nd to 3th: (786, 2.23, 'john')
Prints elements starting from 3rd element: (2.23, 'john', 70.200000000000003)
Prints tuple two times: (123, 'john', 123, 'john')
39
5. Prime Number using Python.
for n in range(2, 10):
count=0;
for x in range(2, n):
if n % x == 0:
print n, 'equals', x, '*', n/x
count=1;
break
if count!=1:
print n, 'is a prime number'
output:
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3
6. The Range() and Len() in Python
a = ['Mary', 'had', 'a', 'little', 'lamb']
for i in range(len(a)):
print i, a[i];
output:
0 Mary
1 had
2a
3 little
4 lamb
40
7. Write a python program to perform functions in Dictionary.
#Python Dictionary
tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
print ("Python Dictionary:" );
print ("complete dictionary",tinydict );
print ("Key :",tinydict.keys()); # Prints all the keys
print ("values:",tinydict.values()); # Prints all the values
output:
[jkkmct@localhost ~]$ python func_dict.py
Python Dictionary
complete dictionary {'dept': 'sales', 'code': 6734, 'name': 'john'}
Key : ['dept', 'code', 'name']
values: ['sales', 6734, 'john']
8. Fibonacci Series using Python
>>> def fib(n): # write Fibonacci series up to n
... """Print a Fibonacci series up to n."""
... a, b = 0, 1
... while b < n:
... print b,
... a, b = b, a+b
...
>>> # Now call the function we just defined:
... fib(2000)
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
9. Set operations in Python
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
>>> fruit = set(basket) # create a set without duplicates
>>> fruit
set(['orange', 'pear', 'apple', 'banana'])
>>> 'orange' in fruit # fast membership testing
41
True
>>> 'crabgrass' in fruit
False
>>> # Demonstrate set operations on unique letters from two words
...
>>> a = set('abracadabra')
>>> b = set('alacazam')
>>> a # unique letters in a
set(['a', 'r', 'b', 'c', 'd'])
>>> a - b # letters in a but not in b
set(['r', 'd', 'b'])
>>> a | b # letters in either a or b
set(['a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'])
>>> a & b # letters in both a and b
set(['a', 'c'])
>>> a ^ b # letters in a or b but not both
set(['r', 'd', 'b', 'm', 'z', 'l'])
10. Error Handling In Python
import sys
try:
f = open('myfile.txt')
s = f.readline()
i = int(s.strip())
except IOError as (errno, strerror):
print "I/O error({0}): {1}".format(errno, strerror)
except ValueError:
print "Could not convert data to an integer."
except:
print "Unexpected error:", sys.exc_info()[0]
raise
42
output:
\\ In the root directory there is a text file named “myfile.txt” and have content “hello”
[jkkmct@localhost ~]$ python errorhandle.py
Could not convert data to an integer.
Traceback (most recent call last):
File "errorhandle.py", line 5, in <module>
i=int(s.strip())
ValueError: invalid literal for int() with base 10: 'hello'
\\ In the root directory there is a text file named “myfile.txt” and have content “12345”
[jkkmct@localhost ~]$ python errorhandle.py
Traceback (most recent call last):
File "errorhandle.py", line 12, in <module>
raise
TypeError: exceptions must be classes or instances, not NoneType
11.Finally class in Python
def divide(x, y):
try:
result = x / y
except ZeroDivisionError:
print "division by zero!"
else:
print "result is", result
finally:
print "executing finally clause"
>>> divide(2, 1)
result is 2
executing finally clause
>>> divide(2, 0)
division by zero!
executing finally clause
>>> divide("2", "1")
executing finally clause
43
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in divide
TypeError: unsupported operand type(s) for /: 'str' and 'str'
RESULT:
Thus the python has been executed successfully to perform the functions in the list
and tuple.
44
Ex. No:
EMPLOYEE MANAGEMENT SYSTEM USING IN
PYTHON
Date:
AIM:
To write program for Employee Management System using in python.
ALOGRITHM:
1. Start the program.
2. Import the #!/usr/bin/python.
3. Declare the variable and function.
4. Add the employee details.
5. Show the employee details.
6. Search the employee details.
7. Save the program for filename.py
8. Execute the program.
9. Stop the program.
45
PROGRAM:
def emp_add(el):
n = raw_input("Name :")
a = raw_input("Age :")
e = {'name':n, 'age':a}
el.append(e)
def emp_show(el):
print '-'*20
for e in el:
print 'Name :', e['name']
print 'Age :', e['age']
print '-'*20
def emp_search(el):
name = raw_input("Enter a name : ")
for e in el:
if e['name'] == name:
print "Name: ", e['name']
print "Age : ", e['age']
return
print "No such employee :("
def menu():
print "\n1. Add employee"
print "2. Show employees"
print "3. Search for employee"
print "4. Exit"
def NOT_ANOTHER_MAIN__SIGH():
el = []
while True:
menu()
c = raw_input("\nEnter your choice :")
try:
c = int(c)
except ValueError:
print "Enter a number :D"
continue
if c == 1:
46
emp_add(el)
elif c == 2:
emp_show(el)
elif c == 3:
emp_search(el)
elif c == 4:
exit(0)
else:
print "Bad choice. Try again"
if __name__ == '__main__':
NOT_ANOTHER_MAIN__SIGH()
47
OUTPUT:
[jkkmct@localhost ~]$ chmod u+x pgm1.py
[jkkmct@localhost ~]$ python pgm1.py
1. Add employee
2. Show employees
3. Search for employee
4. Exit
Enter your choice :1
Name :prasanth
Age :20
1. Add employee
2. Show employees
3. Search for employee
4. Exit
Enter your choice :2
-------------------Name : prasanth
Age : 20
-------------------1. Add employee
2. Show employees
3. Search for employee
4. Exit
Enter your choice :3
Enter a name : prasanth
Name: prasanth
Age : 20
1. Add employee
2. Show employees
3. Search for employee
4. Exit
Enter your choice :
RESULT
Thus the above program was executed successfully and output was verified.
48
Ex. No:
PERL PROGRAMMING
Date:
AIM:
To create a program in Perl to find the palindrome using simple subroutine and recursion
function.
ALGORITHM:
Step 1: Start the Program
Step 2: Type the following in terminal [root@localhost cgi-bin]# gedit
Step 3: Type the program in gedit
Step 4: Save it with the extension of the .pl
Step 5: Execute in the terminal window.
Step 6: Stop the program
49
PROGRAM FOR PERL
1. Sample PERL
#!usr/bin/perl # the above line is shebang directive
$name=<STDIN>;
chomp($name);
print "$name\n";
2. Scalar variables in PERL
#!/usr/bin/perl
my $animal="Camel"; # this variable is lexically scoped ie local
my $ans=42_243; #this is similar to 42243
print "$animal\n";
print "$ans\n";
print "The square of &ans",$ans*$ans,"\n";
3. Array in PERL
#!usr/bin/perl
my @animal=("cow","Buffalo","Camel");
print "@animal\n"; # list all elements in array
print "$#animal\n"; # list last element position
print "$animal[0]\n"; #list 0th position element
$count=@animal;
print "$count"; # count no of elements in array
4. Hash in PERL
#!usr/bin/perl
%color=('apple'=>"red",'banana'=>"yellow",'orange'=>"orange");
print “Before Deletion\n";
# to display all the values in hash
@keys=keys %color;
@values=values %color; # it ill store the array values
foreach $key (@keys)
{ print "$color{$key}\n";
}
delete $color{'apple'}; # to remove specific key
print “After Deletion \n”;
@keys=keys %color;
@values=values %color; # it ill store the array values
foreach $key (@keys)
{ print "$color{$key}\n";
}
50
5.If loop in perl
#!usr/bin/perl
my $a=10;
$condition=1;
if($condition)
{ my $y=100;
print "$a\n";
print "$y\n";
}
print "$a\n";
print "$y\n";
6. If not loop (unless)in perl
#!usr/bin/perl
$a=5;
unless($a>10) #is equal to if not
{ print "a less than 10";
}
7. While loop (until) in perl
#!usr/bin/perl
$a=0;
until($a>10) #is equal to while
{
print "$a\n";
$a++;
}
8. for each loop (upper limit is not fixed )in perl
#!usr/bin/perl
my @animals=("cow","buffalo","camel",123,100,243,300);
foreach $key(@animals)
{ print "$key\n";
}
9. String operation:
#!usr/bin/perl
$a="hello";
$b="world";
print $a.$b,"\n";
$str="-";
51
print $str x 80,"/n";
@a=(10..25);
print "@a\n";
10. Hard reference variable:
10.1 Reference variable(scalar)
#!usr/bin/perl
$a=100;
$b=\$a;
print "$b\n";
10.2 De reference the variable(scalar variable)
#!usr/bin/perl
$a=100;
$b=\$a;
print "$$b\n";
10.3 Array reference variable
#!usr/bin/perl
@arr=('hello','122','200','thamarai');
$c=\@arr;
print "$c\n"; # print the address
print "@$c\n"; # print the values of array
print "$c->[1]\n"; #point the specified location in array, to access the single element
10.4 Hash variable in perl
#!usr/bin/perl
%color=('apple'=>"red",'banana'=>"yellow",'orange'=>"orange");
$h=\%color;
print "$h\n";#print the reference address
@keys=keys %$h;
52
print "@keys\n"; #it contains the key value
print "$h->{'apple'}\n"; # it print the the apple alone
10.5 Magic variable in perl
#!usr/bin/perl
%color=('apple'=>"red",'banana'=>"yellow",'orange'=>"orange");
$h=\%color;
print "$h\n";#print the reference address
@keys=keys %$h;
print "$h->{'apple'}\n"; # it print the apple alone
foreach (@keys)
{ print "$h->($_}\n"; # to display all key values we use $_ instead of keys
}
11 .Function
#!usr/bin/perl
sub sayHello()
{ print "Hello\n";
}
&sayHello();
11.1 function with parameter
#!usr/bin/perl
sub add()
{ my ($a,$b)=@_; #the values will be stored in @_ array variable for dynamically
print $a+$b;
}
&add(10,15);
11.2 Find Maximum value using function
#!usr/bin/perl
sub max()
53
{ $max=shift @_; # shift function remove the first element in array and the remaining
element will be stored in $max
foreach $v (@_) # $v is the second values in the @_
{ $max=$v if $max<$v;
}
return $max;
}
$d=&max(10,278,1050,76,800,246,76,345);
print "The maximum value is $d\n";
12. Symbolic reference
That is no values and name for function (anonymous function)
Anonymous function is used only when need to use the code only once
#!usr/bin/perl
$b=sub #anonymous
{
my ($c,$d)=@_;
$e=$c*$d;
return $e;
};
91
$a=&$b(20,30);#De reference the function
print "the product is $a\n";
54
OUTPUT:
1. Sample PERL
[jkkmct@localhost ~]$ perl first.pl
thamarai
thamarai
2. Scalar variables in PERL
[jkkmct@localhost ~]$ perl scalar.pl
Camel
42243
3. Array in PERL
[jkkmct@localhost ~]$ perl array.pl
cow Buffalo Camel
2
cow
3
4. Hash in PERL
[Jkkmct@Jkkmct ~]$ perl Hash.pl
Before Deletion
yellow
red
orange
After Deletion
yellow
orange
[Jkkmct@Jkkmct ~]$
5.If loop in perl
[jkkmct@localhost ~]$ perl ifloop.pl
10
100
10
6. If not loop (unless)in perl
[jkkmct@localhost ~]$ perl unless.pl
a less than 10
7. While loop (until) in perl
[jkkmct@localhost ~]$ perl until.pl
0
1
2
3
4
5
55
6
7
8
9
10
8. for each loop (upper limit is not fixed )in perl
[jkkmct@localhost ~]$ perl foreach.pl
cow
buffalo
camel
123
100
243
300
9. String operation:
[jkkmct@localhost ~]$ perl string.pl
helloworld
--------------------------------------------------------------------------------/n10 11
12 13 14 15 16 17 18 19 20 21 22 23 24 25
10. Hard reference variable:
10.1 Reference variable(scalar)
[jkkmct@localhost ~]$ perl reference.pl
SCALAR(0x9506a68)
10.2 De reference the variable(scalar variable)
[jkkmct@localhost ~]$ perl reference1.pl
100
10.3 Array reference variable
[jkkmct@localhost ~]$ perl arrayvariable.pl
ARRAY(0x8358a70)
hello 122 200 thamarai
122
56
10.4 Hash variable in perl
[jkkmct@localhost ~]$ perl hashvariable.pl
HASH(0x830da70)
banana apple orange
red
10.5 Magic variable in perl
[jkkmct@localhost ~]$ perl hashvariable1.pl
HASH(0x8df4a70)
red
HASH(0x8df4a70)->(banana}
HASH(0x8df4a70)->(apple}
HASH(0x8df4a70)->(orange}
11 .Function
[jkkmct@localhost ~]$ perl function.pl
Hello
11.1 function with parameter
[jkkmct@localhost ~]$ perl functionparam.pl
25
11.2 Find Maximum value using function
[jkkmct@localhost ~]$ perl functionparam.pl
The maximum value is 1050
12. Symbolic reference
[jkkmct@localhost ~]$ perl symbolicref.pl
the product is 600
RESULT:
Thus the above program was executed successfully and output was verified.
57
Ex. No:
PERL PROGRAMMING USING CGI
Date:
AIM:
To study the Perl and CGI connectivity to create a database and add the details into
the database dynamically using the browser.
ALGORITHM:
1. Start the program.
2. Connect to the database.
3. Declare the variable for using database attributes.
4. Declare the condition for insert the value for database.
5. Create the form design for html program.
6. Add the employee details in browser.
7. And show the database added the details.
8. Execute the program.
9. Stop the program.
PROCEDURE:
Type the following in terminal
[jkkmct@localhost ~]$ su
Password:
[root@localhost jkkmct]# cd /var/www/html
[root@localhost html]# gedit
58
PROGRAM:
<html>
<head>
<title>LOGIN</title></head>
<body>
<form action="/cgi-bin/form2.cgi" method="post">
<p>
"Enter student roll no"<input type="text" name="rollno"></p>
<p>"enter the student name"<input type="text" name="sname"></p>
<p>"click here to submit"<input type="submit" name="submit"></p>
</form>
</body>
save the page as form.html & close it
Type the following URL in browser
http://localhost/form.html
59
SCRIPT:
#!/usr/bin/perl
use CGI;
$cgi=new CGI;
use DBI;
$rollno=$cgi->param('rollno');
$name=$cgi->param('sname');
my $dbh=DBI->connect("dbi:mysql:student","root","");
my $sth=$dbh->prepare("insert into students values(?,?)");
$res=$sth->execute($rollno,$name);
$dbh->disconnect;
if($res)
{
print $cgi->header,
$cgi->start_html,
$cgi->h1("Record created"),
$cgi->end_html;
}
Save that file as form2.cgi
close that file & open a same terminal type as
[root@localhost cgi-bin]# chmod +x form2.cgi
In new browser type the following
http://localhost/form.html
60
OUTPUT
Enter details using Web browser
61
Record created message in browser
Check the database as
mysql> select * from students;
+--------+---------------+
| rollno | sname |
+--------+---------------+
| 100 | thamarai |
| 200 | selvi |
| NULL | abcd |
| 71 | thamaraiselvi |
+--------+---------------+
4 rows in set (0.00 sec)
RESULT:
Thus the CGI connectivity is used to create database and to add details into it dynamically
using the browser.
62
Ex. No:
Date:
NS2 SIMULATION INSTALLATION
AIM
To study in detail about the installation of the NS2 simulator using the open source
environment.
PROCEDURE
INTRODUCTION TO NETWORK SIMULATOR NS-2
NETWORK SIMULATOR-2 is designed to run from on most UNIX based operating
systems.Ns is a discrete event simulator targeted at networking research. Ns provides
substantial support for simulation of TCP, routing, and multicast protocols over wired and
wireless (local and satellite) networks.
Step 1:
Download a copy of ns-allinone-2.34.tar.gz. Then from the command prompt there, execute
the following:
tar -xzf ns-allinone-2.34.tar.gz
cd ns-allinone-2.34
./install
(If this fails, try the Distribution Specific instructions)
Step 2:
After a long wait and a whole lot of text, you should see the installation finish up with text
like the following:
Nam has been installed successfully.
Ns-allinone package has been installed successfully.
Here are the installation places:
tcl8.4.11: /home/pcraven/ns-allinone-2.29/{bin,include,lib}
tk8.4.11: /home/pcraven/ns-allinone-2.29/{bin,include,lib}
63
otcl: /home/pcraven/ns-allinone-2.29/otcl-1.11
tclcl: /home/pcraven/ns-allinone-2.29/tclcl-1.17
ns: /home/pcraven/ns-allinone-2.29/ns-2.29/ns
nam: /home/pcraven/ns-allinone-2.29/nam-1.11/nam
xgraph: /home/pcraven/ns-allinone-2.29/xgraph-12.1
gt-itm: /home/pcraven/ns-allinone-2.29/itm, edriver, sgb2alt, sgb2ns,
sgb2comns, sgb2hierns
---------------------------------------------------------------------------------Please put /home/myusername/ns-allinone2.29/bin:/home/myusername/ns-allinone2.29/tcl8.4.11/unix:/home/myusername/ns-allinone-2.29/tk8.4.11/unix
into your PATH environment; so that you'll be able to run
itm/tclsh/wish/xgraph.
IMPORTANT NOTICES:
(1) You MUST put /home/myusername/ns-allinone-2.29/otcl-1.11,
/home/myusername/ns-allinone-2.29/lib,
into your LD_LIBRARY_PATH environment variable.
If it complains about X libraries, add path to your X libraries into LD_LIBRARY_PATH.
If you are using csh, you can set it like:
setenv LD_LIBRARY_PATH <paths>
If you are using sh, you can set it like:
export LD_LIBRARY_PATH=<paths>
(2) You MUST put /home/myusername/ns-allinone-2.29/tcl8.4.11/library
into your TCL_LIBRARY environmental variable. Otherwise ns/nam will complain during
startup.
(3) [OPTIONAL] To save disk space, you can now delete directories
tcl8.4.11 and tk8.4.11. They are now installed under /home/myusername/nsallinone2.29/{bin,include,lib}
After these steps, you can now run the ns validation suite with
cd ns-2.29; ./validate For trouble shooting, please first read ns problems page
http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list archive for
related posts.
64
At this point, you should follow the advice here and update your environment variables. You
should also add ns-allinone-2.29/bin to you path. This has links to all the executables created
by NS-2. Since the Tcl scripts may call these executables (like nam or xgraph), it is a good
idea to have them in the path.
You can test the installation by doing the following:
cd ns-2.29
./validate
Note that this validation takes a really long time. If it starts out ok, you
probably have a good installation.
At this point, you can see Getting Started with NS-2 .
RESULT
Thus the NS2 simulator has been installed successfully using an open source
environment.
65
Ex. No:
NS2 SIMULATION
Date:
AIM:
To write a program for NS2 Simulation in single processing using TCP.
ALOGRITHM:
1. Start the program.
2. Create the simulation operator.
3. Declare the color for nodes.
4. Declare the four nodes.
5. Connection transfer to one to another.
6. The TCP protocol using transfer the single
7. Save and execute the program.
8. Stop the program
66
PROGRAM:
#Create a simulator object
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the NAM trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the NAM trace file
close $nf
#Execute NAM on the trace file
exec nam out.nam &
exit 0
}
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
67
#Monitor the queue for link (n2-n3). (for NAM)
$ns duplex-link-op $n2 $n3 queuePos 0.5
#Setup a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
#Schedule events for the CBR and FTP agents
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"
#Detach tcp and sink agents (not really necessary)
68
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Print CBR packet size and interval
puts "CBR packet size = [$cbr set packet_size_]"
puts "CBR interval = [$cbr set interval_]"
#Run the simulation
$ns run
69
OUTPUT:
70
RESULT:
Thus the above program was executed successfully and output was verified.
71