Top Banner
EASWARI ENGINEERING COLLEGE DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LAB MANUAL CS2406 OPEN SOURCE LAB Year/Sem : IV B.E(CSE) /VII Academic Year: 2012-13 PREPARED BY APPROVED BY Mr. Bharathi Raja N HOD/CSE
52
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Open Source Lab Manual

EASWARI ENGINEERING COLLEGE

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

LAB MANUAL

CS2406 OPEN SOURCE LABYear/Sem : IV B.E(CSE) /VII

Academic Year: 2012-13

PREPARED BY APPROVED BY

Mr. Bharathi Raja N HOD/CSE

Page 2: Open Source Lab Manual

CS2406 OPEN SOURCE LAB L T P C 0 0 3 2 OBJECTIVE:

To expose students to FOSS environment and introduce them to use open source packages 1. Kernel configuration, compilation and installation : Download / access the latest kernel source code from kernel.org,compile the kernel and install it in the local system.Try to view the source code of the kernel 2. Virtualisation environment (e.g., xen, kqemu or lguest) to test an applications, new kernels and isolate applications. It could also be used to expose students to other alternate OSs like *BSD

3. Compiling from source : learn about the various build systems used like the auto* family, cmake, ant etc. instead of just running the commands. This could involve the full process like fetching from a cvs and also include autoconf, automake etc., 4. Introduction to packet management system : Given a set of RPM or DEB, how to build and maintain, serve packages over http or ftp. and also how do you configure client systems to access the package repository. 5. Installing various software packages Either the package is yet to be installed or an older version is existing. The student can practice installing the latest version. Of course, this might need internet access.

• Install samba and share files to windows • Install Common Unix Printing System(CUPS)

6. Write userspace drivers using fuse -- easier to debug and less dangerous to the system (Writing full-fledged drivers is difficult at student level)

Page 3: Open Source Lab Manual

7. GUI programming : a sample programme – using Gambas since the students have VB knowledge. However, one should try using GTK or QT 8. Version Control System setup and usage using RCS, CVS, SVN 9. Text processing with Perl: simple programs, connecting with database e.g., MYSQL 10. Running PHP : simple applications like login forms after setting up a LAMP stack 11. Running Python : some simple exercise – e.g. Connecting with MySql database 12. Set up the complete network interface usinf ifconfig command like setting gateway, DNS, IP tables, etc.,

LIST OF EXPERIMENTSEx No. 1 Kernel Configuration, Compilation and InstallationEx No. 2 Virtualisation EnvironmentEx No. 3 Compiling from Source Ex No. 4 Packet Management SystemEx No. 5 Installing Various Software Packages Ex No. 6 FUSE - File System in User SpaceEx No. 7 GUI Programming Using GAMBAS2Ex No. 8 Version Control System Setup and Usage using RCS, CVS, SVNEx No. 9 PERL programmingEx No. 10 PHP with MYSQLEx No. 11 Python programming with MYSQL Ex No. 12 Setting Up The Complete Network Interface

CONTENT BEYOND THE SYLLABUS:1. Sample Django application for displaying “Hello world” message with

Current time.2. Create a new directory named templates in blog directory

Page 4: Open Source Lab Manual

Ex No. 1 Kernel Configuration, Compilation and InstallationAim:To do Download / access the latest kernel source code from kernel.org, compile the kernel and install it in the local system. Also try to view the source code of the kernel.

Algorithm :

1. Check for the current version of the working kernel

$uname -r

2. Download the kernel source code from

wget http://fosslabserver.linuxpert.in/kernel/v2.6/linux-2.6.35.7.tar.gz

3. Extract the kernel source code (through GUI) or terminal

tar zxvf linux-2.6.35.7.tar.gz

4. Inside the kernel source directory, open the Makefile

vi Makefile

5. Look for the line EXTRAVERSION and append a name

ex. 2.6.35.7-mykernel

6. make menuconfig (choose the desired kernel options)

7. make bzImage (builds the kernel)

8. su

9. cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.35.7

10. chmod 755 /boot/vmlinuz-2.6.35.7

11. make modules (builds the kernel modules)

12. make modules_install (installs the kernel modules in the /lib/modules directory)

13. mkinitrd /boot/initramfs-2.6.35.7.img 2.6.35.7-<extra-ver>

Note: check for the newly created directory in the

/lib/modules directory and give the name above

Page 5: Open Source Lab Manual

Ex No. 2 Virtualisation Environment

Aim:

To develop Virtualisation environment (e.g., xen, kqemu or lguest) to test an applications, new kernels and isolate applications.

Algorithm:

Steps for Virtualization using QEMU and FreeDOS

1. Download the fdbasecd.iso from www.freedos.org (or) from fosslab server

The following steps should be followed from the directory where fdbasecd.iso is stored

2. qemu-img create virtualdisk.img 100M

3. qemu -hda virtualdisk.img -cdrom fdbasecd.iso -boot d

4. After booting through QEMU, select 1 to boot from CDROM

5. Select Language - English US

6. Select option to boot FreeDOS from CDROM

7. from X:>fdisk

8. Enable Large disk support (Y)

9. Create DOS partition -> Primary DOS partition

10. Make the whole DOS Primary partition as Active (Y)

Page 6: Open Source Lab Manual

Ex No. 3 Compiling from Source

Aim:

To learn about the various build systems used like the auto* family, cmake, ant etc. instead of just running the commands. This could involve the full process like fetching from a cvs and also include autoconf, automake etc.,

Algorithm:

1. Open terminal2. Check for webattery availability

#rpm –q webattery#which webattery#rpm –e webattery#exit

