Upload
samueljamespeter
View
151
Download
3
Tags:
Embed Size (px)
DESCRIPTION
New Cs77 Open Source Lab Manual
Citation preview
By- Mr.I.Samuel Peter James
CS77 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. Virtualization 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 user space drivers using fuse -- easier to debug and less dangerous to the system
(Writing full-fledged drivers is difficult at student level)
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 liek setting gateway,
DNS, IP tables, etc.,
RESOURCES:
An environment like FOSS Lab Server (developed by NRCFOSS containing the various
packages)
OR
Equivalent system with Linux distro supplemented with relevant packages
Note:
Once the lists of experiments are finalized, NRCFOSS can generate full lab manuals complete
with exercises, necessary downloads, etc. These could be made available on NRCFOSS web
portal.
By- Mr.I.Samuel Peter James
SL.NO EXPERIMENTS NAME
1. Basic UNIX Command
2. Installation Of Common Unix Printing System (Cups)
3. Creating A Program To Perform Virtualization Using Qemu
4. Compiling Software From Source
5a Implementation Of Complex Number Using Python Program
5b Implementation Of Python Program To Print String In Reverse Order
5c Program To Find Biggest Of The Numbers
5d Program To Display Fibonacci Series
6a Program To Display * Using For
6b Program For Function With Multiple Return Values
6c Module Program In Python
6d Program To Display Time
7a Program To Find Arithmetic Operation
7b Program To Calculate The Average Wind Speed Of The Day Using Data Specified
In Task 3
7c Program To Find The First Factorial That Has More Than 100 Digits
7d Program To Find That Prints Prime Numbers Less Than 20.
7e Program To Find The Function That Returns The Smallest And Largest Element In
A List.
8a Program To Accept Input From User
8b Program To Connect Python And MYSQLDB
8c Program To Perform Operator Overloading
9a Program To Greater Among Three Number
9b Program To Display The Name.
9c Program To Create Scalar Variables In Perl.
9d Program To Create Array In Perl.
9e Program To Display All Values In Hash.
9f Program To Delection Of Hash Values.
10 Connection Between The PHP Program And The Database MYSQL
11 Create Login Page Using The PHP Program And The Database MYSQL
By- Mr.I.Samuel Peter James
INTRODUCTION
The free software movement was launched in 1983. In 1998, a group of individuals
advocated that the term free software should be replaced by open source software (OSS) as
an expression which is less ambiguous and more comfortable for the
corporate world. Software developers may want to publish their software with an open
source license, so that anybody may also develop the same software or understand its internal
functioning. Open source software generally allows anyone to create modifications of the
software, port it to new operating systems and processor architectures, share it with others or
market it. Scholars Casson and Ryan have pointed out several policy-based reasons for
adoption of open source, in particular, the heightened value proposition from open source
(when compared to most proprietary formats) in the following categories:
• Security
• Affordability
• Transparency
• Perpetuity
• Interoperability
• Localization
The Open Source Definition, notably, presents an open source
philosophy, and further defines the terms of usage, modification and redistribution of
open source software. Software licenses grant rights to users which would otherwise be
reserved by copyright law to the copyright holder. Several open source software licenses
have qualified within the boundaries of the Open Source Definition. The most prominent and
popular example is the GNU General Public License (GPL). While open source distribution
presents a way to make the source code of a product publicly accessible, the open source
licenses allow the authors to fine tune such access.
The open source label came out of a strategy session held on April 7, 1998 in Palo Alto
in reaction to Netscape's January 1998 announcement of a source code release for Navigator
(as Mozilla). A group of individuals at the session included Tim O'Reilly, Linus Torvalds,
Tom Paquin, Jamie Zawinski, Larry Wall, Brian Behlendorf, Sameer Parekh, Eric Allman,
Greg Olson, Paul Vixie, John Ousterhout, Guido van Rossum, Philip Zimmermann, John
Gilmore and Eric S. Raymond. They used the opportunity before the release of Navigator's
source code to clarify a potential confusion caused by the ambiguity of the word "free" in
English.
By- Mr.I.Samuel Peter James
The Free Software Foundation (FSF), started in 1985, intended the word "free"
to mean freedom to distribute (or "free as in free speech") and not freedom from cost (or "free
as in free beer"). Since a great deal of free software already was (and still is) free of charge,
such free software became associated with zero cost, which seemed anti-commercial.
The Open Source Definition
The Open Source Definition is used by the Open Source Initiative to determine
whether a software license can be considered open source. The definition was based on the
Debian Free Software Guidelines, written and adapted primarily by Bruce Perens. Perens did
not base his writing on the "four freedoms" of Free Software from the Free Software
Foundation, which were only widely available later.
Perens' principles
Under Perens' definition, open source describes a broad general type of software
license that makes source code available to the general public with relaxed or non-existent
copyright restrictions. The principles, as stated, say absolutely nothing about trademark or
patent use and require absolutely no cooperation to ensure that any common audit or release
regime applies to any derived works. It is an explicit "feature" of open source that it may
put no restrictions on the use or distribution by any organization or user. It forbids this, in
principle, to guarantee continued access to derived works even by the major original
contributors.
Widely used open source products
Open source software (OSS) projects are built and maintained by a network of
volunteer programmers. Prime examples of open source products are the Apache HTTP
Server, the e- commerce platform and the internet browser Mozilla Firefox. One of the most
successful open source products is t he GN U/Linux operating system, an open
source Unix-like operating system. In some fields, open software is the norm, like in VoIP
applications with Asterisk (PBX). Open source standards are not, however, limited to
open-source software. For example, Microsoft has also joined the open-source discussion
with the adoption of their Open Document format as well as creating another open standard,
the Office Open XML formats.
Comparison with closed source
One source of conflict is related to economics: Making money through traditional
methods, such as sale of the use of individual copies and patent royalty payment (generally
By- Mr.I.Samuel Peter James
called licensing), is more difficult and in many ways against the very concept of open source
software.
Some closed-source advocates see open source software as damaging to the
market of commercial software. This is one of the many reasons, as mentioned above, that
the term free software was replaced with open source — because many company
executives could not believe in a product that did not participate economically in a
free-market or mixed-market economy.
The counter to this argument is the use of open source software to fuel the market for a
separate product or service. For example:
Providing support and installation services; similar to IT Security groups,
Linux Distributions, and Systems companies.
Using the software as a stepping stone to sell a higher-end product or service; e.g.,
OpenOffice.org vs. StarOffice.
Cost avoidance / cost sharing: many developers need a product, so it makes sense to
share development costs (X Window System and the Apache web server)
Comparison with free software
The main difference is that by choosing one term over the other (i.e. either "open
source" or "free software") one lets others know about what one's goals are. As Richard
Stallman puts it, "Open source is a development methodology; free software is a social
movement."
Critics have said that the term ―open source‖ fosters an ambiguity of a different kind
such that it confuses the mere availability of the source with the freedom to use, modify,
and redistribute it. Developers have used the alternative terms Free/open source Software
(FOSS), or Free/Libre/open source Software (FLOSS), consequently, to describe open
source software which is also free software.
The term ―open source‖ was originally intended to be trade markable; however, the
term was deemed too descriptive, so no trademark exists. The OSI would prefer that people
treat Open Source as if it were a trademark, and use it only to describe software licensed
under an OSI approved license.
OSI Certified is a trademark licensed only to people who are distributing software
licensed under a license listed on the Open Source Initiative's list.
Open source software and free software are different terms for software which comes
with certain rights, or freedoms, for the user. They describe two approaches and philosophies
By- Mr.I.Samuel Peter James
towards free software. Open source and free software both describe software which is free from
onerous licensing restrictions. It may be used, copied, studied, modified and redistributed
without restriction. Free software is not the same as freeware, software available at zero prices.
Open source vs. source-available
Although the OSI definition of "open source software" is widely accepted, a small
number of people and organizations use the term to refer to software where the source is
available for viewing, but which may not legally be modified or redistributed. Such software
is more often referred to as source-available, or as shared source, a term coined by
Microsoft.
Development tools
In OSS development the participants, who are mostly volunteers, are distributed
amongst different geographic regions so there is need for tools to aid participants to collaborate
in source code development. Often these tools are also available as OSS.
Revision control systems such as Concurrent Versions System (CVS) and later
Subversion (svn) and Git are examples of tools that help centrally manage the source code
files and the changes to those files for a software project.
Utilities that automate testing, compiling and bug reporting help preserve stability and
support of software projects that have numerous developers but no managers, quality
controller or technical support. Building syst ems that report compilation errors among
different platforms include Tinderbox. Commonly used bug trackers include Bugzilla and
GNATS.
List of free and open source software
packages
Applied fields
Computer simulation
SimPy; queue-theoretic event-based
simulator written in Python
Blender; 3D modeling software
written in Python and C++ that can
make animations and games
Grid Computing
P-GRADE Portal — Grid portal
software enabling the creation,
execution and monitoring of workflows
through high-level Web interfaces
ARTIFICIAL INTELLIGENCE
Computer Vision
OpenCV Open Source Computer
Vision Library
AForge.NET Computer Vision,
Artificial Intelligence and Robotics
library for the .NET Framework
Robotics
By- Mr.I.Samuel Peter James
ROS Robot Operating System
Planning
TREX Reactive planning
Machine Learning
See Data Mining below
See R programming language --
packages of statistical learning and
analysis tools
Speech (synthesis and recognition)
• CMU Sphinx — Speech recognition
software from Carnegie Mellon
University
• Emacspeak — Audio desktop
• Festival Speech Synthesis System
• Modular Audio Recognition
Framework — voice, audio, speech,
NLP processing
• NonVisual Desktop Access (NVDA)
Screen reader for Windows
File Systems
• OpenAFS -- a Distributed File
System supporting a very wide
variety of operating systems
Data Visualization Components
• FusionCharts Free
• ParaView plotting and visualization
functions developed by Sandia
National Laboratory, capable of
massively parallel flow visualization
utilizing multiple computer processors
Data mining
• Orange (software) — Open source
data visualization and data mining for
novice and experts, through visual
programming or Python scripting.
Extension for bioinformatics and text
mining.
• RapidMiner — data mining software
written in Java, fully integrating
Weka, featuring 350+ operators for
preprocessing, machine learning,
visualization, etc.
• Scriptella ETL — ETL
(Extract-Transform-Load) and script
execution tool. Supports integration
with J2EE and Spring.
Provides connectors to CSV,
LDAP, XML, JDBC/ODBC and
other data sources.
Enterprise search engines
• Jumper 2.0
• Lucene
• Solr
• Xapian
Communication-related
• Asterisk — Telephony and VoIP server
• Ekiga — Video conferencing
application for GNOME and Microsoft
Windows
• FreePBX — Front-end and advanced
PBX configuration for Asterisk
• FreeSWITCH — Open Source
telephony platform
Remote access and management
• FreeNX
• OpenVPN
• rdesktop
By- Mr.I.Samuel Peter James
Web-related
• Apache Cocoon — a web application
framework
• Apache — the most popular web server
• AWStats — a log file parser and
analyzer
• BookmarkSync — a tool for browsers
• CougarXML — a Javascript
framework for parsing and
manipulating XML code, based on
W3C DOM Level-3 specifications.
Portal Server
• Liferay
• Sun Java System Portal Server
• uPortal
Middleware
• Apache Axis2 - Web service
framework (implementations are
available in both Java & C)
• Apache Geronimo
• GlassFish Application Server
• JacORB — Java implementation of the
OMG's CORBA standard
• Jakarta Tomcat — a servlet container
and standalone webserver
• JBoss Application Server an
application server
• ObjectWeb JOnAS — Java Open
Application Server, a J2EE application
server
Other networking programs
• OpenLDAP — an open source LDAP
server
• JXplorer — an open source LDAP
client
• openVXI — an open source
VoiceXML interpreter
• YaCy — P2P-based search engine
Password management
• KeePass
• Password Safe
Programming language support
• ABCL — an implementation of
Common Lisp for the JVM
• ArgoUML — ArgoUML is a
modelling tool that helps you
design using UML diagrams
• CLISP — a Common Lisp interpreter
and bytecode-compiler
• Clojure — a Lisp (not Scheme nor
Common Lisp) targeting the JVM
• DJGPP — a 32-bit DOS port of GCC
and other GNU utilities
• Dragonfly — newLISP based web
development framework
• Eiffel
• ECL — an Common Lisp
implementation designed for
integration with C
• GCC — a set of compilers
for multiple programming
languages and platforms,
including
C
C++
Objective-C
Ada
Java
By- Mr.I.Samuel Peter James
Pascal
• Logo — Derivative of Lisp without
parenthesis, for kids, with Turtle
Graphics
• Parser — a language for dynamic
website creation
• Perl — a programming language strong
on text processing
• PHP — a scripting language designed
for web site applications
• Processing - a visual programming
language based on Java
• Prolog — Logic programming
• Python — a high-level scripting
language
Code generators
• Bison
• CodeSynthesis XSD — XML Data
Binding compiler for C++
• CodeSynthesis XSD/e —
Validating XML parser/serializer
and C++ XML Data Binding
generator for mobile and embedded
systems
• xmlbeansxx — XML Data Binding
code generator for C++
Anti-virus
• ClamAV
• ClamWin
• Gateway Anti-Virus
Anti-spyware
• Winpooch
Data loss prevention
• MyDLP
Encryption
• GnuPG
• KGPG
• Seahorse
• GnuTLS
• OpenSSL
Disk encryption
• CrossCrypt
• FreeOTFE and FreeOTFE Explorer
Firewall
• Iptables
• Coyote Linux
• fdgw
• Firestarter
• IPFilter
• ipfw
• IPCop
• IPFire
• M0n0wall
• PeerGuardian
• PF
By- Mr.I.Samuel Peter James
EX.NO:1
DATE:
Basic UNIX command
Aim:
To study about the basic UNIX commands.
UNIX command:
Working with files:
1. cat
Command : cat
Syntax : $cat >file name
Use : it is used to create a new file
Command : cat
Syntax : $cat file name
Use : it is used to display the file contents
Command : cat
Syntax : $cat file >>file 2
Use : to append the file from one to another
Command : cat
Syntax : $cat file1 file2 file3>file4
Use : the cat command is also used to concatenate more than one file into a single
one
2. cp
Command : cp
Syntax : $cp file1 file2
Use : it copies the contents of one file into another within your own directory.
3. rm
Command : rm
Syntax : $rm file name
Use : it is used to remove the file.
4. wc
Command : wc
Syntax : $wc file name
Use : it is used to counts and display numbers, words, lines and character in a file.
By- Mr.I.Samuel Peter James
The various options are:
Command : wc -l
Syntax : $wc -l file name
Use : it displays number of lines only.
Command : wc -w
Syntax : $wc -w file name
Use : it displays number of words only.
Command : wc -c
Syntax : $wc -c file name
Use : it displays number of characters only.
5. ls
Command : ls -a
Syntax : $ls -a
Use : it lists all directories including hidden files.
Command : ls -l
Syntax : $ls -l
Use : it lists files in long form.
Command : ls -r
Syntax : $ls -r
Use : it lists files in reverse order.
Command : ls -R
Syntax : $ls -R
Use : it displays a recursive list of all files in all sub directories.
6. mv
Command : mv
Syntax : $mv old file name : new file name
Use : it is used a rename a file.
7. comm
Command : comm
Syntax : $comm file1 file2
Use : it compares two files and displays output in three columns.
8. cmp
Command : cmp
Syntax : $cmp file1 file2
By- Mr.I.Samuel Peter James
Use : it compares two files and tells which point the files are differ. The output is displayed
in the form of byte and line number.
9. diff
Command : diff
Syntax : $diff file1 file2
Use : it locates and reports all differences between two files
10. pr
Command : pr
Syntax : $pr file name
Use : it prints the contents of a file. It produces output in a single column that contains 66
lines per page.
Working with directories:
1. pwd
Command : pwd
Syntax : $pwd
Use : the pwd stands for Print Working Directory. It displays the current working directory.
2. mkdir
Command : mkdir
Syntax : $mkdir directory name
Use : it is used to create a new directory in a disk.
3. rmdir
Command : rmdir
Syntax : $rmdir directory name
Use : it is used to remove directory from the disk.
4. cd
Command : cd
Syntax : $cd directory name
Use : it is used to change the directory.
Command : cd..
Syntax : $cd..
Use : it is used to go back to the parent directory.
5. dircmp
Command : dircmp -s
Syntax : $dircmp -s directory1 directory2
Use : it compares two directories having same filenames.
By- Mr.I.Samuel Peter James
Working with filters:
1. head
Command : head
Syntax : $head –n file name
Use : it displays first n lines of the file. If n is omitted, the first 10 lines of the file are
displayed.
2. tail
Command : tail
Syntax : $tail –n file name
Use : it displays last n lines of the file. If n is omitted, the last 10 lines of the file are
displayed.
3. more
Command : more
Syntax : $more –n file name
Use : it displays text up to n line number.
4. grep
Command : grep
Syntax : $grep [option] ―<word>‖ < file name>
Use : it prints all the lines of the file which contains the given word.
The various options are:
Command : grep -v
Syntax : $grep -v
Use : it displays all the lines except those containing pattern.
Command : grep -c
Syntax : $grep -c
Use : it reports only the number of matching lines.
5. sort
Command : sort
Syntax : $sort file name
Use : it sorts the file contents.
The various options are:
Command : sort -r
Syntax : $sort -r file name
Use : it sorts the file in reverse order.
Command : sort -f
Syntax : $sort -f file name
Use : it sorts the file and ignores cases.
By- Mr.I.Samuel Peter James
Command : sort -n
Syntax : $sort -n file name
Use : it sorts the numeric strings arithmetically.
Command : sort -u
Syntax : $sort -u file name
Use : it eliminates duplicate line.
6. cut
Command : cut
Syntax : $cut –c <list> < file name>
Where <list> indicates the specification for starting and ending column
position.
Use : it cuts out selected fields from each line of a file.
7. paste
Command : paste
Syntax : $paste file name
Use : it is used to paste the text that was previously used with the cut command.
8. man
Command : man
Syntax : $man command name
Use : it is used to see the help information for the specified commands.
9. sleep
Command : sleep
Syntax : $sleep n Where n indicates the number of seconds
Use : it is used to make some delay for execution in the program.
10. find
Command : find
Syntax : $find *.c
Use : it displays all files with extension ‗c‘.
11. pg
Command : pg
Syntax : $pg file name
Use : it displays contents of the files page by page wise.
General purpose commands:
1. who
Command : who
Syntax : $who
By- Mr.I.Samuel Peter James
Use : it displays the list of users who logged in.
Command : who am i
Syntax : $who am i
Use : it is used to identify the user and lists the user name, terminal line, login date and login
time.
2. echo
Command : echo
Syntax : $echo
Use : it displays message on the screen.
3.date
Command : date
Syntax : $date
Use : it displays the system date and time.
4. clear
Command : clear
Syntax : $clear
Use : it is used to clear the screen.
5. cal
Command : cal
Syntax : $cal
Use : it displays a calendar for the month or year.
6. banner
Command : banner
Syntax : $banner <text>
Use : it displays text in the form of a banner (large letter).
7.tty
Command : tty
Syntax : $tty
Use : it is used to indicate the terminal name that we are using.
8.nl
Command : nl
Syntax : $nl file name
Use : it is used to add line numbers to a file and it displays the file.
By- Mr.I.Samuel Peter James
EX.NO:2
DATE:
INSTALLATION OF COMMON UNIX PRINTING SYSTEM (CUPS)
AIM:
To write a steps to install the common UNIX printing system.
NOTE:
The following steps to be executed using Fedora system with printer connected system
(printer ON status).
PROCEDURE:
Step 1:
Open a terminal window
Type the following command
[fosslab@fosslab] $ rpm -qa | grep window
[fossIab@fosslab] $ rp -qi cups
Then using clear command clear the screen
Login to super user
[fosslab@fosslab] S su
Check the status of the cups using the following command
[fosslab@fosslab] $ service cups status
Start the service of cups using the following command
[fosslab@fosslab] S service cups start
Check the status of the cups again
[fosslab@fosslab] $ service cups status
Click Mozilla browser and type
Mozilla Firefox http://localhost:631
This address loads for cups for administrator
Step 2:
1. Select the option Adding printer and classes.
Click adding printers and classes
Then click acid printer option
2. Select the option “Add printer”
3. Give the root username and root password.
Then save username and password
By- Mr.I.Samuel Peter James
User name:
Password:
4. Select the printer type and select continue option.
5. Give the printer name, location and description and give continue option.
6. Select the maker of printer and select the continue option.
7. Select the model of printer and select the option “Add printer”
Select Hp printer (Hp LIP) and then click continue.
Connection [http://localhost:6031//ipp/] and then click continue
Name: hp 1010
Description: Lab
Clicks continue.
Name: HP
Then click continue.
Model: HP LaserJet 1010 foomatic
Then click add printer.
8. Select the paper size and set the default options.
Then change the page size to A4. Then click set default option.
Click Hp.
Then change maintenance print test page.
9. Click on the printer name and see the jobs that are pending.
Finally click show all jobs.
10. End of Algorithm.
RESULT:
Thus the program for to write a steps to install the common UNIX printing system is to
be obtained and the output is verified.
By- Mr.I.Samuel Peter James
EX.NO:3
DATE:
CREATING A PROGRAM TO PERFORM VIRTUALIZATION USING QEMU
AIM:
To create a step for performing virtualization environment to test applications, new
kernels and isolate applications using qemu.
DEFINITION:
Virtualization is the creation of a virtual (rather than actual) version of something,
such as hardware platform, operating system, a storage device or network resources.
PROCEDURE:
Step 1:
Open a terminal window
[fosslab@fosslab] $ rpm -qa | grep qemu
[fosslab@fosslab] $ rpm -qi qemu
Step 2:
Open Mozilla fire fox and then type http:// fosslabserver/tools/freedos. Then the
address to be loaded.
Click fdbasecd.iso. Then save the fdbasecd.iso by clicking save file option. Then
fdbasecd.iso in downloaded by downloads.
Step 3:
Open a terminal window
[fosslab@fosslab] $ pwd
[fosslab@fosslab] S mkdir virtual
Mount the /student in virtual
[fosslab@fosslab] $ sshfs student virtual
Create another directory called virtual1
[fosslab@fosslab] $ mkdir virtual1
Copy the file dsl.iso to virtual1
[fosslab@fosslab] $ cp virtual/dsl.iso virtual1
Change directory to virtual1
[fosslab@fosslab] S cd virtual1
[fosslab@fosslab] S pwd
To create a virtual disk, type in the following command
By- Mr.I.Samuel Peter James
[fosslab@fosslab] $qemu-img create virtual disk.img 100M
100M-size of the hard disk
To start the Virtual OS,type in the following command
[fosslab@fosslab] S mv/home/fosslab/downloads/fdbasecd.iso
[fosslab@fosslab] S ls-1
[fosslab@fosslab] $qemu-had virtualdisk.img-cdrom dsl.iso –boot d
Press ENTER key when the boot screen appears to boot into the OS
Then exit the window.
RESULT:
Thus the program for to creating and perform virtualization using qemu is to be
obtained and the output is verified.
By- Mr.I.Samuel Peter James
EX.NO:4
DATE:
COMPILING SOFTWARE FROM SOURCE
AIM:
To learn about the common build systems available in Linux and to use them.
RESOURCE:
Introduction
Open source software is distributed in source code form. In case of popular software
Linux distributions will often have the software packaged in their repositories. If the package is
not package is not in the repository the user has to compile the software from source. To do this
the user has to understand about the build system used in the project.
The GNU build system, also known as the Autotools, is a suite of programming tools
designed to assist in making source-code packages portable to many Unix-like systems. It can
be difficult to make a software program portable: the C compiler differs from system to system;
certain library functions are missing on some systems; header files may have different names.
One way to handle this is write conditional code, with code blocks selected by means of
preprocessor directives (#ifdef); but because of the wide variety of build environments this
approach quickly becomes unmanageable. The GNU build system is designed to address this
problem more manageably.
Tools included in the GNU build system
The GNU build system comprises the GNU utility programs Autoconf, Automake, and
Libtool. Other related tools frequently used with the GNU build system are GNU‘s make
program, GNU gettext, pkg-config, and the GNU Compiler Collection, also called GCC.
GNU Autoconf
Autoconf generates a configure script based on the contents of a configure.ac file
which characterizes a particular body of source code. The configure script, when run, scans the
build environment and generates a subordinate config.statusscript which, in turn, converts
other input files and most commonly Makefile.in into output files (Makefile) which are
appropriate for that build environment. Finally the make program uses Makefile to generate
executable programs from source code.
The complexity of the GNU build system reflects the variety of circumstances under
which a body of source code may be built.
By- Mr.I.Samuel Peter James
If a source code file is changed then it suffices to re-run make which only re- compiles that
part of the body of the source code affected by the change.
If a .in file has changed then it suffices to re-run config.status and make.
If the body of source code is copied to another computer then it is suffices to re- run
configure (which runs config.status) and make. (For this reason source code using the GNU
build system is normally distributed without the files thatconfigure generates.)
If the body of source code is changed more fundamentally then configure.ac and the .in
files need to be changed and all subsequent steps also followed.
To process files, autoconf uses the GNU implementation of the m4 macro system.
Autoconf comes with several auxiliary programs such as Autoheader, which is used to help
manage C header files; Autoscan, which can create an initial input file for Autoconf; and
ifnames, which can list C pre-processor identifiers used in the program.
GNU Automake
Automake helps to create portable Makefiles, which are in turn processed with the
make utility. It takes its input as Makefile.am, and turns it into Makefile.in, which is used by
the configure script to generate the file Makefile output.
GNU Libtool
Libtool helps manage the creation of static and dynamic libraries on various Unix-like
operating systems. Libtool accomplishes this by abstracting the library-creation process,
hiding differences between various systems (e.g. GNU/Linuxsystems vs. Solaris).
Gnulib
Gnulib simplifies the process of making software that uses Autoconf and Automake
portable to a wide range of systems.
Make
In software development, make is a utility that automatically builds executable
programs and libraries from source code by reading files called makefiles which specify how
to derive the target program. Make can decide where to start through topological sorting.
Though integrated development environments and language-specific compiler features
can also be used to manage the build process in modern systems, make remains widely
used, especially in Unix.
Make is typically used to build executable programs and libraries from source code.
Generally though, any process that involves transforming a dependency file to a target result
By- Mr.I.Samuel Peter James
(by executing some number of arbitrary commands) is applicable to make. To cite an example,
make could be used to detect a change made to an image file (the dependency) and the target
actions that result might be to convert the file to some specific format, copy the result into a
content management system, and then send e-mail to a predefined set of users that the above
actions were performed.
CMake
CMake is a unified, cross-platform, open-source build system that enables developers
to build, test and package software by specifying build parameters in simple, portable text files.
It works in a compiler-independent manner and the build process works in conjunction with
native build environments, such as make, Apple's Xcode and Microsoft Visual Studio. It also
has minimal dependencies, C++ only. CMake is open source software.
CMake can:
Create libraries
Generate wrappers
Compile source code
Build executables in arbitrary combinations
Apache Ant
Apache Ant is a software tool for automating software build processes. It is similar to
Make but is implemented using the Java language, requires the Java platform, and is best suited
to building Java projects.
The most immediately noticeable difference between Ant and Make is that Ant uses
XML to describe the build process and its dependencies, whereas Make uses Makefile format.
By default the XML file is named build.xml.
Ant is an Apache project. It is open source software, and is released under the Apache Software
License.
Pre-requisites:
The computers need the development tools to be installed. Instructions for installing
them will be given along with each exercise.
PROCEDURE:
Create a directory for all the programs in the exercise.
> mkdir build_systems
> cd build_systems
By- Mr.I.Samuel Peter James
Make
We will be using a simple program written in C and write a makefile to compile the
program.
> mkdir gnumake
> cd gnumake
> gedit squareroot.c
The Code:
// A simple program that computes the square root of a number
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (int argc, char *argv[])
{
if (argc < 2)
{
fprintf(stdout,"Usage: %s number\n",argv[0]);
return 1;
}
double inputValue = atof(argv[1]); double outputValue = sqrt(inputValue);
fprintf(stdout,"The square root of %g is %g\n",
inputValue, outputValue);
return 0;
}
Test it by compiling it once:
> gcc squareroot.c -o squareroot -lm
> ./sqaureroot 49
> The square root of 49 is 7
Now we write a simple makefile to compile the program.
> gedit Makefile
The Code:
# Commands start with TAB not spaces
CC= gcc CFLAGS= -g LDFLAGS = -lm
By- Mr.I.Samuel Peter James
all: squareroot squareroot: squareroot.o squareroot.o: squareroot.c clean:
rm -f squareroot squareroot.o
Now we test the Makefile:
> make
make: Nothing to be done for `all'.
> make clean
rm -f squareroot squareroot.o
> make
gcc -g -c -o squareroot.o squareroot.c gcc -lm squareroot.o -o squareroot
> ./squareroot 49
>The square root of 49 is 7
CMake
We will now write a simple script for CMake to compile the previously written program.
First we install CMake
> yum install cmake
We create a new directory and copy the source code to it.
> cd ..
> mkdir cmake
> cd cmake
> cp ../gnumake/squareroot.c .
Now we create configuration files for CMake.
> gedit CMakeLists.txt
The Code:
cmake_minimum_required (VERSION 2.6) project (squareroot) add_executable(squareroot
squareroot.c) TARGET_LINK_LIBRARIES(squareroot m)
CMake is commonly use with out of source builds ie, we build the program in a directory
separate from the source. We use the generated makefile to compile the program.
> mkdir build
> cd build
> ls
> cmake ..
-- The C compiler identification is GNU
By- Mr.I.Samuel Peter James
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to:
/home/<user>/projects/buildsystems/cmake/build
> ls
CMakeCache.txt CMakeFiles cmake_install.cmake Makefile
> make
Scanning dependencies of target squareroot
[100%] Building C object CMakeFiles/squareroot.dir/squareroot.c.o
Linking C executable squareroot
[100%] Built target squareroot
>ls
CMakeCache.txt CMakeFiles cmake_install.cmake Makefile squareroot
> ./squareroot 49
The square root of 49 is 7
Study the CMake generated Makefile.
To uninstall the program:
> su
> make uninstall
> exit
RESULT:
Thus the various build systems used like the auto* family, cmake, instead of just
running the commands successfully and the output was verified.
By- Mr.I.Samuel Peter James
EX.NO:5(a)
DATE:
Implementation of complex number using python program
Aim:
To create a python program to perform calculations using complex numbers.
Algorithm:
Step 1: Give the input complex numbers
Step 2: Calculate real and imaginary part of the numbers.
Step 3: Print the round complex number as output.
Program:
Prim complex(0,l)+complex(2,3)
A=complex(0,l)+complex(2,3)
Print a.real,a.imag
Print round(5.78.1)
RESULT:
Thus the python program to calculate complex number was executed and the output
was verified.
By- Mr.I.Samuel Peter James
EX.NO:5(b)
DATE:
Implementation of python program to print string in reverse order
Aim:
To write a python program to print a given string in the reverse order.
Algorithm:
Step 1: Give an string in a variable 'a'
Step 2: Create a temporary space to store reversed string.
Step 3: Add temp value with i and create reverse string.
Step 4: Print string value stored in temp
Program:
a=’FOSSLAB’
temp=’’’’
for i in a:
temp=i+temp:
print temp
RESULT:
Thus the python program to print string in reverse was executed and the output was
verified.
By- Mr.I.Samuel Peter James
EX.NO:5(C)
DATE:
Program to find biggest of the numbers
Aim:
To write a python program to find the biggest number among the given number.
Algorithm:
Step 1: Give value for the three numbers using variables a.b,c,
Step 2: Compare a with b&c & print a if it is big.
Step 3: Otherwise print b as a biggest number.
Step 4: If above conditions fail print c as the biggest number.
Program:
A=5
b=9
c=17
if a>b:
if a>c:
print a
elif b>c:
print b
else
print c
RESULT:
Thus the python program to find biggest number was executed and the output was
verified.
By- Mr.I.Samuel Peter James
EX.NO:5(D)
DATE:
Program to display Fibonacci series
Aim:
To write a python program to display the Fibonacci series numbers.
Algorithm:
Step 1: Initialize the values for variables a,b.
Step 2: Give the Fibonacci value of n as 10.
Step 3: Print the increment value of b until fibonacci value.
Step 4: Print the Fibonacci series numbers.
Program:
a,b=0,l
n=10
while b<n:
prinl b,
a,b=b,a+b
RESULT:
Thus the program print the Fibonacci series number was executed and the output was
verified.
By- Mr.I.Samuel Peter James
EX.NO:6(A)
DATE:
Program to display * using for
Aim:
To write a python program to display * using for.
Algorithm:
Step 1: Consider i as value from 1 to 4.
Step 2: Print * in every i.
Program:
For i in range(i,4)'
print * i
RESULT:
Thus the python program display * using for was executed and the output was verified.
By- Mr.I.Samuel Peter James
EX.NO:6(B)
DATE:
Program for function with multiple return values
Aim:
To write a program for function with multiple values.
Algorithm:
Step 1: Define min max functions
Step 2: If item is greater than large; great =small.
Step 3: If not item less than small: small—item.
Step 4: Print small, large.
Program:
Def min max(numbers);
Small=large=numbers[0];
For item in numbers:
If item>large:
Large -item:
elif item<small:
Small=item
#Test
Small,large=min max[1,2,7,6,3,1,2,8,4]
Print small,large
RESULT:
Thus the python program for function with multiple values was executed and the output
was verified.
By- Mr.I.Samuel Peter James
EX.NO:6(C)
DATE:
Module program in python
Aim:
To write a module program in python.
Algorithm:
Step 1: Execute Fibonacci program in one file.
Step 2: In main file define Fibonacci program.
Step 3: Now output will be in main.py file.
Program:
#fibo.py
Def fib(n):
a,b=0,l
while b<n:
print b:
a,b=b,l+b
#main1.py .
import fibo
fibo.fib(25)
RESULT:
Thus the python module program was executed and the output was verified.
By- Mr.I.Samuel Peter James
EX.NO:6(D)
DATE:
Program to display time
Aim:
To write a program to display date and time.
Algorithm:
Step I: Import the local time.
Step 2: Consider + as the local time.
Step 3: Print date and time.
Program:
from the time import the local time
t=local time()
print t.tm_m.day."|",t.rm_mar. 1 ",t.tm_year;
print t.tim_hour,"_”,t.tim-min,r,”.”,t.tm_sec:
RESULT:
Thus the program to display time and date was executed and the output was verified.
By- Mr.I.Samuel Peter James
EX.NO:7(A)
DATE:
Program to find arithmetic operation
Aim:
To write a python program for to find the arithmetic operation.
Algorithm:
Step 1: Give value for the two numbers using variables
Step 2: Declare the variables and initialize the statement
Step 3: Calculate the arithmetic operation
Program:
print 'arithemeticoperations'
print 'addition'
print float(345.55)+float(387.23)
a=float(345.55)+float(387.23)
print 'roundedvalue'
print round(a)
print 'Subtraction'
print float(345.55)-float(387.23)
b=float(345.55)-float(387.23)
print 'roundedvalue'
print round(b)
print 'Multiplication'
print float(345.55)*float(387.23)
c=float(345.55)*float(387.23)
print 'roundedvalue'
print round(c)
print 'Division'
print float(345.55)/float(387.23)
d=float(345.55)/float(387.23)
print 'roundedvalue'
print round(d)
RESULT:
Thus the python program to find the arithmetic operation was executed and the output
was verified.
By- Mr.I.Samuel Peter James
EX.NO:7(B)
DATE:
Program to calculate the average wind speed of the day using data specified in Task 3
Aim:
To write a python program for to calculate the average wind speed of the day using the
data specified in Task 3.
Algorithm:
Step 1: Give value for the numbers using variables
Step 2: Declare the variables and initialize the statement
Step 3: Calculate the average wind speed of the day using the data specified in Task 3.
Program:
wind_speed = [3, 5, 3, 2, 0, 0, 5, 5, 11, 5, 10, 2]
noon = wind_speed[6]
print noon
afternoon = wind_speed[7:12]
print afternoon
last = wind_speed[-1]
print last
RESULT:
Thus the python program to calculate the average wind speed of the day using the data
specified in Task 3 was executed and the output was verified.
By- Mr.I.Samuel Peter James
EX.NO:7(C)
DATE:
Program to find the first factorial that has more than 100 digits
Aim:
To write a python program for to find the first factorial that has more than 100 digits.
Algorithm:
Step 1: Give value for the numbers using variables
Step 2: Declare the variables and initialize the statement
Step 3: Calculate the find the first factorial that has more than 100 digits.
Program:
n = 1
fact = 1
while fact < (10 ** 100):
n = n + 1
fact = fact * n
print fact
RESULT:
Thus the python program to find the first factorial that has more than 100 digits was
executed and the output was verified.
By- Mr.I.Samuel Peter James
EX.NO:7(D)
DATE:
Program to find that prints prime numbers less than 20.
Aim:
To write a python program for to find that prints prime numbers less than 20.
Algorithm:
Step 1: Give value for the numbers using variables
Step 2: Declare the variables and initialize the statement
Step 3: Calculate the find that prints prime numbers less than 20.
Program:
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'
RESULT:
Thus the python program to find that prints prime numbers less than 20 was executed
and the output was verified.
By- Mr.I.Samuel Peter James
EX.NO:7(E)
DATE:
Program to find the function that returns the smallest and largest element in a list.
Aim:
To write a python program for to find the function that returns the smallest and largest
element in a list.
Algorithm:
Step 1: Give value for the numbers using variables
Step 2: Declare the variables and initialize the statement
Step 3: Calculate the find the function that returns the smallest and largest element in a
list.
Program:
def min_max(numbers):
smallest = largest = numbers[0]
for item in numbers:
if item > largest:
largest = item
elif item < smallest:
smallest = item
return smallest, largest
# Test
smallest, largest = min_max([1, 2, 7, 6, 3, 1, 2, 8, 4])
RESULT:
Thus the python program to find the function that returns the smallest and largest
element in a list was executed and the output was verified.
By- Mr.I.Samuel Peter James
EX.NO:8(A)
DATE:
Program to accept input from user
Aim:
To create a program to get numbers as input from user and produce the corresponding
output.
Algorithm:
Step 1: Get the values of a & b.
Step 2: calculate the values of two numbers
Step 3: Print the output.
Program:
//import sys
a=raw input=Enter a no:");
b=raw_input("Enter another no:");
print int(a)+int(b);
RESULT:
Thus the python program to get input from users and corresponding operations are
executed and the output was verified.
By- Mr.I.Samuel Peter James
EX.NO:8(B)
DATE:
Program to connect python and MYSQLDB
Aim
To create a program to connect python and MYSQLDB.
Algorithm:
Step 1: Create a database and its corresponding tables.
Step 2: Provide coding in gedit text editor to perform various operations.
Step 3: Give inputs thro python program and store it on database.
Program:
import MYSQLdB as db
conn=db.connect"" ,"root ", "", "TESTDB")
cursor=conn.cursor()
cursor.execute("SELECT VERSION()")
data=cursor.fetchone()
print”Database version:%s"%data
sql="""CREATE TABLE EMP(NAME CHAR(20)),"'"
cursor.execute(sql)
sql="INSERT INTO EMP(NAME) VALUES ('joe')"
cursor.execute(sql)
sql="SELECT * FROM EMP"
cursor.execute(sql)
results=cursor. fetchall()
for row in results:
fname=row[0]
print"fname=%s",( fname)
sql="UPDATE EMP SET NAME='rex'"
cursor.execute( sql)
sql="DELETE FROM EMP"
cursor.execute(sql)
RESULT:
Thus the python program to connect MYSQL was executed and the output was verified.
By- Mr.I.Samuel Peter James
EX.NO:8(C)
DATE:
Program to perform operator overloading
Aim:
To create a python program to create class. point and perform operator overloading.
Algorithm:
Step I: Create a class point
Step 2: create various functions for mathematical operations.
Step 3: In main program for various values perform mathematical operations.
Program:
class point:
define_(self,x=0,y=0):
self.x=x
self.v=v
def_add_(self,other):
return point(self.x+other.x,self.y+other.y)
def_mul (self,other):
return self.x*other.x+self.y+other.y
def_str_(self):
return”(%d.%d)”%(self.x,self.y)
#main program
P1 =point(1 ,2)
P2=point(3,4)
Print pl,p2
Print p1 +p2
Print p1 *p2
RESULT:
Thus the python program to perform operator overloading was executed and the output
was verified.
By- Mr.I.Samuel Peter James
EX.NO:9(A)
DATE:
GREATER AMONG THREE NUMBER
AIM:
To write a Perl program to check greater among three numbers.
ALGORITHM:
STEP 1: Step the program
STEP 2: Read the values of a.b,c
STEP 3: If a value greater than b&c print a is greater.
STEP 4: If b is greater than a&c print b is greater else print G is greater
STEP 5: Stop the program.
PROGRAM:
print "enter a value:";
$a=<>;
print"enter b values:";
$b=<>;
print”enter c values:";
$c=<>;
if(($a>$b )&&(%$a>$c))
{
print"a is greater";
i
elseif(sb>5c)&&($b>$a))
print' b is greater":
}
else
{
print"c is greater";
}
RESULT:
Thus the Perl program for to check greater among three numbers was executed and the
output was verified.
By- Mr.I.Samuel Peter James
EX.NO:9(B)
DATE:
SIMPLE PROGRAM FOR DISPLAY NAME
AIM:
To write a Perl program to display the name.
ALGORITHM:
STEP 1: Start the program
STEP 2: Type the PERL program using vi editor and save with the extension .pl
STEP 3: # program-name.pl to execute the program.
STEP 4: # the above line is shebang directive
STEP 5: Stop the program.
PROGRAM:
#!usr/bin/perl # the above line is shebang directive
$name=<STDIN>;
chomp($name);
print "$name\n";
OUTPUT:
[linuxpert@localhost ~]$ perl extension.pl
rose
rose
RESULT:
Thus the Perl program for to display the name was executed and the output was
verified.
By- Mr.I.Samuel Peter James
EX.NO:9(C)
DATE:
SCALAR VARIABLES IN PERL
AIM:
To write a Perl program to create scalar variables in Perl.
ALGORITHM:
STEP 1: Start the program
STEP 2: Type the PERL program using vi editor and save with the extension .pl
STEP 3: # program-name.pl to execute the program.
STEP 4: # the above line is shebang directive
STEP 5: Stop the program.
PROGRAM:
#!/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";
OUTPUT:
[linuxpert@localhost ~]$ perl scalar.pl
Camel
42243
RESULT:
Thus the Perl program for to create scalar variables in Perl was executed and the
output was verified.
By- Mr.I.Samuel Peter James
EX.NO:9(D)
DATE:
ARRAY IN PERL
AIM:
To write a Perl program to create array in Perl.
ALGORITHM:
STEP 1: Start the program
STEP 2: Type the PERL program using vi editor and save with the extension .pl
STEP 3: # program-name.pl to execute the program.
STEP 4: # the above line is shebang directive
STEP 5: Stop the program.
PROGRAM:
#!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
OUTPUT:
[linuxpert@localhost ~]$ perl array.pl
cow Buffalo Camel
2
cow
3
RESULT:
Thus the Perl program for to create array in Perl was executed and the output was
verified.
By- Mr.I.Samuel Peter James
EX.NO:9(E)
DATE:
TO DISPLAY ALL VALUES IN HASH
AIM:
To write a Perl program to display all values in hash.
Algorithm:
STEP 1: Start the program
STEP 2: Type the PERL program using vi editor and save with the extension .pl
STEP 3: # program-name.pl to execute the program.
STEP 4: # the above line is shebang directive
STEP 5: Stop the program.
Program:
#!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.pl
red
yellow
red
orange
RESULT:
Thus the PERL program display all values in hash was verified and the output was
verified.
By- Mr.I.Samuel Peter James
EX.NO:9(F)
DATE:
TO DELECTION OF HASH VALUES
AIM:
To write a Perl program to delection of Hash values.
Algorithm:
STEP 1: Start the program
STEP 2: Type the PERL program using vi editor and save with the extension .pl
STEP 3: # program-name.pl to execute the program.
STEP 4: # the above line is shebang directive
STEP 5: Stop the program.
Program:
#!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 values
foreach $key (@keys)
{
print "$color{$key}\n";
}
delete $color{'apple'}; # to remove specific key
RESULT:
Thus the PERL program to delection of Hash values was verified and the output was
verified.
By- Mr.I.Samuel Peter James
EX.NO:10
DATE:
Connecting PHP with Mysql
Aim:
To create a connection between the PHP program and the database MYSQL.
Procedure:
[linuxpert@localhost ~]# chmod 777/var/www/html
[linuxpert@localhost ~]$ su
Password: admin123
[root@localhost linuxpert]# cd /var/www/html
[root@localhost html]# gedit
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>
</html>
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')";
By- Mr.I.Samuel Peter James
$res=@mysql_query($str) or die(mysql_error());
if($res>0)
{
echo "Record created";
}
?>
TYPE THE FOLLOWING IN THE BROWSER
http://localhost/form.html
When u press the submit button
[linuxpert@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
mysql> connect
Connection id: 29
Current database: student
mysql> show tables;
+-------------------+
By- Mr.I.Samuel Peter James
| 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 connection was established between PHP and MYSQL and the output was
verified.
By- Mr.I.Samuel Peter James
EX.NO:11
DATE:
Create Login Page using PHP with Mysql
Aim:
To create a Create Login Page using the PHP program and the database MYSQL.
Procedure:
[linuxpert@localhost ~]# chmod 777/var/www/html
[linuxpert@localhost ~]$ su
Password: admin123
[root@localhost linuxpert]# cd /var/www/html
[root@localhost html]# gedit
Type the following in gedit and save it as HomePage.php
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>
By- Mr.I.Samuel Peter James
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
Type the following in gedit and save it as checklogin.php
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.
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";