open source)i
TRANSCRIPT
-
8/8/2019 Open Source)I
1/42
Web DBs & PHP
-
8/8/2019 Open Source)I
2/42
Topics Covered
Database Driven WebOpen Source Software
(LAMP - Linux, Apache, MySQL and PHP)
References
-
8/8/2019 Open Source)I
3/42
Database Driven Web Application
ClientsApplication
Servers includingweb servers
Database Server
A database web application is an application based on World
Wide Web (Internet) and database using web browser as aclient.
Traditional client-server (2-tier architecture):A client
computerhandles the userinterface (Access Forms, Oracle
Forms, Reports) and a database server stores the data. The
actual functionality (business logic) of the application resides
on the client and/orin the databases
Web-based (multi-tier architecture):A client computer
uses a browser to access information from twoormore
servers (web servers, application servers, database servers)(i.e.) A web serverhandles web requests, an application
serverhandles dynamic requests and a database server
stores the data)
-
8/8/2019 Open Source)I
4/42
Three-Tier Architecture
-
8/8/2019 Open Source)I
5/42
Benefits of Web Applications
Free Infrastructure:A major benefit is that the whole
infrastructure is already in place and well developed. Only a web
browseris needed. The new applications can be available to all
the relevant users immediately IT support staffdo not have to go
to eachclient workstation toinstall the Client Software
Free Upgrades:As the application resides on the server, new
versions will be immediately and simultaneously available to every
user. There is no need to distribute updated application files to
every user.
Interchangeable components: It is possible to exchange either
the serveror the browser without breaking the application.
-
8/8/2019 Open Source)I
6/42
Web TechnologiesClient-side
HTML (HyperText Markup Language)CSS (Cascading Style Sheets)
XML (Extensible Markup Language)
DTD (Document Type Declaration)
XSLT (Extensible Style Sheet Language Translator)JavaScript
VBScript/Jscript
Animation (Flash )
Dynamic Hypertext Markup Language (DHTML HTML, JavaScript, CSS & Document Object Model
(DOM)
-
8/8/2019 Open Source)I
7/42
7 10/22/10
Web TechnologiesServer-side
o PHP
o ASP (Active Server Pages) & ASP.NET
o JSP (Java Server Pages)
o Java Servletso C++/Java
o PERL
o XMLDatabase
ODBC
JDBC
OleDB
-
8/8/2019 Open Source)I
8/42
CGI (Common Gateway Interface)
Set ofrules that define how web servercommunicates withother software on the
same machine
Defines how the other software (CGI program)talks back to the web server
Has nothing to do with any particular
programming language!
Often confused with Perl
-
8/8/2019 Open Source)I
9/42
9 10/22/
10
CGI what can it do?Can dynamically create web content
Reacting fromuserinput orotherfactors
For example:
User inputs data intoform Posts it to web server
CGI program
1.receives data
2.processes it
3.and returns tailored page to web serverforuser
-
8/8/2019 Open Source)I
10/42
10 10/22/
10
CGI todayStill used
Widely supported Established standard
Portable
Can return any content supported by server (not just HTML)
But Needs a programmer Perl, C, C++,TCL, BASIC
Can be fiddly to debug
Has been known tocause security problems
CGI Overhead
Fork offnew process
Initialise scripts
Ser verimplementation specificissues!
-
8/8/2019 Open Source)I
11/42
SSI (ServerSide Includes)
Innovation ofNCSA's HTTPD
And non-standard
Simple interface forcreating dynamiccontent
Ifyour application doesnt need an executable
perhaps consider SSI
i.e. including a navigation baron all pages or
house styles
Can only return an HTML page
-
8/8/2019 Open Source)I
12/42
ASP (Active ServerPages)
Microsofts server-side offering
Runs on MS web servers (IIS or PWS)
Latest ASP.NET
You write HTML pages with little bits ofVisual
Basicor C# embedded in between tags
Ser verinterprets them before delivering the
page
Example:
Today is:
-
8/8/2019 Open Source)I
13/42
JSP (Java ServerPages)
Sun Microsystems equivalent ofASP
Based on Java technology
You write HTML with little bits ofJava
embedded in between tags
Ser verinterprets them before delivering the
page
It compiles theminto Servlets (see later)
Example:
Today is:
-
8/8/2019 Open Source)I
14/42
ASP VSJSP
Both simple fast methods ofcreating dynamic webcontent
As compared to CGI
JSP is an industry wide initiative led by Sun
ASP is Microsoft Portability issues?
Apache has roughly 70% share in web server market
& supports JSP via Jakarta Tomcat
So Microsoft got together with Covalent technologies and gotASP.NETonto Apache
JSP can run on NT and IIS web servers through third
party solutions
-
8/8/2019 Open Source)I
15/42
www.opensource.org
Software in a community that is: Freely Used (no warranty, no limits on usage)
Source code is available for any modifications
Freely Extended (must share source, represent original
works and owners) License is not specific to a product or restrict other software
and also technology neutral.
There's always plenty ofprofessional and peersupport from documentation and mailing lists.
Runs on any Platform. Bugs are fixed rapidly, andrequests forfeatures are always heard, evaluated,
and iffeasible,implemented.
Open Source Software
-
8/8/2019 Open Source)I
16/42
Linux (www.linux.com)
*nixflavour that is all the rage at the moment. Similar to Unix but free and runs on just about anything.
Latest version: 9.2
Apache (www.apache.org)
Most popular web page serving software Latest version: 2.0
MySQL (www.mysql.com)
Open source SQL database that is free and extremely powerful
Latest version: 4.1 (though 5.0.1is testing version)
PHP (www.php.net)
PHP ((Hypertext Preprocessor)Hypertext Preprocessor) is mainly focused on server-sidescripting, so youcan do anything any other CGI programcan do,such as collect form data, generate dynamicpage content,or
send and receive cookies. But PHP can domuchmore. Latest version: 4.3 thou h 5 is testin
LAMPLAMP
Free
Coordinated
Cross-platform
Plenty ofsupporthttp://www.lamphost.net/
-
8/8/2019 Open Source)I
17/42
Software UsageSoftware Usage
-
8/8/2019 Open Source)I
18/42
One of the most powerful development models
for the Web has been the notion ofAMP.
AMP stands for AApache /pache / MMySQL /ySQL / PPHPHP &
Perl working together.
AMP
Apache is the
industry-leading
web server thatruns a majority
of web servers
on the Internet.
MySQL is a very
popular
database thatruns on most
operating
systems.
PHP / Perl is a
general purpose
scripting
environment
widely used for
building dynamicweb sites.
Together, they form the nucleus of a web application system.
www.easyphp.org -> contains the software needed for all three packages. You
can install and configure very easily. I am showing the installation separately
-
8/8/2019 Open Source)I
19/42
Apache, MySQL and PHP (AMP)
Integration
User
Us
er
-
8/8/2019 Open Source)I
20/42
20 10
/22/10
Apache - BenefitsApache is well supportedApache is well supported -- Most support for Apache is free andMost support for Apache is free and
ava
ilable 24
hours a day
via Internet
ma
il
or newsgr
oups.a
va
ilable 24
hours a day
via Internet
ma
il
or newsgr
oups.Apache is multiApache is multi--platformplatform -- Apache can run on virtually any hardwareApache can run on virtually any hardware
platform (from PCs tomainframes), and almost any operating system,platform (from PCs tomainframes), and almost any operating system,
such as Linux, Windows, NetWare, Macintosh,xBSD, etc.such as Linux, Windows, NetWare, Macintosh,xBSD, etc.
Apache is secureApache is secure -- security holes are rare but when they exist theysecurity holes are rare but when they exist they
are discovered and fixed quicklyare discovered and fixed quickly
Apache is extensibleApache is extensible -- anyone can write modules that easily plug in toanyone can write modules that easily plug in to
Apache. IfApache doesn't do what you want or need it to do, anyoneApache. IfApache doesn't do what you want or need it to do, anyone
withprogramming skills can write the modules you need.withprogramming skills can write the modules you need.
Apache is databaseApache is database--friendlyfriendly -- youcan interface Apache withvirtuallyyoucan interface Apache withvirtually
any commercial database, such as Oracle, Sybase, DB2, and Informix,any commercial database, such as Oracle, Sybase, DB2, and Informix,
as well as free databases such as MySQL and Postgres.as well as free databases such as MySQL and Postgres.
Apache is hardwareApache is hardware--friendlyfriendly -- Apache generally consumes farfewerApache generally consumes farfewer
hardware resources that commercial web servers.hardware resources that commercial web servers.
No Microsoft VirusesNo Microsoft Viruses -- Apache is immune to the Code Red, Nimda,Apache is immune to the Code Red, Nimda,
and otherviruses that target at Microsoft Web servers.and otherviruses that target at Microsoft Web servers.
-
8/8/2019 Open Source)I
21/42
Installation Apache (ver 2.0.52)
Go tohttp://httpd.apache.org/download.cgi
Ifyou are downloading the Win32 distribution,
please read these important notes at the website
http://apache.mirror.mcgill.ca/httpd/binaries/win32/README.html
Download the binary version
Win32 Binary (MSI Installer): apache_2.0.52-
win32-x86-no_ssl.msi
-
8/8/2019 Open Source)I
22/42
Move to the folder where theMove to the folder where the
Apache is installed and doubleApache is installed and doubleclick on the file to start theclick on the file to start theinstallation.installation.
Welcome screenWelcome screen -- Press NextPress Nextto continueto continue
Apa
che l
icenseA
pa
che l
icense Accept theAccept theterms and Press Nextterms and Press Next
BriefintroBriefintro Read and PressRead and PressNextNext
Server InformationServer Information EnterEnteradmin users emailadmin users email
SetupTypeSetupType TypicalTypical Destination Folder :Destination Folder : leave to theleave to the
default and press Nextdefault and press Next
Wait for installation toWait for installation tocompletecomplete
Youcan change the settingsYoucan change the settings ininhttpd.conf file in conf folderhttpd.conf file in conf folder
Installation Apache (ver 2.0.52)
-
8/8/2019 Open Source)I
23/42
Find the port address Open httpd.confand find the port number : 80,8080orOpen httpd.confand find the port number : 80,8080or8088 (on this machine)8088 (on this machine) c:c:\\programprogramfilesfiles\\ApachegroupApachegroup\\Apache2Apache2\ \conf folderconf folder
Starting Apache service C:ProgramC:Program
FilesFiles\\ApacheGroupApacheGroup\\Apache2Apache2\\binbin\\ApacheMonitor.exe. YouApacheMonitor.exe. Youwill see at the task barwill see at the task bar
Open the monitor and start the apache service ifit is notOpen the monitor and start the apache service ifit is not
done alreadydone already Testing the Apache web server
http://localhost:8088/ Youmay have a different portYoumay have a different portnumbernumber
you will see the test web page.you will see the test web page.
Starting Apache
-
8/8/2019 Open Source)I
24/42
Configuration - Apache Edit and save httpd.conffile:
Alter O ptions Indexes FollowSymLinks into
Options -Indexes FollowSymLinks
Reboot Apache (not computer)
-
8/8/2019 Open Source)I
25/42
MySQL - BenefitsIn 1996T.c.X. DataKonsultAB , a consulting firmin Sweden developed
MySQL.The largest growing relational database out on the market as it can
handle large databases that can be accessed over the Web - Meets
the ANSI SQL92 regulations (SQL-Structured Query Language)
Mainly runs on UNIX-based environments, but alsoused on windows
One of the most used open source databases in the world.Capacity tohandle 50,000,000+ records.
Very fast command execution,perhaps the fastest to be found on the
market.
Flexible and secure password system toprotect your data - powerful
security systemFast, reliable, easy touse, and affordable!
On-line helpfacility - (type help or -?,)
Comes with a source code
Multi-User and works on Several Platforms
-
8/8/2019 Open Source)I
26/42
Installation - MySQL
Go toGo tohttp://dev.mysql.com/downloads/mysql/5.0.htmlhttp://dev.mysql.com/downloads/mysql/5.0.html
and move to Windows (x86)5.0.0aand move to Windows (x86)5.0.0a--alpha26.7Malpha26.7M
Click DownloadClick Download
Create foldercalled mysql and Unzip the fileCreate foldercalled mysql and Unzip the file
ExecuteExecute setup.exesetup.exe
Welcome screenWelcome screen Press Next to continuePress Next to continueInformation:Information: Note down and press NextNote down and press Next
Destination Folder:Destination Folder: Default (c:Default (c:\\mysql)mysql)
Wait forinstallation tocompleteWait forinstallation tocomplete -- Press FinishPress Finish
-
8/8/2019 Open Source)I
27/42
Starting MySQL
Go to C:\mysql\bin
Execute winmysqladmin.exe. You will be prompted for
username and password. Type as admin with password as
admin
You will see the Traffic light signal on the task bar and alsothe admin window
-
8/8/2019 Open Source)I
28/42
Configuration - MySQL
-
8/8/2019 Open Source)I
29/42
MySQL Control Center
Graphical administrative interface for MySQLGraphical administrative interface for MySQLdatabase(s)database(s)
Can administer several DB servers that areCan administer several DB servers that are
hosted on different machineshosted on different machines
Download fromDownload from
http://dev.mysql.com/downloads/other/mysqlcc.html
Execute the fileExecute the file
-
8/8/2019 Open Source)I
30/42
3010/22/10
Open programin programs menuOpen programin programs menu
EstablishconnectionEstablishconnectionto DB serverto DB server
MySQL Control Center - Configuration
-
8/8/2019 Open Source)I
31/42
31 10/22/10
in Databases ignore mysql; delete testin Databases ignore mysql; delete test in User Administration deletein User Administration delete
first twousers and assignfirst twousers and assign
password to root userspassword to root users ignore Server Administrationignore Server Administration
adapt connection (password)adapt connection (password)
MySQL Control Center - Configuration
-
8/8/2019 Open Source)I
32/42
32 10/22/10
Open-source technology
Providing server-side scripting very similar to
ASP/JSP
Source code and distribution freely available
Large community ofdevelopers Implementations for
All major UNIX, Linux and Windows operating
systems
Accessing different databases especially MySQL but others inc Microsoft
Access
PHP Hypertext Preprocessor
-
8/8/2019 Open Source)I
33/42
PHP
A ser ver-side embedded scripting language originallycreated by Rasmus Lerdorf in 1994. PHP has changed
extensively since then.
A PHP web page is a file containing HTML interspersed
with PHP script. the PHP script is executed on the serverand the resulting HTML sent to the client - very similar to
ASP.
PHP syntaxhas muchin common with Java, JavaScript,
Python and Perl. It is designed with the express intentionofmaking server scripting easy tocode.
PHP scripts can run as a Common Gateway Interface
(CGI) application
-
8/8/2019 Open Source)I
34/42
34 10/22/10
PHP how?Any web server
CGI is a standard across most web serversHigh security
PHP runs in it's own process space somalicious
scripts cannot attack the server
...at least that was the ideaHigh reliability
A fault in the PHP does not affect the server
process
Can run as an Apache modulePHP can also run from the command line. This has
gained some popularity so the command line
interpreteris now built by default.
-
8/8/2019 Open Source)I
35/42
35 10/22/10
PHP as an Apache module?Highperformance
the PHP interpreter runs as part of theApache process so nooverhead of
spawning a new process
Persistent database connectivity
PHP does not stop running after servicing
the request
Vulnerable
Opens the possibility ofattacking the serverprocess via a PHP script
-
8/8/2019 Open Source)I
36/42
PHP at UoG
The Unix Apache webserver stuweb.cms.gre.ac.uk runs
5.0.5 and the Windoze IIS servercms-stu-iis.gre.ac.uk
runs 5.2.3 (the Windoze Apache server
stuapache.cms.gre.ac.uk is currently not working). Don't
be too surprised at differences between your domestic
installation and the University servers.
These notes are suitable for both PHP4 and PHP5.
Amongst otherimprovements PHP 5 provides animproved implementation ofDOM and we will use this
when we look more closely at XML.
-
8/8/2019 Open Source)I
37/42
Which OS? The natural home for PHP is a Unix/Linuxplatform runing Apache.
Windoze distributions are usually precompiled binaries, whichis an
endorsement ofone strengthofthe Win32 platform - there are only 4 major
versions tocope with and frequently a single software build can suit all four.
The configuration concepts are howeverpretty much the same for eachplatform so regardless ofthe platformon which you are running there are a
couple ofconfiguration files that it is a good idea tohave a look at and
modify to suit your needs:
httpd.conf- the main apache config filephp.ini - the main PHP config file
-
8/8/2019 Open Source)I
38/42
38 10/22/10
PHP - BenefitsEasy,powerful,popularEasy,powerful,popular
ServerServer--side scripting languageside scripting languageSupports many DBs (not only MySQL)Supports many DBs (not only MySQL)
Platform IndependentPlatform Independent
Web Server IndependentWeb Server Independent
Free and Open SourceFree and Open SourcePHP Overtakes Microsoft ASP as the Webs Number
1 server side Web technology for the Internet.
An recent Netcraft surveys indicated 24 percent ofthe 37.6million websites,or are running PHP scripts.
PHP adoption is growing by 6.5 percent eachmonth.
(9million sites)
-
8/8/2019 Open Source)I
39/42
39 10/22/10
PHP & MySQLBooks1. PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide by Larry
Ullman, Peachpit Press, May 200
3, ISBN0
-321
-1
8648-6, 572 pages2. Web Database Applications with PHP & MySQL by Hugh E. Williams & David
Lane O'Reilly & Associates, Mar 2002, ISBN 0-5960-0041-3, 582 pages
3. PHP MySQL Website Programming by Chris Lea, Mike Buzzard, Jessey White-
Cinis & DilipThomas Wrox Press Inc, Mar 2003, ISBN 1-861008-27-9, 500
pages
4. Sams TeachYourselfPHP, MySQL and Apache All in One By Julie Meloni,
SAMS, ISBN: 0672326205;
5. PHP Professional Projects by Ashish Wilfred, Meeta Gupta, Kartik Bhatnagar,
ISBN: 1-931841-53-5 2002
6. Beginnning PHP 5 and MySQL: From Novice to Professional by W. J. Gilmore
7. PHP and MySQL Web Development (3rd edition) by Luke Welling, Laura
Thomson
-
8/8/2019 Open Source)I
40/42
40 10/22/10
PHP Referenceswww.php.net
-
8/8/2019 Open Source)I
41/42
MySQL References http://www.mysql.com/http://www.mysql.com/ -- THE OFFICIAL MYSQLTHE OFFICIAL MYSQL
WEBSITEWEBSITE http://www.mysql.com/documentation/http://www.mysql.com/documentation/ -- CODING/HELPCODING/HELPDOCUMENTATIONDOCUMENTATION
http://www.mysql.com/information/presentations/presenthttp://www.mysql.com/information/presentations/presentationation--ede2000ede2000--20001010/20001010/ -- SYNTAX EXPLAINEDSYNTAX EXPLAINED
http://hotwired.lycos.com/webmonkey/programming/php/http://hotwired.lycos.com/webmonkey/programming/php/tutorials/tutorial4.htmltutorials/tutorial4.html
PHP AND MYSQL TUTORIALPHP AND MYSQL TUTORIAL
http://www.devshed.com/Server_Side/MySQLhttp://www.devshed.com/Server_Side/MySQL -- THETHEDEVELOPER SHED (MYSQL INFO.)DEVELOPER SHED (MYSQL INFO.)
http://www.faqts.com/knowledge_base/index.phtml/fid/94http://www.faqts.com/knowledge_base/index.phtml/fid/94MYSQL QUERIES AND COMMON PROBLEMSMYSQL QUERIES AND COMMON PROBLEMS
www.mysql.comwww.mysql.com
http://www.freewebmasterhelp.com/tutorials/phpmysqlhttp://www.freewebmasterhelp.com/tutorials/phpmysql
-
8/8/2019 Open Source)I
42/42
The end
Thank youfor listenning