3. Move to Home/Downloads directory and download webattery package $cd Downloads$rpm –ivh weabattery-1.2.6.f14.src.rpm

4. Move to rpmbuild folder in Home directory and rpmbuild SOURCES folder$cd ..$cd rpmbuild$cd SOURCES

5. Extract webattery package$tar zxvf webattery-1.2.tar.gz

6. Move to webattery-1.2 directory src$cd webattery-1.2$cd src$cd ..

7. Perform configuration $./configure

8. Do make$make

9. Login as superuser$su –

10.Install webattery package#make install

11.Check for webattery package#which webattery

Page 7: Open Source Lab Manual

Ex No. 4 Packet Management System

Aim:To build and maintain RPM or DEB packages, serve packages over http or ftp and also to configure client systems to access the package repository.Algorithm:

1. Go to browser and type http://fosslabserver/pub/tools/internet/qmail

2. Download the qmail-packages.zip to Downloads folder3. Go to Downloads folder and extract qmail-packages.zip4. In the terminal move to Downloads folder which is under home/

fosslab 5. List all the files in the Downloads folder using

$ls –l6. Move the contents of qmail-packages directory to directory qmail

$mv qmail-packages qmail$ls –l

7. Move to qmail directory$cd qmail$ls

8. To see no of rpm packages give the command as follows$ls *.rpm | wc

9. Move again to Downloads folder10. Now create a repository for qmail

$createrepo qmail/11. Next go to qmail directory and check if repodata folder is created

$cd qmail$ls –l

12. Move to repodata folder $cd repodata $ls –l13. Move back to fosslab directory14. Check for the Apache Web Server Status

$service httpd status$service httpd start (if Apache Web Server Status is stopped)$service httpd status

15. Go to browser and type http://localhost

Page 8: Open Source Lab Manual

if the Fedora test page is displayed then Apache Web Server is running

16. Move the qmail packages from home/fosslab/Downloads directory to /var/www/html/ which can be served by Apache Web Server requesting clients$mv /home/fosslab/Downloads/qmail /var/www/html

17.Go to /var/www/html and see if the qmail packages are available$cd /var/www/html$ls –l

18. Next go to browser and type http://localhost/qmail

19. Now we have to create the repository configuration file so that the clients can use the configuration file for installing qmail packages from the server$su#cd /etc/yum.repos.d/#ls –l#vi qmail.repo Type the following lines into the file[qmail]name=Q-Mail packagesbaseurl=http://localhost/qmailenabled=1gpgcheck=0save the file :wq

20. View the qmail.repo file#cat qmail.repo

21. Now we have to rebuild the YUM Cache, so that YUM package manager includes the qmail package information#yum clean all#yum makecache

22.Now check if qmail packages are included#yum search qmail

23.Now install qmail toaster#yum install qmailtoaster-plus #yum install libsrs2-toaster

YUM fedora.repo, fedora-updates.repo

1. Login as superuser and move to /etc/yum.repos.d/$su#cd /etc/yum.repos.d

Page 9: Open Source Lab Manual

#ls –l2. Edit fedora.repo file

#vi fedora.repoMake the following changesAdd # before ‘mirrorlist’ in line 5Add the following line at line 7baseurl=http://fosslabserver/f14repo/save the file

3. Edit fedora-updates.repo#vi fedora-updates.repoChange enabled=0 and save the file

4. Now we have to rebuild YUM cache#yum clean all#yum makecache

5. List repo groups#yum grouplist

6. Now install “XFCE”#yum groupinstall “XFCE”

7. Now install kernel#yum install kernel

rpmfusion-free.repo, rpmfusion-nonfree

1. In the browser typehttp://fosslabserver/f14repo/rpmfusion/i386/freefind the file rpmfusion-free-release-14.0.4.noarch.rpm and copy the path

2. In the terminal login as superuser $su

3. N o w y o u h a v e t o i n s t a l l t h e r p m f u s i o n - f r e e -release-14.0.4.noarch.rpm by pasting the path after rpm#rpm –ivh http://fosslab/f14repo/rpmfusion/i386/free/rpmfusion-free-release-14.0.4.noarch.rpm

4. N e x t y o u h a v e t o i n s t a l l t h e r p m f u s i o n - n o n f r e e -release-14.0.4.noarch.rpm by pasting the path after rpm#rpm –ivh http://fosslab/f14repo/rpmfusion/i386/free/rpmfusion-nonfree-release-14.0.4.noarch.rpm

5. Move to /etc/yum.repos.d/$cd /etc/yum.repos.d/

6. Edit rpmfusion-free.repo#vi rpmfusion-free.repoAdd # before ‘mirrorlist’ in line 4

Page 10: Open Source Lab Manual

Add the following line at line 6baseurl=http://fosslabserver/f14repo/rpmfusion/i386/freesave the file

7. Edit rpmfusion-free-updates.repoChange enabled=0 and save the file

8. Edit rpmfusion-nonfree.repoAdd # before ‘mirrorlist’ in line 4Add the following line at line 6baseurl=http://fosslabserver/f14repo/rpmfusion/i386/nonfree/save the file

9. Edit rpmfusion-nonfree-updates.repoChange enabled=0 and save the file

10.Now we have to rebuild YUM cache#yum clean all

#yum makecache11. Now check if packages are included

#yum search vlc12.Next install vlc

#yum install vlc*

Page 11: Open Source Lab Manual

Ex No. 5 Installing Various Software Packages

Aim:To install samba and share files to windows and also install Common Unix Printing System (CUPS)

Algorithm:

CUPS

1. Check for existence of CUPS$rpm –qa | grep cups$rpm –qi cups

2. Check if CUPS is running #service cups status

3. Open firefox and type the following#open firefox

