Open Source Software Technology Lab Manual

Embed Size (px)

Citation preview

  • 8/16/2019 Open Source Software Technology Lab Manual

    1/29

    Department of Computer Science & Engineering

    LAB MANUAL

      Session 2013-2014

    Subject Name : - Open Source Softare !ec"no#o$%Lab

    Subject &o'e : - (&S-)*3

    Branc" : - &S+,(!

    ear : - 3r'

    Semester : - )t"

    (N!+./AL UN(+/S(! LU&NO

    Dasauli, Kursi Road, PO Basha-226026

  • 8/16/2019 Open Source Software Technology Lab Manual

    2/29

     List of Lab +ercises

    Week 1 Experiment No. Name of the Experiments Page No.

    1 Objective Overview of FOSS & Basic Command interface on Linux 3

    2 1 Usage of Basic Linux Commands, Fie Utiities Commands !

    Week-2 Objective Learning "dministrative Commands

    1 #

    2 $ %i ditor & its 'odes, (ntroduction of Basic administrativecommands

    )

    3 3 Usage of Basic *etwor+ eated Commands -

    Week-3 Objective Learning S.e Scri/ting

    1 02

    2 ! " Scri/t to c.ec+ for a fie existence in t.e fie sstem 14

    3 # " Scri/t to execute different command to demonstrate Switc.cases statement

    11

    4 ) " Scri/t to .ande command ine argument and ot.er S/eciasmbos

    1$

    Week-4 Objective Learn .ow to Com/ie, 5ebug & xecute C, C66 & 7ava8rogramming Code wit.out (5s

    1 13

    2 - Create a sam/e C /rogram for demonstrating t.e use ofcontro statements t.en com/ie and execute t.e code

    1!

    3 0 Create a sam/e C66 cass based /rogram for demonstratingt.e use of Object oriented 5esign 8atterns, t.en com/ie andexecute t.e code

    1#

    4 2 Creating a sam/e java 8rogram for demonstrating t.e use ofcontro statements t.en com/ie and execute t.e code

    1)

    Week-5 Objective Learning Basics of L"'8 Server

    1 1-

    2 14 (nstaation "nd Configuration of L"'8 Server on Linux9Ubuntu:

    10

    3 11 Creating sim/e 5atabase in 'S; Server /erforming ;ueries 12

    Week-6 Objective Learning " 5ee/ 5ive in 'S;

    1 $4

    2 1$ 'S; "dministrator< 'onitoring t.e Server and User"dministration

    $1

    3 13 'S; "dmin, Bac+u/ and restore, User "ccount ig.ts'anagement

    $$

    Week-7 Objective Basics of 8=8 >eb 8rogramming

    1 $3

    2   1! " 8=8 code to demonstrate t.e usage of %ariabe, String,"rra and Contro Structure

    $!

    Week-8 Objective Some 5ee/ 5ive in 8=8 8rogramming

    1 $#$)

    2 1# " 8=8 8rogram to im/ement customi?ed functions, Form=anding Strategies

    $-

    5e/t of CS @(A $ (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    3/29

    " 8=8 8rogram to demonstrate t.e use of 8=8 mai 9:Function

    Week-9 Objective Learning 5atabase Connectivit between 8=8 and 'S;

    1 $0

    2 1) Create a ogin Contro for a web /age to demonstrate t.e use

    of Connectivit and Basic retrieva of data from database

    $2

    Week-1 Objective " Sam/e 8roject to create a website for Universit Utiities

    1 "otment of aread discussed 8roject i+e 5atabasemanagement Sstems

    5e/t of CS @(A 3 (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    4/29

    !"er"ie# of $!%%

    A.e O/en Source (nitiative 9OS(: is a Caifornia /ubic benefit cor/oration, wit. #419c:3 taxexem/t status,

    founded in 1220 O/en source software is software t.at can be free used, c.anged, and s.ared 9in modifiedor unmodified form: b anone O/en source software is made b man /eo/e, and distributed under

    icenses t.at com/ wit. t.e O/en Source 5efinition

    A.e O/en Source (nitiative 9OS(: is a goba non/rofit t.at su//orts and /romotes t.e

    o/en source movement "mong ot.er t.ings, we maintain t.e O/en Source 5efinition,

    and a ist of icenses t.at com/ wit. t.at definition

    A.e O/en Source 5efinition

    O/en source doesnt just mean access to t.e source code A.e distribution terms of o/en

    source software must com/ wit. t.e foowing criteria<

    1. $ree &e'istri()tion

    A.e icense s.a not restrict an /art from seing or giving awa t.e software as a

    com/onent of an aggregate software distribution containing /rograms from severa

    different sources A.e icense s.a not re;uire a roat or ot.er fee for suc. sae

    2. %o)r*e +o'e

    A.e /rogram must incude source code, and must aow distribution in source code as

    we as com/ied form >.ere some form of a /roduct is not distributed wit. source code,

    t.ere must be a we/ubici?ed means of obtaining t.e source code for no more t.an a

    reasonabe re/roduction cost /referab, downoading via t.e (nternet wit.out c.arge A.e

    source code must be t.e /referred form in w.ic. a /rogrammer woud modif t.e

     /rogram 5eiberate obfuscated source code is not aowed (ntermediate forms suc. as

    t.e out/ut of a /re/rocessor or transator are not aowed

    5e/t of CS @(A ! (CS$#1 

    http://opensource.org/licenseshttp://opensource.org/definitionhttp://opensource.org/definitionhttp://opensource.org/licenseshttp://opensource.org/licenseshttp://opensource.org/licenseshttp://opensource.org/definitionhttp://opensource.org/definitionhttp://opensource.org/licenses

  • 8/16/2019 Open Source Software Technology Lab Manual

    5/29

    3. ,eri"e' Works

    A.e icense must aow modifications and derived wor+s, and must aow t.em to be

    distributed under t.e same terms as t.e icense of t.e origina software

    4. ntegrit of the /)thor0s %o)r*e +o'e

    A.e icense ma restrict sourcecode from being distributed in modified form only if t.e

    icense aows t.e distribution of D/atc. fiesD wit. t.e source code for t.e /ur/ose of

    modifing t.e /rogram at buid time A.e icense must ex/icit /ermit distribution of

    software buit from modified source code A.e icense ma re;uire derived wor+s to carr

    a different name or version number from t.e origina software

    5. No ,is*rimination /gainst Persons or ro)ps

    A.e icense must not discriminate against an /erson or grou/ of /ersons

    6. No ,is*rimination /gainst $ie's of En'ea"or

    A.e icense must not restrict anone from ma+ing use of t.e /rogram in a s/ecific fied of 

    endeavor For exam/e, it ma not restrict t.e /rogram from being used in a business, or

    from being used for genetic researc.

    7. ,istri()tion of i*ense

    A.e rig.ts attac.ed to t.e /rogram must a// to a to w.om t.e /rogram is redistributed

    wit.out t.e need for execution of an additiona icense b t.ose /arties

    8. i*ense )st Not e %pe*ifi* to a Pro')*t

    A.e rig.ts attac.ed to t.e /rogram must not de/end on t.e /rograms being /art of a

     /articuar software distribution (f t.e /rogram is extracted from t.at distribution and used

    5e/t of CS @(A # (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    6/29

    or distributed wit.in t.e terms of t.e /rograms icense, a /arties to w.om t.e /rogram

    is redistributed s.oud .ave t.e same rig.ts as t.ose t.at are granted in conjunction wit.

    t.e origina software distribution

    9. i*ense )st Not &estri*t !ther %oft#are

    A.e icense must not /ace restrictions on ot.er software t.at is distributed aong wit. t.e

    icensed software For exam/e, t.e icense must not insist t.at a ot.er /rograms

    distributed on t.e same medium must be o/ensource software

    1. i*ense )st e e*hnoog-Ne)tra

     *o /rovision of t.e icense ma be /redicated on an individua tec.noog or ste of

    interface

    asi* +omman's in in)x

    Command Syntax

    Commands can be run b t.emseves, or ou can /ass in additiona arguments to ma+e t.em do

    different t.ings A/ica command sntax can oo+ somet.ing i+e t.is<

    command [-argument] [-argument] [--argument] [fle]

     xam/es< ls List fies in current director

    ls -l Lists fies in Eong format

    ls -l --color "s above, wit. coouri?ed out/ut

    cat flename S.ow contents of a fie

    cat -n flename S.ow contents of a fie, wit. ine numbers

    5e/t of CS @(A ) (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    7/29

    x/eriment *o 1

    Usage of Basic Linux Commands, Fie Utiities Commands

    !E+E

    • Learn .ow to execute commands in s.e of Ubuntu

    /fter *ompeting this experiment o) #i (e a(e to

    • Student s.oud abe to use basic sntax structure of Commands

    • Understand .ow to use commands in a s.e

    • =ow to get .e/ for Commands

    &e:)irements

    Aoos @ "//aratus< Unix@Linux O/erating Sstem, Bas. S.e

    %*reen %hots

    5e/t of CS @(A - (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    8/29

    Exer*iseG1 >.at is a sntax structure of CommandsHG$ =ow to see our ogin detaisHG3 =ow to c.ange date and time of our Linux@Unix@Ubuntu

    $or $)rther &ea'ing %t)'ent a &efer to the foo#ing ooks

    1 Linux (n de/t. B Ias.want Janet+ar

    5e/t of CS @(A 0 (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    9/29

    earning /'ministrati"e +omman's

     The Linux System Administrator's Guide, describes the system administration aspects

    o using Linux! "t is intended or people #ho $no# next to nothing about systemadministration, but #ho ha%e already mastered at least the basics o normal usage!

     This manual doesn't tell you ho# to install Linux& that is described in the "nstallationand Getting Started document! See belo# or more inormation

    about Linux manuals! System administration co%ers all the things that you ha%e to doto $eep a computer system in usable order! "t includes things li$e bac$ing up fles andrestoring them i necessary(, installing ne# programs, creating accounts or usersand deleting them #hen no longer needed(, ma$ing certain that the flesystem is notcorrupted, and so on! " a computer #ere, say, a house, system administration #ouldbe called maintenance, and #ould include cleaning, fxing bro$en #indo#s, and other

    such things! The structure o this manual is such that many o the chapters should beusable independently, so i you need inormation about bac$ups, or example, you canread )ust that chapter! *o#e%er, this manual is frst and oremost a tutorial and can beread se+uentially or as a #hole!

    x/eriment *o $

    i E'itor ; its o'es< ntro')*tion of asi* a'ministrati"e *omman's

    !E+E

    • Learning t.e wor+ing of %i ditor and switc.ing between different t.ree different modes

    • S.oud be read to run and configure administrative commands

    &e:)irements

    Aoos @ "//aratus< Unix@Linux@>indows O/erating Sstem, Bas. S.e wit. root ogin /rivieges ie root user name and 8assword

    Exer*ise

    1 >.at are t.e t.ree modes in %i ditorH =ow to switc. from one mode to anot.er $ =ow to ta+e bac+ u/ of t.e re;uired data from fie sstemH$ =ow to ma+e a cose oo+ on Conf fies using administrative commandsH

    earning %he %*ripts

    5e/t of CS @(A 2 (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    10/29

     " s.e is an environment in w.ic. we can run our commands, /rograms, and s.e scri/ts A.ereare different favors of s.es, just as t.ere are different favors of o/erating sstems ac. favor of s.e .as its own set of recogni?ed commands and functionsA.is boo+ wor+s wit. t.e Bourne, Bas., and Jorn s.es S.es are ocated in eit.er t.e @usr@bin@

    director or t.e @bin@ director, de/ending on t.e U*(K favor and s/ecific version A.e /rom/t,, w.ic. is caed command /rom/t, is issued b t.e s.e >.ie t.e /rom/t is dis/aed, oucan t/e a command A.e s.e reads our in/ut after ou /ress nter (t determines t.e commandou want executed b oo+ing at t.e first word of our in/ut " word is an unbro+en set ofc.aracters S/aces and tabs se/arate words Foowing is a sim/e exam/e of 'ate commandw.ic. dis/as current date and time<

    5e/t of CS @(A 14 (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    11/29

    x/eriment *o 3

    earning %he %*ripting

    !(=e*ti"e

    • (dentif t.e /robem statement for w.ic. S.e scri/ting is created

     

    • Student s.oud be abe to create s.e scri/t to demonstrate t.e usage of contro statements

    and usage of s/ecia smbos

    • =ow to use command ine argument in S.e scri/t

    &e:)irements

    Aoos @ "//aratus< Unix@Linux@>indows O/erating Sstem, Medit Aext ditor, Bas. S.e wit. rootogin credentias

    Exer*ise

    1 Student wi be we versed wit. s.e scri/ting for instaation and configuration of softwares

    $ =ow to use and manage contro statement in s.e scri/t3 5emonstrate t.e use of effective use of command ine "rgument in s.e scri/ting

    earn ho# to +ompie< ,e()g ; Exe*)te +< +>> ;

    a"a Programming +o'e #itho)t ,Es

    x/eriment *o !

    !(=e*ti"e• Ao write /rogram in different /rogramming Languages Suc. as C, C66, 7ava 8roagramming

    • 8ro/er usage of man and gdb too for effective usage of coding strategies in C, C /us /us,

    7ava 8rogramming

    5e/t of CS @(A 11 (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    12/29

    &e:)irements

    Aoos @ "//aratus< Unix@Linux@>indows O/erating Sstem, Medit Aext ditor, Com/iers andinter/reters of a anguages 9C, C66, 7ava:

    +ercise:

    1 Create a sam/e C /rogram for demonstrating t.e use of contro statements t.en com/ie and execute t.ecodeSon ?in*)'e@st'io.hA BBet )s ass)me fie name for this *o'e is 'emo*.*

    int mainCD

    printfCFheo #or' GFDHI

    o +ompie Jo)r +o'e K** 'emo*.** -o 'emo*.exe BB -o option #i *reate o(=e*t fie #ith gi"en fie

    name as 'emo*.exe

    to Exe*)te Jo)r +o'e K.B'emo*.exe BB)se of 0.B0 is m)st (efore exe*)ting o)r 'emo*.exe fie

    Note Lser *an )se man)a of ** for 'etaie' options of *ompiing an' 'e()ging mo'es as Cman **D

    ii Create a sam/e C66 cass based /rogram for demonstrating t.e use of Object oriented5esign 8atterns, t.en com/ie and execute t.e code?in*)'e@st'ioA BBet )s ass)me fie name for this *o'e is 'emo*p)sp)s.*pp

    ?in*)'e@iostreamA

    )sing namespa*e st'H*ass /

    pri"ate

    int aH

    p)(i*

    "oi' get,ataCD

    *o)t@@FENE& ,// M F@@en'H

    I

    "oi' set,ataCD

    a25H BBset the 'efa)t "a)e of a to 25

    I

    "oi' 'isp,ataCD

    *o)t@@FJo)r ,ata is F@@a@@en'H

    I

    IH

    int mainCD

    printfCFheo #or' G N + > > OnOnOnF DH/ o(=H

    5e/t of CS @(A 1$ (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    13/29

    o(=.set,ataCDH

    o(=.get,ataCDH

    o(=.'isp,ataCDH

    I

    o +ompie Jo)r +o'e Kg** 'emo*p)sp)s.*pp -o 'emo*p)sp)s.exe BB -o option #i *reate o(=e*t

    fie #ith gi"en fie name as 'emo*)sp)s.exeto Exe*)te Jo)r +o'e K.B'emo*p)sp)s.exe BB)se of .Bis m)st (efore exe*)ting o)r

    'emo*p)sp)s.exe fie

    Note Lser *an )se man)a of g** for 'etaie' options of *ompiing an' 'e()ging mo'es CK man g**D

    iii Creating a sam/e java 8rogram for demonstrating t.e use of conto statements t.en com/ie andexecute t.e code*ass /

    pri"ate stati* int aH

    p)(i* stati* "oi' get,ataCD

    *o)t@@FENE& ,// M F@@en'H

    I

    stati* "oi' set,ataCD

    a25H BBset the 'efa)t "a)e of a to 25

    I

    stati* "oi' 'isp,ataCD

    *o)t@@FJo)r ,ata is F@@a@@en'H

    I

    IH

    p)(i* stati* "oi' mainC%tring asQD

    printfCFheo #or' G N / / OnOnOnF DH

    / o(=ne# /CDH

    o(=.set,ataCDH

    o(=.get,ataCDH

    o(=.'isp,ataCDH

    I

    o +ompie Jo)r +o'e K=a"a* 'emo=a"a.=a"a BB R the time of *ompiing fiename is gi"en as paramterto =a"a* C=a"a *ompierD

    to Exe*)te Jo)r +o'e K=a"a / BB R the time of interpreting (te*o'e fie *ass name is gi"en

    Note Lser *an )se man)a of g** for 'etaie' options of *ompiing an' 'e()ging mo'es CK man g**D

    5e/t of CS @(A 13 (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    14/29

    Learning Basics of L"'8 Server LAMP is an acronym for a web services solution stack consisting of Linux, the Apache

    HTTP Server, the MySQL or MariaDB database engines, and the PHP or Perl, or

    Python programming language. All components are free and open-source software, andthe combination is suitable for building dynamic web pages.The combination of the

    software included in a LAMP stack may vary, for example the Apache web server can

    be replaced by some other web server software. Although the original authors of these

    programs did not design them to work as a component of the LAMP stack, the

    development philosophy and tool sets are shared and were developed in close

    conjunction. The software combination has become popular because it is entirely free

    and open-source software, which means that each component can be adapted to the

    underlying hardware and customized to meet the specification as exactly as possible,

    without overt vendor lock-in. The complete software stack is also free of cost,maximizing the available budget for tailoring the hardware and software. Due to the

    nature of free and open-source software and the ubiquity of its components, each

    component of the LAMP stack has been tested for performance and security. At the

    same time, continuing development and an abundance of experienced developers

    permit new features and custom modification for specific applications. The components

    of the LAMP stack are present in the software repositories of most Linux distributions, 

    providing a simple way to install, set up and operate a LAMP stack out of the box. The

    website of a small company is typically not subject to high traffic and is not prone to

    frequent attacks, and can therefore be administered with minimal resources.

    The LAMP bundle can be and often is combined with many other free and open-sourcesoftware packages such as, for example:

    • netsniff-ng  for security testing and hardening

    • Snort, an intrusion detection (IDS) and intrusion prevention system (IPS)

    • RRDtool for diagrams

    • Nagios, Collectd or Cacti, for monitoring. 

    5e/t of CS @(A 1! (CS$#1 

    http://en.wikipedia.org/wiki/Comparison_of_lightweight_web_servershttp://en.wikipedia.org/wiki/Free_and_open-source_softwarehttp://en.wikipedia.org/wiki/Free_and_open-source_softwarehttp://en.wikipedia.org/wiki/Vendor_lock-inhttp://en.wikipedia.org/wiki/Software_repositoryhttp://en.wikipedia.org/wiki/Linux_distributionhttp://en.wikipedia.org/wiki/Linux_distributionhttp://en.wikipedia.org/wiki/Linux_distributionhttp://en.wikipedia.org/wiki/Out_of_the_boxhttp://en.wikipedia.org/wiki/Websitehttp://en.wikipedia.org/wiki/Netsniff-nghttp://en.wikipedia.org/wiki/Snort_(software)http://en.wikipedia.org/wiki/Intrusion_detection_systemhttp://en.wikipedia.org/wiki/Intrusion_prevention_systemhttp://en.wikipedia.org/wiki/RRDtoolhttp://en.wikipedia.org/wiki/Nagioshttp://en.wikipedia.org/wiki/Collectdhttp://en.wikipedia.org/wiki/Cacti_(software)http://en.wikipedia.org/wiki/Comparison_of_lightweight_web_servershttp://en.wikipedia.org/wiki/Free_and_open-source_softwarehttp://en.wikipedia.org/wiki/Free_and_open-source_softwarehttp://en.wikipedia.org/wiki/Vendor_lock-inhttp://en.wikipedia.org/wiki/Software_repositoryhttp://en.wikipedia.org/wiki/Linux_distributionhttp://en.wikipedia.org/wiki/Out_of_the_boxhttp://en.wikipedia.org/wiki/Websitehttp://en.wikipedia.org/wiki/Netsniff-nghttp://en.wikipedia.org/wiki/Snort_(software)http://en.wikipedia.org/wiki/Intrusion_detection_systemhttp://en.wikipedia.org/wiki/Intrusion_prevention_systemhttp://en.wikipedia.org/wiki/RRDtoolhttp://en.wikipedia.org/wiki/Nagioshttp://en.wikipedia.org/wiki/Collectdhttp://en.wikipedia.org/wiki/Cacti_(software)

  • 8/16/2019 Open Source Software Technology Lab Manual

    15/29

    x/eriment *o #

    (nstaation "nd Configuration of L"'8 Server on Linux 9Ubuntu:!(=e*ti"e 

    • =ow to (nsta and configure L"'8 Stac+ on Ubuntu

    • Configuring 8./'"dmin for 'S;

    &e:)irements

    Aoos @ "//aratus< Unix@Linux@>indows O/erating Sstem, Medit Aext ditor, L"'8 SA"CJfrom (nternet

    +ercise:

    1 >"8 to c.ec+ w.et.er t.e c.aracter entered is in u//ercase etter, owercase etter, a digit or as/ecia smbo

    Learning Installing LAMP On Ubuntu 

    In this guide I will show you how to install a LAMP system. LAMP stands for Linux, Apache, MySQL,

    PHP. The guide is intended to help those who have very little knowlegde of using Linux.

    Install Apache

    To start off we will install Apache.

    1. Open up the Terminal ( Applications > Accessories > Terminal).

    2. Copy/Paste the following line of code into Terminal and then press enter:

    sudo apt-get install apache2

    3. The Terminal will then ask you for you're password, type it and then press enter.Testing Apache

    To make sure everything installed correctly we will now test Apache to ensure it is working properly.

    1. Open up any web browser and then enter the following into the web address:

    http://localhost/ 

    You should see a folder entitled apache2-default/ . Open it and you will see a message saying "It works!" ,

    congrats to you!

    Install PHP

    In this part we will install PHP 5.

    Step 1. Again open up the Terminal ( Applications > Accessories > Terminal).

    Step 2. Copy/Paste the following line into Terminal and press enter:

    sudo apt-get install php5 libapache2-mod-php5

    5e/t of CS @(A 1# (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    16/29

    Step 3. In order for PHP to work and be compatible with Apache we must restart it. Type the following code

    in Terminal to do this:

    sudo /etc/init.d/apache2 restart 

     Test PHP

    To ensure there are no issues with PHP let's give it a quick test run.

    Step 1. In the terminal copy/paste the following line:

    sudo gedit /var/www/testphp.php

    This will open up a file called phptest.php.

    Step 2. Copy/Paste this line into the phptest file:

    Step 3. Save and close the file.

    Step 4. Now open you're web browser and type the following into the web address:

    http://localhost/testphp.php

    The page should look like this:

    Congrats you have now installed both Apache and PHP!

    Install MySQL

    To finish this guide up we will install MySQL. (Note - Out of Apache and PHP, MySQL is the most difficult

    to set up. I will provide some great resources for anyone having trouble at the end of this guide.)

    Step 1. Once again open up the amazing Terminal and then copy/paste this line:

    sudo apt-get install mysql-server 

    Step 2 (optional). In order for other computers on your network to view the server you have created, you

    must first edit the "Bind Address". Begin by opening up Terminal to edit the my.cnf  file.

    gksudo gedit /etc/mysql/my.cnf 

    Change the linebind-address = 127.0.0.1

    And change the 127.0.0.1 to your IP address.

    Step 3. This is where things may start to get tricky. Begin by typing the following into Terminal:

    mysql -u root 

    Following that copy/paste this line:

    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

    (Make sure to change yourpassword  to a password of your choice.)

    Step 4. We are now going to install a program called phpMyAdmin which is an easy tool to edit your

    databases. Copy/paste the following line into Terminal:

    sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadminAfter that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a

    file entitled php.ini. To open it type the following:

    gksudo gedit /etc/php5/apache2/php.ini

    Now we are going to have to uncomment the following line by taking out the semicolon (;).

    Change this line:

    ;extension=mysql.so

    To look like this:

    extension=mysql.so

    Now just restart Apache and you are all set!

    sudo /etc/init.d/apache2 restart 

    With This We are all set to start Our LAMP Project

    Other Web Links for further Help

    5e/t of CS @(A 1) (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    17/29

    • https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-

    stack-on-ubuntu-14-04h

    • ttps://help.ubuntu.com/community/ApacheMySQLPHP

    5e/t of CS @(A 1- (CS$#1 

    https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04hhttps://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04hhttps://help.ubuntu.com/community/ApacheMySQLPHPhttps://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04hhttps://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04hhttps://help.ubuntu.com/community/ApacheMySQLPHP

  • 8/16/2019 Open Source Software Technology Lab Manual

    18/29

    Learning " 5ee/ 5ive in 'S;

    MySQL officially, but also called "My Sequel" is (as of March 2014) the world's second most[a] 

     widely used open-source relational database management system (RDBMS).It is named after co-founder Michael Widenius's daughter, My. The SQL phrase stands for Structured Query Language.[6]The MySQL development project has made its source code available under the terms of the GNUGeneral Public License, as well as under a variety of proprietary  agreements. MySQL was ownedand sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by OracleCorporation.

    MySQL is a popular choice of database for use in web applications, and is a central component ofthe widely used LAMP open source web application software stack (and other 'AMP' stacks). LAMP

    is an acronym for "Linux, Apache, MySQL, Perl /PHP /Python." Free-software-open source projectsthat require a full-featured database management system often use MySQL.

    For commercial use, several paid editions are available, and offer additional functionality. Applications which use MySQL databases include: TYPO3, MODx, Joomla, WordPress, phpBB,MyBB, Drupal and other software. MySQL is also used in many high-profile, large-scale websites,including Wikipedia

    5e/t of CS @(A 10 (CS$#1 

    http://en.wikipedia.org/wiki/MySQL_server#cite_note-9http://en.wikipedia.org/wiki/Relational_database_management_systemhttp://en.wikipedia.org/wiki/Michael_Wideniushttp://en.wikipedia.org/wiki/SQLhttp://en.wikipedia.org/wiki/Structured_Query_Languagehttp://en.wikipedia.org/wiki/MySQL_server#cite_note-whatismysql-6http://en.wikipedia.org/wiki/Source_codehttp://en.wikipedia.org/wiki/GNU_General_Public_Licensehttp://en.wikipedia.org/wiki/GNU_General_Public_Licensehttp://en.wikipedia.org/wiki/Proprietary_softwarehttp://en.wikipedia.org/wiki/Businesshttp://en.wikipedia.org/wiki/Swedenhttp://en.wikipedia.org/wiki/MySQL_ABhttp://en.wikipedia.org/wiki/Oracle_Corporationhttp://en.wikipedia.org/wiki/Oracle_Corporationhttp://en.wikipedia.org/wiki/LAMP_(software_bundle)http://en.wikipedia.org/wiki/List_of_AMP_packageshttp://en.wikipedia.org/wiki/Linuxhttp://en.wikipedia.org/wiki/Apache_HTTP_Serverhttp://en.wikipedia.org/wiki/Perlhttp://en.wikipedia.org/wiki/PHPhttp://en.wikipedia.org/wiki/Python_(programming_language)http://en.wikipedia.org/wiki/Free_softwarehttp://en.wikipedia.org/wiki/TYPO3http://en.wikipedia.org/wiki/MODxhttp://en.wikipedia.org/wiki/Joomlahttp://en.wikipedia.org/wiki/WordPresshttp://en.wikipedia.org/wiki/PhpBBhttp://en.wikipedia.org/wiki/MyBBhttp://en.wikipedia.org/wiki/Drupalhttp://en.wikipedia.org/wiki/Websitehttp://en.wikipedia.org/wiki/Wikipediahttp://en.wikipedia.org/wiki/MySQL_server#cite_note-9http://en.wikipedia.org/wiki/Relational_database_management_systemhttp://en.wikipedia.org/wiki/Michael_Wideniushttp://en.wikipedia.org/wiki/SQLhttp://en.wikipedia.org/wiki/Structured_Query_Languagehttp://en.wikipedia.org/wiki/MySQL_server#cite_note-whatismysql-6http://en.wikipedia.org/wiki/Source_codehttp://en.wikipedia.org/wiki/GNU_General_Public_Licensehttp://en.wikipedia.org/wiki/GNU_General_Public_Licensehttp://en.wikipedia.org/wiki/Proprietary_softwarehttp://en.wikipedia.org/wiki/Businesshttp://en.wikipedia.org/wiki/Swedenhttp://en.wikipedia.org/wiki/MySQL_ABhttp://en.wikipedia.org/wiki/Oracle_Corporationhttp://en.wikipedia.org/wiki/Oracle_Corporationhttp://en.wikipedia.org/wiki/LAMP_(software_bundle)http://en.wikipedia.org/wiki/List_of_AMP_packageshttp://en.wikipedia.org/wiki/Linuxhttp://en.wikipedia.org/wiki/Apache_HTTP_Serverhttp://en.wikipedia.org/wiki/Perlhttp://en.wikipedia.org/wiki/PHPhttp://en.wikipedia.org/wiki/Python_(programming_language)http://en.wikipedia.org/wiki/Free_softwarehttp://en.wikipedia.org/wiki/TYPO3http://en.wikipedia.org/wiki/MODxhttp://en.wikipedia.org/wiki/Joomlahttp://en.wikipedia.org/wiki/WordPresshttp://en.wikipedia.org/wiki/PhpBBhttp://en.wikipedia.org/wiki/MyBBhttp://en.wikipedia.org/wiki/Drupalhttp://en.wikipedia.org/wiki/Websitehttp://en.wikipedia.org/wiki/Wikipedia

  • 8/16/2019 Open Source Software Technology Lab Manual

    19/29

    x/eriment *o )

    !(=e*ti"e

    • Learning about onfguration o yS+l Ser%er "nstance !

    • reating .L ..L /uerries in .atabase!

    • Accesing 0ser 1oles anagement "n yS+l

    •  

    &e:)irements

      Aoos @ "//aratus< Unix@Linux@>indows O/erating Sstem, Medit Aext ditor, 'S; Server andCient instance

    Exer*ise 

    1 >"8 to design database in 'S;$ "ot oes and 8ermission to new added user3 =ow to monitor t.e server

    5e/t of CS @(A 12 (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    20/29

    asi*s of PSP We( Programming

    PHP is a server-side scripting language designed for web development but also used

    as a general-purpose programming language. As of January 2013, PHP was

    installed on more than 240 million websites (39% of those sampled) and 2.1 million

    web servers.[4] Originally created by Rasmus Lerdorf in 1994,[5] the reference

    implementation of PHP (the Zend Engine) is now produced by The PHP Group.[6]

    While PHP originally stood for Personal Home Page,[5] it now stands for PHP:

    Hypertext Preprocessor, which is a recursive acronym. PHP code can be simply

    mixed with HTML code, or it can be used in combination with various templating

    engines and web frameworks. PHP code is usually processed by a PHP interpreter,

    which is usually implemented as a web server's native module or a Common

    Gateway Interface (CGI) executable. After the PHP code is interpreted and

    executed, the web server sends resulting output to its client, usually in form of a

    part of the generated web page – for example, PHP code can generate a web page's

    HTML code, an image, or some other data. PHP has also evolved to include a

    command-line interface (CLI) capability and can be used in standalone graphical

    applications.PHP is free software released under the PHP License. PHP has been

    widely ported and can be deployed on most web servers on almost every operating

    system and platform, free of charge

    5e/t of CS @(A $4 (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    21/29

    x/eriment *o -

    / PSP *o'e to 'emonstrate the )sage of aria(e< %tring< /rra an' +ontro %tr)*t)re

    !(=e*ti"e

    • Student should start using basics o php %ariable, String, Arays

    • Student should start using ontrol statements in 2hp

     

    5e/t of CS @(A $1 (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    22/29

      &e:)irements

      Aoos @ "//aratus< Unix@Linux@>indows O/erating Sstem, Medit Aext ditor, L"'8 SA"CJ

      +ercise:

    1 Basics of 8=8 scri/ts, variabes, 5ata A/es, O/erators and x/ressions, "rras, oo/[email protected].$NH/./txtPm first string t/e variabeQec.o txtxP#44Q(f 9 x R $PP4:

    ec.o Ex is even noQeseec.o Ex is odd numberQHN@.$N@[email protected]

    $ " 8=8 8roram to im/emet customised Functions

    N.tmNbod

    NH/./Function muti9x,:/roPxTQeturn /roQVec.o Et.e vaue of -T0Pmuti9-,0:QN@HN@[email protected]

    ii " 8=8 8rogram to im/ement Form =andingto demonstrate t.is we need to create $ se/rate fies 1 for storing .tm content $ for storing /./ fie

    first .tm fie wi be as foowsN.tmNbodN.$Su// order formN@.$Nform actionP/rocess/./ met.odP/ostNseect namePboo+No/tion5esign "nasis "nd "gorit.ms N@o/tionNo/tion5ata Structure >it. C66 N@o/tionNo/tion7"%" framewor+s in de/t. N@o/tionNo/tion5istributed Sstems N@o/tionNo/tionO/erting Sstem N@o/tion

    N@seectGuantit < Nin/ut nameP;uantit t/ePtext @

    5e/t of CS @(A $$ (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    23/29

    Nin/ut namePsubmit @N@form N@[email protected] Second /./ /age wi be i+e t.isN.tmNbod

    NH/./;uantitPW8OSAXY;uantitZ[Qc.o Eou ordered ;uantit boo+ Boo+sNbr @Qc.o Et.an+u for orderingHN@[email protected]

    iii " 8=8 8rogram to im/ement 8=8 mai 9: FunctionNH/./to Pabcdef\gmaicomQ

    subjectPASA S*5(*M '"(L US(*M 8=8QmessageP.i t.ere ( .ave send ou t.e mai +ind S8%QfromP.odiu\maicomQ.eadersPFrom< fromQ'ai9to,subject,message,.eaders:Qc.o E'ai Sent Successfu QH

    5e/t of CS @(A $3 (CS$#1 

    mailto:[email protected]:[email protected]:[email protected]:[email protected]

  • 8/16/2019 Open Source Software Technology Lab Manual

    24/29

    earning ,ata(ase +onne*ti"it (et#een PSP an' %:

    Open a Connection to the MySQL Server 

    Before we can access data in a database, we must open a connection to the MySQLserver.

    In PHP, this is done with the mysqi!connect"# function.

    Syntax

    mysqi!connect"host,username,password,dbname#$

    Parameter ,es*ription

    .ost O/tiona it.er a .ost name or an (8 address

    username O/tiona A.e 'SGL user name

     /assword O/tiona A.e /assword to og in wit.

    dbname O/tiona A.e defaut database to be used w.en /erforming ;ueries

    Note: %here are more avaiabe parameters, but the ones isted above arethe most important.

    x/eriment *o 0

    Use the PHP mysqli_connect() function to open a new connection to theMySQL serer!

    In the following example we store the connection in a variable ($con) for later use in the script:

    Close Connection 

    The connection will be closed automatically when the script ends. To close the connection before, usethe mysqli_close() function:

    5e/t of CS @(A $! (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    25/29

    !(=e*ti"e9

    1 Understanding t.e basic conce/ts of for oo/

    $ 5eveo/ing different /atterns

    &e:)irements

      Aoos @ "//aratus< Unix@Linux@>indows O/erating Sstem, Aext ditor, Aurbo C66 (5

      Exer*ise

    1 >"8 for a cacuator using do w.ie

    $ " 8=8 8rogram to demonstrate t.e use of 8=8 mai function1 NH/./

    $ to Pabcdef\gmaicomQ3 subjectPASA S*5(*M '"(L US(*M 8=8Q! messageP.i t.ere ( .ave send ou t.e mai +ind S8%Q# fromP.odiu\maicomQ) .eadersPFrom< fromQ- 'ai9to,subject,message,.eaders:Q0 c.o E'ai Sent Successfu Q2 H

    5e/t of CS @(A $# (CS$#1 

    mailto:[email protected]:[email protected]:[email protected]:[email protected]

  • 8/16/2019 Open Source Software Technology Lab Manual

    26/29

    +onne*ti"it of PSP #ih %:

     

    x/eriment *o 2

    +reate a ogin +ontro for a #e( page to 'emonstrate the )se of +onne*ti"it an' asi*

    retrie"a of 'ata from 'ata(ase

    !(=e*ti"e9

    1 Understanding t.e basic conce/ts of ogin Contro used in most web based User "ut.entication sstem

    $ 5eveo/ing abiit to ana?e t.e /robem statement reated to navigating /agesas /er data given at run time

    &e:)irements

      Aoos @ "//aratus< Unix@Linux@>indows O/erating Sstem, Aext ditor, L"'8 SA"CJ 

      Exer*ise

    1 =ow to create ogin contro and embed it in web /ages

    Soution

    Step 1:-

    Use following sql query to create users table

    CREATE TABLE `users` (`id` int(4) NOT NULL auto_increment,

    `username` varchar(65) NOT NULL default '',

    `password` varchar(65) NOT NULL default '',

    PRIMARY KEY (`id`)

    ) TYPE=MyISAM AUTO_INCREMENT=2 ;

    --

    -- Dumping data for table `users`

    --

    5e/t of CS @(A $) (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    27/29

    Here we are using two database fields , Namely username for storing user id’s for logins and

    password for storing the passwords.

    Step 2:- Create login screen

     After that we need to create a login screen which will ultimately autehnticate user via

    database !, Let’s create a small page and form named login_home.php

    Member Login


    Username :


    Password :


    Step: 3 Authenticating users

    Once a user has entered the username and password on the login_home.php , the form pass

    the values to login_check.php via POST variables , This method is defined at the form

    attribute element on login_home.php.

    Note:- While the values are passed via $_POST variables, we will be querying passwords indatabase after encrypting them with md5 function .

    < ?php

    $db_host="localhost"; // Host name of your database server !, In 90% cases it's localhost

    $db_uname=""; // Mysql username of your database

    $db_passwd=""; // Mysql password of your database

    $db_name="test"; // Database name

    $db_table_name="users"; // Name of the table we created earlier

     // Connect to server and select databse.

    $conn = mysql_connect("$db_host", "$db_uname", "$db_passwd") or die ("cannot connect" .

    mysql_error());

    $conn_db = mysql_select_db("$db_name" , $conn ) or die("cannot select DB" . mysql_error());

     // username and password sent from form

    $form_uname = $_POST['myusername'];

    $form_passwd = $_POST['mypassword'];

     // To protect MySQL injection (more detail about MySQL injection)$form_uname = stripslashes($form_uname);

    5e/t of CS @(A $- (CS$#1 

  • 8/16/2019 Open Source Software Technology Lab Manual

    28/29

    $form_passwd = stripslashes($form_passwd);

    $form_uname = mysql_real_escape_string($form_uname);

    $form_passwd = mysql_real_escape_string($form_passwd);

    $form_passwd = md5($form_passwd); //md5 encryption for querying the password from

    database

    $sql="SELECT * FROM $db_table_name WHERE username='$form_uname' and

    password='$form_passwd'";

    $result=mysql_query($sql);

     // Mysql_num_row is counting table row

    $count=mysql_num_rows($result);

     // If result matched $form_uname and $form_passwd, table row must be 1 row

    if($count==1){ // Register $form_uname, $form_passwd and redirect to file "login_success.php"

    $logged_in = TRUE;

    session_register("form_uname");

    session_register("logged_in");

    header("location:login_success.php");

    }

    else {

    echo "Wrong Username or Password";

    }

    ?>

    Please note that this is not the best way to store passwords , A better way for ensuring

    security is defined in this Password Hashing  tutorial. (Credits John Rockefeller)

    This code will create sessions which can use to authenticate users on the particular pages ,

    These pages just need to check the session value of logged_in , If logged_in is set for true then

    the user is authenticated and else it will be redirected to the login page

    5e/t of CS @(A $0 (CS$#1 

    http://phpsec.org/articles/2005/password-hashing.htmlhttp://www.johnrockefeller.net/http://phpsec.org/articles/2005/password-hashing.htmlhttp://www.johnrockefeller.net/

  • 8/16/2019 Open Source Software Technology Lab Manual

    29/29

    " Sam/e 8roject to create a website for Universit Utiities

    (n t.is /.ase students wi be given various universit reated web based Utiities as form of 5atamanagement sstems

    x/eriment *o 14

     !E+E

    1. Students s.oud abe to Create sim/e 5atabase management >eb based Soutions  2. Lets Student understand t.e rea word >eb Based Software (ndustr Strategies

     

    &e:)irements

     Aoos @ "//aratus< Unix@Linux@>indows O/erating Sstem, Aext ditor, Aurbo C66 (5

      Exer*ise1 8ro/er 5ri for 5ocumentation for a /.ases used in >eb 5eveo/ment Strategies