http://localhost:631/

under CUPS for administrators select Adding Printers and Classes

4. Under Printers select Add Printer and give username and passwordUsername : rootPasswd: admin123

5. Under Add Printer select HP Printer (HPLIP) and click on continue6. Then give the connection as

http://localhost:631/ipp/ and click on continue

7. Give a name for the printer(HP1010), description(HP1010 LaserJet Printer) and location (Lab 1) and click on continue.

8. Select the make as HP and click on continue.9. Select the model (HP LaserJet 1010 Foomatic/hpijs (en) and click

on Add Printer10.After printer is added change the page size as A4 and click on set

default properties11.In the next page click on HP101012.Select print test page from Maintenance 13.Click on show all jobs

Page 12: Open Source Lab Manual

SAMBA

I Stage 1 (Linux)

1. Check if SAMBA is installed and working$rpm –qa | grep cups$su#service smb status#service smb start (if samba was in stopped state)#service smb status

2. Check if network message block is running#service nmb status#service nmb start (if samba was in stopped state)#service nmb status

3. View the ip table#iptables –L

4. Stop the iptables service#service iptables stop

5. View the ipv6 table#ip6tables –L

6. Stop the iptables service#service ip6tables stop

7. Check enforce status#getenforce#setenforce (to enable enforce)#setenforce 0

8. Add winuser and set samba password for the winuser#useradd winuser#smbpasswd –a winuser#service smb status# service nmb status

II Stage 2 (Windows)

1. Go to run and type the ip of your linux box\\192.168.1.43 (for example)

2. Give the password which you assigned to winuser in linux3. Create some folders in the linux login

III Stage 3 (Linux)1. Login as winuser

Page 13: Open Source Lab Manual

2. Go to places home folder and check if the folders created in windows is available

IV Stage 4 (Linux)1. Login open source lab\2. Go to places home folder3. Press CTRL+L and type

smb://192.168.1.252 (ip address of the windows machine)4. Login as administrator5. Create some folders and try viewing in linux box

Page 14: Open Source Lab Manual

Ex No. 6 FUSE - File System in User Space

Aim:

To write userspace drivers using fuse -- easier to debug and less dangerous to the system

Algorithm:

1. Check whether FUSE is installed$rpm –qa | grep fuse$rpm –qi fuse

2. Open browser and type the followinghttp://fosslabserver.linuxpertsystem.in/osslab/samples/fuse.gzdownload fuse.gz

3. Go to Places Downloads and extract fuse.gz (or)Do the following$wget http://fosslabserver.linuxpertsystem.in/osslab/samples/fuze.gz$tar zxvf fuse.gz

4. Go to terminal then move to home/fosslab/Downloads5. Extract fusetutorial.gz and move to that directory6. Next move to src directory7. Look for bbfs.c file and view it8. Then look for log.c and view it9. Now try to fuse cflags

$pkg-config fuse --cflags10.Then fuse libs

$pkg-config fuse --libs11. Perform makefile

$make12. Look for bbfs file (coloured green)13. Move to examples folder

$cd ../examples14. View the mountdir and rootdir directories

$ls –al mountdir$ls –al rootdir

15. Move to rootdir folder and create some empty files$cd rootdir/$touch myfile

Page 15: Open Source Lab Manual

$ls –l16. Move back to examples folder and check the no of files in

mountdir$cd ..$ls –l mountdir

17.Check the files in rootdir/$ls –l rootdir/

18.Now call the fuse bbfs$ ..src/bbfs rootdir/ mountdir/

19.Now check the no of files under mountdir/$ls –l mountdir/

20. Now mount the filesystem to see the fuse working$mount

21. Next unmount the fuse and check for the no of files in mountdir/$fusermount –u mountdir/$ls –l $mount

$tail –f bbfs.log

Page 16: Open Source Lab Manual

Ex No. 7 GUI Programming Using GAMBAS2

Aim:

To create a login form for booking train ticket using GAMBAS2 Algorithm:

1. Go to Applications Programming2. Under Programming Gambas23. In the Gambas2 environment select New Project4. Next select the location of the project to be created5. In the next step give a name for your project6. Now after your project is created you have to create forms for

your project7. The different tools are available under the toolbox8. Add the appropriate tools to your form9. Next add the appropriate code for the different controls placed

on the form10.Save the project11.Run the project

Page 17: Open Source Lab Manual

Ex No. 8 Version Control System Setup and Usage using RCS, CVS, SVNAim:To do Version Control System setup and usage using RCS, CVS, SVNAlgorithm:

1. Check for SVN status$rpm –qa | grep subversion

2. Check for java / jre installed status$rpm –qa | grep java

3. Go to browser and type http://fosslabserver/tools/development/svnedge

4. Download CollabNetSubversionEdge-1.3.2_linux-x86_64.tar.gz to downloads folder

5. G o t o P l a c e s D o w n l o a d s a n d e x t r a c t CollabNetSubversionEdge-1.3.2_linux-x86_64.tar.gz

6. Login as superuser and edit sudo $su –#visudo

7. In the visudo file add the following line after line no 77 (to insert line no type :se nu)fosslab ALL=(ALL) ALL

8. Check for java version$java –version$which java

9. Set the environmental variables$export JAVA_HOME=/usr$JAVA_HOME/bin/java –version

10. Move to fosslab/Downloads directory$cd fosslab$cd Downloads

11.Move to csvn directory$cd csvn

12.Install CSV$sudo –E bin/csvn install

13. Start bin/csvn service $bin/csvn start

14.Check for bin/csvn console status$bin/csvn console

15.Type the following address in browser and check http://localhost:3343/csvn

Page 18: Open Source Lab Manual

16. Give the user and password17. Click on Administration link and change port to 8888 and

Administrator as admin and also give admin email id18. Click on Save19. Click on status link and start the subversion edge20. Install the webattery package as given in exercise 321. Go to http://localhost:3343/csvn and give username and

password22. Under repositories link click on new repository23. Give the name of repository as webattery and click on create24. Click on repository list link to view the repository added25. Copy the text next to webattery26. Go to terminal and make directory subversion-test

$mkdir subversion-test27. Move the subversion-test folder28. Paste the text which you copied which was next to webattery29. Give username and password

Page 19: Open Source Lab Manual

Ex No. 9 PERL programming

Aim:To demonstrate the PERL program connectivity with MySQL databaseAlgorithm:

1. Sample PERL#!usr/bin/perl # the above line is shebang directive$name=<STDIN>;chomp($name);print "$name\n";output:[linuxpert@localhost ~]$ perl first.plHello WorldHello World2. Scalar variables in PERL#!/usr/bin/perlmy $animal="Camel"; # this variable is lexically scoped ie localmy $ans=42_243; #this is similar to 42243print "$animal\n";print "$ans\n";print "The square of &ans",$ans*$ans,"\n";output:[linuxpert@localhost ~]$ perl scalar.plCamel422433. Array in PERL#!usr/bin/perlmy @animal=("cow","Buffalo","Camel");print "@animal\n"; # list all elements in arrayprint "$#animal\n"; # list last element positionprint "$animal[0]\n"; #list 0th position element$count=@animal;print "$count"; # count no of elements in arrayoutput:[linuxpert@localhost ~]$ perl array.plcow Buffalo Camel2cow34. Hash in PERL

Page 20: Open Source Lab Manual

#!usr/bin/perl%color=('apple'=>"red",'banana'=>"yellow",'orange'=>"orange");print "$color{'apple'}\n";output:[linuxpert@localhost ~]$ perl hash.plred5. To display all values in hash#!usr/bin/perl%color=('apple'=>"red",'banana'=>"yellow",'orange'=>"orange");print "$color{'apple'}\n";# to display all the values in hash@keys=keys %color;foreach $key (@keys){print "$color{$key}\n";}output:[linuxpert@localhost ~]$ perl hashvalues.plredyellowredorange6.for delection of Hash values#!usr/bin/perl%color=('apple'=>"red",'banana'=>"yellow",'orange'=>"orange");print "$color{'apple'}\n";# to display all the values in hash@keys=keys %color;@values=values %color; # it ill store the array valuesforeach $key (@keys){print "$color{$key}\n";}delete $color{'apple'}; # to remove specific key7.If loop in perl#!usr/bin/perlmy $a=10;$condition=1;if($condition){my $y=100;

Page 21: Open Source Lab Manual

print "$a\n";print "$y\n";}print "$a\n";print "$y\n";output:[linuxpert@localhost ~]$ perl ifloop.pl10100108. If not loop (unless)in perl#!usr/bin/perl$a=5;unless($a>10) #is equal to if not{print "a less than 10";}output:[linuxpert@localhost ~]$ perl unless.pla less than 109. While loop (until) in perl#!usr/bin/perl$a=0;until($a>10) #is equal to while{print "$a\n";$a++;}out put:[linuxpert@localhost ~]$ perl unless.pla less than 10[linuxpert@localhost ~]$ perl until.pl0123456789

Page 22: Open Source Lab Manual

1010. for each loop (upper limit is not fixed )in perl#!usr/bin/perlmy @animals=("cow","buffalo","camel",123,100,243,300);foreach $key(@animals){print "$key\n";}output:[linuxpert@localhost ~]$ perl foreach.plcowbuffalocamel12310024330011. String operation:#!usr/bin/perl$a="hello";$b="world";print $a.$b,"\n";$str="-";print $str x 80,"/n";@a=(10..25);print "@a\n";output[linuxpert@localhost ~]$ perl string.plhelloworld--------------------------------------------------------------------------------/n10 1112 13 14 15 16 17 18 19 20 21 22 23 24 2512. Hard reference variable:12.1 Reference variable(scalar)#!usr/bin/perl$a=100;$b=\$a;print "$b\n";output:[linuxpert@localhost ~]$ perl reference.plSCALAR(0x9506a68)12.2 De reference the variable(scalar variable)

Page 23: Open Source Lab Manual

#!usr/bin/perl$a=100;$b=\$a;print "$$b\n";output:[linuxpert@localhost ~]$ perl reference1.pl10012.3 Array reference variable#!usr/bin/perl@arr=('hello','122','200','Hello');$c=\@arr;print "$c\n"; # print the addressprint "@$c\n"; # print the values of arrayprint "$c->[1]\n"; #point the specified location in array, to access the singleelementoutput:[linuxpert@localhost ~]$ perl arrayvariable.plARRAY(0x8358a70)hello 122 200 hello12212.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;print "@keys\n"; #it contains the key valueprint "$h->{'apple'}\n"; # it print the the apple aloneoutput:[linuxpert@localhost ~]$ perl hashvariable.plHASH(0x830da70)banana apple orangered12.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 the apple alone

Page 24: Open Source Lab Manual

foreach (@keys){print "$h->($_}\n"; # to display all key values we use $_ instead of keys}output:[linuxpert@localhost ~]$ perl hashvariable1.plHASH(0x8df4a70)redHASH(0x8df4a70)->(banana}HASH(0x8df4a70)->(apple}HASH(0x8df4a70)->(orange}13 .Function#!usr/bin/perlsub sayHello(){print "Hello\n";}&sayHello();output:[linuxpert@localhost ~]$ perl function.plHello13.1 function with parameter#!usr/bin/perlsub add(){my ($a,$b)=@_; #the values will be stored in @_ array variable fordynamicallyprint $a+$b;}&add(10,15);output:[linuxpert@localhost ~]$ perl functionparam.pl2513.2 Find Maximum value using function#!usr/bin/perlsub max(){$max=shift @_; # shift function remove the first element in array and theremaining element will be stored in $maxforeach $v (@_) # $v is the second values in the @_

Page 25: Open Source Lab Manual

{$max=$v if $max<$v;}return $max;}$d=&max(10,278,1050,76,800,246,76,345);print "The maximum value is $d\n";output:[linuxpert@localhost ~]$ perl functionparam.plThe maximum value is 105014. Symbolic referenceThat 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;};$a=&$b(20,30);#De reference the functionprint "the product is $a\n";output:[linuxpert@localhost ~]$ perl symbolicref.plthe product is 60014.program to check greater among 3 number#Greatest among 3 numberprint "Enter A value : ";$a=<>;print "Enter b value : ";$b=<>;print "Enter c value : ";$c=<>;if(($a > $b)&&($a > $c)){print "A is greater";}elsif(($b > $c)&&($b > $a)){print "B is greater";}

Page 26: Open Source Lab Manual

else{print "C is greater";}15.Program to get details in run time#! usr/bin/perlprint "Enter the Student Information";print "\n enter name";chomp($name = <>);print "\nenter dob";chomp($dob=<>);print "\n enter registerno.";chomp($registern0.=<>);print "\n enter education";chomp($Education=<>);print "\n Student Information";print "\n Name: $name";print "\n Date Of Birth :$dob";print "\n Register no.:$registern0.";print "\nQualification :$Education";16. Program to perform array releted function#!/usr/bin/perl# Define an array@coins = ("aaa","bbb","ccc");#Array can be represent using qw format#Display all Elements in Arrayprint "Array Elements";print "\n First Statement : @coins";print "\n";# Add elements at the end of the arrayprint "\nPush Function";push(@coins,qw/ddd eee fff ggg/);push(@coins, "Penny","priya");print "\n Second Statement : @coins";print "\n";# Add one element at the beginning of the arrayprint "\n Unshift Function";unshift(@coins, "Dollar");print "\n Third Statement : @coins";print "\n";# Remove one element from the last of the array.

Page 27: Open Source Lab Manual

print "\n Pop Function";pop(@coins);print "\nFourth Statement : @coins";print "\n";# Remove one element from the beginning of the array.print "\n Shift Function";shift(@coins);print "\nFifth Statement : @coins";print "\n";print "@coins";#splice function,you can delete or replace elements within the array.#delete one element at index 1print "\n Using Splice Function";@browser = ("System", "Logic", "Solutions");print "\n @browser";print "\n";#replacing elements at index 1,2@browser = ("System", "Logic", "Solutions");splice(@browser, 1, 2, "Helios", "Matheson");print "\n @browser";17. Program to perform Sub-routine to check biggest numberExample 1:sub maximum{if ($_[0] > $_[1]){print $_[0];}else{print $_[1];}}$biggest = &maximum(37, 24);Example 2:sub maximum{if ($_[0] > $_[1]){$_[0];}

Page 28: Open Source Lab Manual

else{$_[1];}}$biggest = &maximum(37, 24);$biggest2 =&maximum(100,123);print "\nThe biggest amomg 37 and 24 is $biggest";print "\nthe biggest among 100 and 123 is $biggest2";3.Program to return the valuessub get_list{return 5..10;}@list = &get_list;print "@list";18. Program to Open the File# < indicate that file has to be opened in read-only mode# > sign indicates that file has to be opened in writing modeEntities Definition< or r Read Only Access> or w Creates, Writes, and Truncates>> or a Writes, Appends, and Creates+< or r+ Reads and Writes+> or w+ Reads, Writes, Creates, and Truncates+>> or a+ Reads, Writes, Appends, and CreatesSample:#!/usr/bin/perlopen(DATA, "<sample.txt");while(<DATA>){print "$_";}19. Example which opens an existing file file1.txt and read itline by line and generate another copy file2.txt#!/usr/bin/perl# Open file to readopen(DATA1, "<file1.txt");# Open new file to writeopen(DATA2, ">file2.txt");# Copy data from one file to another.

Page 29: Open Source Lab Manual

while(<DATA1>){print DATA2 $_;}close( DATA1 );close( DATA2 );#delete a file file3.txt using unlink functionunlink ("/strawberry/perl/file3.txt");20.Program to returns the key intersection of two hashessub intersection{my ($hasha, $hashb) = @_;my %newhash;foreach my $key (keys %{$hasha}){$newhash{$key} = $$hasha{$key} if (exists $$hashb{$key});}return %newhash;}%hasha = ( 'a' => 'b','b' => 'b','c' => 'b');print %hasha;print "\n";%hashb = ( 'b' => 'b','c' => 'b','d' => 'b');print %hashb;print "\n";%newhash = intersection(\%hasha, \%hashb);print "\n";print %newhash;21. Print out lines of other files with the use of arrays#!/usr/bin/perlprint "content-type: text/html \n\n"; #The header$text = "sample.txt";open (text) or die "Can't open the file!";@fileinput = <text>;print $fileinput[0];print $fileinput[1];print $fileinput[2];

Page 30: Open Source Lab Manual

print $fileinput[3];print $fileinput[4];print $fileinput[5];print $fileinput[6];print $fileinput[7];print $fileinput[8];print $fileinput[9];close (text);22. PERL - Copying FileWe can duplicate a file using the copy function. Copy takes two values theURL of the file to be copied and the URL of the new file. Since we want toduplicate the file in this example22.1 Example for copying and moving and delete function#!/usr/bin/perluse File::Copy;print "\n Copying the content present from file1 to file2";$filetobecopied = "file1.txt";$newfile = "file2.txt";copy($filetobecopied, $newfile) or die "File cannot be copied.";print "\n Now open the new file";print "\n Move function";$oldlocation = "sample.txt";$newlocation = "f:/keerthi/sample.txt";move($oldlocation, $newlocation);# unlink function to delete specific files from your web server.print "\n Delete function";$file = "F:/keerthi/sample.txt";if (unlink($file) == 0){print "\nFile deleted successfully.";}else{print "\nFile was not deleted.";}

APPLICATION USING PERL1.create the table in perl that will be automatically updated indatabase using mysql

Page 31: Open Source Lab Manual

1.1 First create the database as follows in mysql[linuxpert@localhost ~]$ mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.1.45 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || test |+--------------------+3 rows in set (0.25 sec)mysql> create database student;Query OK, 1 row affected (0.02 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || student || test |+--------------------+4 rows in set (0.00 sec)mysql> use student;Database changedmysql> connect;Connection id: 3Current database: studentmysql> show tables;Empty set (0.00 sec)now the table is empty . To create the table we use the following procedure1.2 The following packages should be used to connect PERL with Mysql(use new terminal)[linuxpert@localhost ~]$ rpm -q perl-DBI

Page 32: Open Source Lab Manual

perl-DBI-1.609-4.fc13.i686[linuxpert@localhost ~]$ rpm -q perl-DBD-MySQLperl-DBD-MySQL-4.013-3.fc13.i6861.3 Write the PERL script to connect with mysql as follows#!usr/bin/perluse DBI; #to use the build in package we use "Use", DBI is the build inpackage in perlmy $dbh=DBI->connect("dbi:mysql:student","root",""); #connect todatabaseif(!$dbh){die("error:$!");}$sth=$dbh->prepare("create table students(rollno int,sname varchar(50))");# create the table$sth->execute();$dbh->disconnect;

1.4 Run the Perl script[linuxpert@localhost ~]$ perl connect.plnow see the tables in database (“student”)mysql> show tables;+-------------------+| Tables_in_student |+-------------------+| students |+-------------------+1 row in set (0.00 sec)2. insert the values in perl that will be automatically updated indatabase using mysql as follows#!usr/bin/perluse DBI; #to use the build in package we use "Use", DBI is the build inpackage in perlmy $dbh=DBI->connect("dbi:mysql:student","root",""); #connect todatabaseif(!$dbh){die("error:$!");}

Page 33: Open Source Lab Manual

$sth=$dbh->prepare("insert into students values(100,'thamarai')"); # createthe table$sth->execute();$dbh->disconnect;2.1 compile the perl[linuxpert@localhost ~]$ perl dbinsert.plnow the output ismysql> select * from students;+--------+----------+| rollno | sname |+--------+----------+| 100 | thamarai |+--------+----------+1 row in set (0.00 sec)2.2 insert the values in perl using execute statement#!usr/bin/perluse DBI; #to use the build in package we use "Use", DBI is the build inpackage in perl$rollno=200;$sname="selvi";

my $dbh=DBI->connect("dbi:mysql:student","root",""); #connect todatabaseif(!$dbh){die("error:$!");}$sth=$dbh->prepare("insert into students values(?,?)"); # create the table$sth->execute($rollno,$sname);$dbh->disconnect;compile the program as[linuxpert@localhost ~]$ perl dbinsert1.plnow the output ismysql> select * from students;+--------+----------+| rollno | sname |+--------+----------+| 100 | thamarai || 200 | selvi |

Page 34: Open Source Lab Manual

+--------+----------+2 rows in set (0.08 sec)

CGI PROGRAMMINGEXAMPLE -1type the following in terminal[linuxpert@localhost ~]$ suPassword:[root@localhost linuxpert]# cd /var/www/cgi-bin[root@localhost cgi-bin]# gedittype the following in gedit#!/usr/bin/perluse CGI;$cgi=new CGI;print $cgi->header,$cgi->start_html,$cgi->h1("A simple Example"),$cgi->end_html;type the following in the same terminal[root@localhost cgi-bin]# chmod +x form.cgigo to browser and type the following URLhttp://localhost/cgi-bin/form.cgiU will get the output asEXAMPLE -2in terminal[linuxpert@localhost ~]$ suPassword:[root@localhost linuxpert]# cd /var/www/html[root@localhost html]# gedittype the following in gedit editor<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>

Page 35: Open Source Lab Manual

<p>"click here to submit"<input type="submit" name="submit"></p></form></body>save the page as form.html & close ittype the following URL in browserhttp://localhost/form.html

then type the following in the terminal[root@localhost html]# cd /var/www/cgi-bin[root@localhost cgi-bin]# gedittype the following in gedit#!/usr/bin/perluse 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.cgiclose that file & open a same terminal type as[root@localhost cgi-bin]# chmod +x form2.cgiIn new browser type the followinghttp://localhost/form.htmlwe get the screen asnow check the database asmysql> select * from students;+--------+---------------+| rollno | sname |+--------+---------------+| 100 | thamarai || 200 | selvi |

Page 36: Open Source Lab Manual

| NULL | abcd || 71 | thamaraiselvi |+--------+---------------+4 rows in set (0.00 sec)

Page 37: Open Source Lab Manual

Ex No. 10 PHP with MYSQL

Aim:To create a login form and test the connectivity with MYSQL

Algorithm:

1. linuxpert@localhost ~]$ suPassword: admin123[root@localhost linuxpert]# cd /var/www/html[root@localhost html]# gedit2. type the following in gedit and save it as form.html<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>

3. 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";}?>4. Type the following in the browserhttp://localhost/form.html

Page 38: Open Source Lab Manual

5. Now go to terminal[linuxpert@localhost ~]$ mysql -u root -p\> > Enter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 28Server version: 5.1.45 Source distributionmysql> 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 namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> connectConnection id: 29Current database: studentmysql> 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)

Page 39: Open Source Lab Manual

Example 2. Create Login Page1 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>2 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 databse.

Page 40: Open Source Lab Manual

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 WHEREusername='$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 mustbe 1 rowif($count==1)echo "Welcome To Our Web Page";elseecho "Wrong Username or Password";?>

Page 41: Open Source Lab Manual

Ex No. 11 Python programming with MYSQL

Aim:

To demonstrate the Python program connectivity with MYSQL

Algorithm:

1. Write a Hello World Python ProgramCreate helloworld.py program as shown below.$ vim helloworld.py#!/usr/bin/python# Hello world python programprint "Hello World!";2. Verify Python Interpreter AvailabilityMake sure python interpreter is installed on your system as shownbelow.$ whereis pythonpython: /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/python3. Execute Python ProgramYou can either execute using “python helloworld.py” or“./helloworld.py”.$ python helloworld.pyHello World!( or )$ chmod u+x helloworld.py$ ./helloworld.pyHello World!Note: As python is an interpreted language, you don’t have the compilationstep similar to the C program.4. Write a sample program in python programming#Sample python program

Page 42: Open Source Lab Manual

x=5;y=5;print ("x:",x);print("y:",y);z=x+y;print("z:",z);5. String Concatenation in python programming#String concatenationworda='computer';wordb='science';print("worda is ",worda);print("wordb is",wordb);wordc=worda+" " +wordb;print("wordc is",wordc);wordd=worda*3;print("wordd is ",wordd);str = 'HelloWorld!'length=len(str);print ("str :",str);print("length:",length);print ("first character is",str[0]);print ("print character from 2rd to 6th :", str[2:7] );print ("Prints string starting from 3rd character:",str[2:]);print ("Prints string two times",str * 2);print ("Prints concatenated string :",str + "TEST" );print(str[-1]); #print last characterprint(str[-6]);#print character from last 6th positionprint(str[:-2]);# Everything except the last two characters6. Write a python program to perform function in Lists#Python Lists#!/usr/bin/pythonprint("\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:3]);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

Page 43: Open Source Lab Manual

print("Before modifying the 4th element in list :",list[4]);list[4]='efgh';print("4th element in list :",list[4]);print(" complete list:",list);#Appending new elementslist.append('ijkl');print("After appending list:",list);#deleting an element in listdel list[2];print("List :",list);7. Write a python program to perform functions in tuples#Python Tuplesprint("\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 );print ("concatenated tuple:",tuple + tinytuple );8. Write a python program to perform functions in Dictionary.#Python Dictionarytinydict = {'name': 'john','code':6734, 'dept': 'sales'}print ("Python Dictionary:" );print ("complete dictionary",tinydict );print ("Key :",tinydict.keys()); # Prints all the keysprint ("values:",tinydict.values()); # Prints all the values9. Write a python Program to select odd number from the lists#!/usr/bin/python#program to select odd number from the lista=[11,12,13,14,15,16,17,18,19,20,21,31,44,45,10];print("List is:",a);n=len(a);print("length:",n);i=0;print("Odd number");for i in range(len(a)):if(a[i]%2==1):print(a[i]);10. Conditional statement in Python

Page 44: Open Source Lab Manual

>>> x = int(raw_input("Please enter an integer: "))>>> if x < 0:... x = 0... print 'Negative changed to zero'... elif x == 0:... print 'Zero'... elif x == 1:... print 'Single'... else:... print 'More'11. For Statement in Python>>> # Measure some strings:... a = ['cat', 'window', 'defenestrate']>>> for x in a:... print x, len(x)cat 3window 612. The Range() and Len() in Python>>> a = ['Mary', 'had', 'a', 'little', 'lamb']>>> for i in range(len(a)):... print i, a[i]...OUTPUT:0 Mary1 had2 a3 little4 lamb13. Prime Number using Python.>>> for n in range(2, 10):... for x in range(2, n):... if n % x == 0:... print n, 'equals', x, '*', n/x... break... else:... # loop fell through without finding a factor... print n, 'is a prime number'..OUTPUT:2 is a prime number3 is a prime number

Page 45: Open Source Lab Manual

4 equals 2 * 25 is a prime number6 equals 2 * 37 is a prime number8 equals 2 * 49 equals 3 * 314. 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 159715. Set operations in Python>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']>>> fruit = set(basket) # create a set without duplicates>>> fruitset(['orange', 'pear', 'apple', 'banana'])>>> 'orange' in fruit # fast membership testingTrue>>> 'crabgrass' in fruitFalse>>> # Demonstrate set operations on unique letters from two words...>>> a = set('abracadabra')>>> b = set('alacazam')>>> a # unique letters in aset(['a', 'r', 'b', 'c', 'd'])>>> a - b # letters in a but not in bset(['r', 'd', 'b'])>>> a | b # letters in either a or bset(['a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'])>>> a & b # letters in both a and bset(['a', 'c'])>>> a ^ b # letters in a or b but not bothset(['r', 'd', 'b', 'm', 'z', 'l'])16. Modules And Error Handling In Python

Page 46: Open Source Lab Manual

import systry: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]raise17.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 2executing finally clause>>> divide(2, 0)division by zero!executing finally clause>>> divide("2", "1")executing finally clauseTraceback (most recent call last):File "<stdin>", line 1, in ?File "<stdin>", line 3, in divideTypeError: unsupported operand type(s) for /: 'str' and 'str'18. Simple Class Program in python>>> class Complex:... def __init__(self, realpart, imagpart):... self.r = realpart... self.i = imagpart...

Page 47: Open Source Lab Manual

>>> x = Complex(3.0, -4.5)>>> x.r, x.i(3.0, -4.5)19. Module Program in Python (Fibonacci Series)A module is a file containing Python definitions and statements. Thefile name is the module name with the suffix .py appended. Within amodule, the module’s name (as a string) is available as the value of theglobal variable __name__. For instance, use your favorite text editor tocreate a file called fibo.py in the current directory with the followingcontents:Step 1:Fibo.pydef fib(n): # write Fibonacci series up to na, b = 0, 1while b < n:print b,a, b = b, a+bStep 2:>>> import fiboStep 3:>>> fibo.fib(1000)1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

Page 48: Open Source Lab Manual

Ex No. 12 Setting Up The Complete Network Interface

Aim:

To set up the complete network interface using ifconfig command like setting gateway, DNS, IP tables.

Algorithm:

ifconfig1. Check for network manager status

$service NetworkManager status2. Login as superuser

$su –3. Check ip address and note it down

#ifconfig4. Now stop the network manager service

#service NetworkManager stop#ifconfig

5. Next stop the local network service also#service network stop#service network#ifconfig

6. Check network status#service network status

7. Now configure ip address#ifconfig eth0 192.168.1.12 netmask 255.255.255.0#ifconfig

8. Next enable the loop up#ifconfig lo up

9. Try stopping network service again#ifdown eth0#ifconfig

10. Bring up the network service#ifconfig eth0 up#ifconfig

11. Repeat step 7 for setting ip address

Note : The ip address which u set must be unique. U can set the ip address which you have noted down in the beginning of the exercise.

Page 49: Open Source Lab Manual

Gateway

1. Check for existing gateway#route –n

2. Delete default gateway#route del default

3. Add default gateway again#route add default gw192.168.1.1#route –n

Domain Name Server (DNS)

1. Edit resolv.conf file and add the below lines#vi /etc/resolv.conf

nameserver 192.168.1.173 nameserver 4.2.2.2 #ifconfig #route –n

2. Check the resolv.conf file#cat ../etc/resolv.conf

Configuring eth0

1. Open eth0 configuration file#vi /etc/sysconfig/network-scripts/ifcfg-eth0

2. Edit the following linesBOOTPROTO=”static”(below onboot edit the following lines)IPADDR=192.168.1.12 (use ur ip add)NETMASK=255.255.255.0NETWORK=192.168.1.0

#ifconfig3. Start the eth0 service

ifup eth0#ifconfig#route –n

4. Edit the network file under /etc#vi /etc/sysconfig/networkAdd the following line

Page 50: Open Source Lab Manual

GATEWAY=192.168.1.1725. Now restart network service

#service network restart#ifconfig#route –n

Page 51: Open Source Lab Manual

CONTENT BEYOND THE SYLLABUS:

1. Sample Django application for displaying “Hello world” message with Current time.

2. Create a new directory named templates in blog directory

Introduction

Django is an web application framework, written in Python, which follows the Model-View-Controller (MVC) Pattern. It is named after Django Reinhardt, a gypsy jazz guitarist from the 1930sto early 1950s. To this day, he’s considered one of the best guitarists of all time. Django is pronounced JANG-oh. Rhymes with FANG-oh. It was originally developed to manage several news-oriented sites for The World Company of Lawrence, Kansas, etc., and was released publicly under BSD license by July 2005. In June 2008, It was announced that a newly formed Django Software Foundation will take care of Django in the future.

The Django framework components

Object-relational mapperDefine your data models entirely in Python. You get a rich, dynamic database-access API for free —but you can still write SQL if needed.

Automatic admin interfaceSave yourself the tedious work of creating interfaces for people to add and update content. Django does that automatically, and it's production-ready.

Elegant URL designDesign pretty, cruft-free URLs with no framework-specific limitations. Be as flexible as you like.

Template systemUse Django's powerful, extensible and designer-friendly template language to separate design, content and Python code.

Cache systemHook into memcached or other cache frameworks for super performance — caching is as granular as you need.

InternationalizationDjango has full support for multi-language applications, letting you specify translation strings and providing hooks for language-specific functionality.

The Programs

Page 52: Open Source Lab Manual

3. Sample Django application for displaying “Hello world” message with Current time.

Create a project# Get into project folder which you created now.# Note:When you run django-admin.py startproject mysite, Django will automatically create a new directory containing four files:

* __init__.py, which will be empty. This file is required to tell Python that the directory is a Pythonmodule and can be imported (and imported from).* manage.py, which provides a number of convenience functions for working with the project.* settings.py, which will be the project’s settings file.* urls.py, which will be the project’s root URL configuration.Next you could check the project whether you have installed successfully or not by running thedjango's inbuilt development server named runserver

Now open the url http://127.0.0.1:8000/ in your browser. You will get the following output.

Create an applicationGet into project “mysite”. And create an application#

Note:When you run django-admin.py startapp web, Django creates a sub-directory of your projectdirectory, and creates the following files:web/__init__.pymodels.pytests.pyviews.py__init__.py, which serves the same purpose as at the project level.models.py, which should hold the application’s model classes.views.py, which is for any custom views the application wants to provide.

Create a new directory named templates in blog directory# Get into project folder which you created now.

*********