computerssincetheearly1980s(hisfirstcomputer wasaTandyTRS80Model1withamassive4KB ofRAM!).Duringthistimehehaswritteninexcess of500articlesformanyoftheUK’stopcomputer magazines.Plug-inPHPishisfourthbook.
RobinlivesonthesoutheastcoastofEngland withhiswife,Julie,atrainednurse,andfivechildren, wherehealsofindstimetofosterthreedisabled children,aswellasworkingfulltimefromhome asatechnicalauthor.
About the Technical Editor
Plug-in PHP
100 POWER SOLUTIONS
RobinNixon
ISBN: 978-0-07-166660-2 MHID: 0-07-166660-5
The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-166659-6, MHID: 0-07-166659-1.
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps.
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs. To contact a representative please e-mail us at bulksales@mcgraw-hill.com.
Information has been obtained by McGraw-Hill from sources believed to be reliable. However, because of the possibility of human or mechanical error by our sources, McGraw-Hill, or others, McGraw-Hill does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use of such information.
TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms.
Contents at a Glance
Contents
Acknowledgments ............................................... xxiii Introduction ..................................................... xxv
1 BuildingaDevelopmentServer .................................... 1
WindowsXP,WindowsVista,andWindows7 ........................ 2 ReinstallingZendServerCE .................................. 8 UpgradingZendServerCE .................................. 8 WindowsSecurityAlerts ..................................... 8 AfterInstallation ............................................ 8 Uninstalling ................................................ 11 DocumentRoot ............................................. 12 UbuntuandDebianLinux ......................................... 12 Uninstalling ................................................ 14 AfterInstallation ............................................ 15 DocumentRoot ............................................. 16 Fedora,RHEL,andCentOSLinux ................................... 16 InstallingMySQL ........................................... 16 Uninstalling ................................................ 16 DocumentRoot ............................................. 17 OtherVersionsofLinux ............................................ 17 InstallingMySQL ........................................... 17 Uninstalling ................................................ 17 DocumentRoot ............................................. 17 MacOSX10.4PlusonIntelChips ................................... 18 DocumentRoot ............................................. 20 Uninstalling ................................................ 21 MacOSX10.3 .................................................... 21 DocumentRoot ............................................. 24 ConfiguringErrorHandlinginZendServerCE ....................... 25 AndNowYou’reSettoGo ......................................... 25
2 UsingthePlug-ins ................................................ 27
3 TextProcessing ................................................... 33
Plug-in9:RemoveAccents ......................................... 55 AboutthePlug-in ........................................... 56 Variables,Arrays,andFunctions .............................. 56 HowItWorks .............................................. 56 HowtoUseIt .............................................. 56 ThePlug-in ................................................ 56 Plug-in10:ShortenText ............................................ 57 AboutthePlug-in ........................................... 57 Variables,Arrays,andFunctions .............................. 57 HowItWorks .............................................. 57 HowtoUseIt .............................................. 58 ThePlug-in ................................................ 58
4 ImageHandling .................................................. 59
Plug-in17:ImageDisplay .......................................... 76 AboutthePlug-in ........................................... 76 Variables,Arrays,andFunctions .............................. 77 HowItWorks .............................................. 77 HowtoUseIt .............................................. 77 ThePlug-in ................................................ 78 Plug-in18:ImageConvert ......................................... 78 AboutthePlug-in ........................................... 79 Variables,Arrays,andFunctions .............................. 79 HowItWorks .............................................. 79 HowtoUseIt .............................................. 79 ThePlug-in ................................................ 79 Plug-in19:GifText ................................................ 80 AboutthePlug-in ........................................... 81 Variables,Arrays,andFunctions .............................. 81 HowItWorks .............................................. 81 HowtoUseIt .............................................. 82 ThePlug-in ................................................ 82 Plug-in20:ImageWatermark ....................................... 83 AboutthePlug-in ........................................... 83 Variables,Arrays,andFunctions .............................. 84 HowItWorks .............................................. 84 HowtoUseIt .............................................. 85 ThePlug-in ................................................ 85
5 ContentManagement ............................................. 87
Plug-in25:QueryHighlight ........................................ 98 AboutthePlug-in ........................................... 98 Variables,Arrays,andFunctions .............................. 98 HowItWorks .............................................. 98 HowtoUseIt .............................................. 99 ThePlug-in ................................................ 100 Plug-in26:RollingCopyright ....................................... 100 AboutthePlug-in ........................................... 101 Variables,Arrays,andFunctions .............................. 101 HowItWorks .............................................. 101 HowtoUseIt .............................................. 101 ThePlug-in ................................................ 101 Plug-in27:EmbedYouTubeVideo .................................. 101 AboutthePlug-in ........................................... 101 Variables,Arrays,andFunctions .............................. 102 HowItWorks .............................................. 102 HowtoUseIt .............................................. 102 ThePlug-in ................................................ 103 Plug-in28:CreateList ............................................. 103 AboutthePlug-in ........................................... 104 Variables,Arrays,andFunctions .............................. 104 HowItWorks .............................................. 104 HowtoUseIt .............................................. 104 ThePlug-in ................................................ 105 Plug-in29:HitCounter ............................................ 105 AboutthePlug-in ........................................... 105 Variables,Arrays,andFunctions .............................. 105 HowItWorks .............................................. 106 HowtoUseIt .............................................. 106 ThePlug-in ................................................ 107 Plug-in30:RefererLog ............................................ 108 AboutthePlug-in ........................................... 108 Variables,Arrays,andFunctions .............................. 108 HowItWorks .............................................. 108 HowtoUseIt .............................................. 109 ThePlug-in ................................................ 109
6 FormsandUserInput ............................................. 111
7 TheInternet ..................................................... 141
Plug-in49:RSStoHTML ........................................... 168 AboutthePlug-in ........................................... 168 Variables,Arrays,andFunctions .............................. 169 HowItWorks .............................................. 169 HowtoUseIt .............................................. 169 ThePlug-in ................................................ 170 Plug-in50:HTMLtoMobile ........................................ 170 AboutthePlug-in ........................................... 172 Variables,Arrays,andFunctions .............................. 172 HowItWorks .............................................. 172 HowtoUseIt .............................................. 173 ThePlug-in ................................................ 173
8 ChatandMessaging .............................................. 175
Plug-in57:SendDirectTweet ....................................... 196 AboutthePlug-in ........................................... 196 Variables,Arrays,andFunctions .............................. 197 HowItWorks .............................................. 197 HowtoUseIt .............................................. 197 ThePlug-in ................................................ 197 Plug-in58:GetTweets ............................................. 198 AboutthePlug-in ........................................... 198 Variables,Arrays,andFunctions .............................. 199 HowItWorks .............................................. 199 HowtoUseIt .............................................. 199 ThePlug-in ................................................ 200 Plug-in59:ReplaceSmileys ........................................ 200 AboutthePlug-in ........................................... 201 Variables,Arrays,andFunctions .............................. 201 HowItWorks .............................................. 201 HowtoUseIt .............................................. 201 ThePlug-in ................................................ 202 Plug-in60:ReplaceSMSTalk ....................................... 203 AboutthePlug-in ........................................... 203 Variables,Arrays,andFunctions .............................. 204 HowItWorks .............................................. 204 HowtoUseIt .............................................. 204 ThePlug-in ................................................ 205
9 MySQL,Sessions,andCookies .................................... 207
Plug-in65:CreateSession .......................................... 221 AboutthePlug-in ........................................... 222 Variables,Arrays,andFunctions .............................. 222 HowItWorks .............................................. 222 HowtoUseIt .............................................. 222 ThePlug-in ................................................ 223 Plug-in66:OpenSession ........................................... 223 AboutthePlug-in ........................................... 224 Variables,Arrays,andFunctions .............................. 224 HowItWorks .............................................. 224 HowtoUseIt .............................................. 224 ThePlug-in ................................................ 224 Plug-in67:CloseSession ........................................... 225 AboutthePlug-in ........................................... 225 Variables,Arrays,andFunctions .............................. 225 HowItWorks .............................................. 225 HowtoUseIt .............................................. 226 ThePlug-in ................................................ 226 Plug-in68:SecureSession .......................................... 226 AboutthePlug-in ........................................... 227 Variables,Arrays,andFunctions .............................. 227 HowItWorks .............................................. 227 HowtoUseIt .............................................. 227 ThePlug-in ................................................ 228 Plug-in69:ManageCookie ......................................... 228 AboutthePlug-in ........................................... 229 Variables,Arrays,andFunctions .............................. 229 HowItWorks .............................................. 229 HowtoUseIt .............................................. 229 ThePlug-in ................................................ 230 Plug-in70:BlockUserbyCookie .................................... 230 AboutthePlug-in ........................................... 231 Variables,Arrays,andFunctions .............................. 231 HowItWorks .............................................. 231 HowtoUseIt .............................................. 232 ThePlug-in ................................................ 233
10 APIs,RSS,andXML .............................................. 235
11 IncorporatingJavaScript .......................................... 277
Plug-in89:WordsfromRoot ....................................... 302 AboutthePlug-in ........................................... 303 Variables,Arrays,andFunctions .............................. 303 HowItWorks .............................................. 303 HowtoUseIt .............................................. 303 ThePlug-in ................................................ 304 Plug-in90:PredictWord ........................................... 304 AboutthePlug-in ........................................... 305 Variables,Arrays,andFunctions .............................. 305 HowItWorks .............................................. 305 HowtoUseIt .............................................. 306 ThePlug-in ................................................ 306
12 DiverseSolutions ................................................ 309
Plug-in97:GoogleTranslate ........................................ 324 AboutthePlug-in ........................................... 324 Variables,Arrays,andFunctions .............................. 325 HowItWorks .............................................. 325 HowtoUseIt .............................................. 325 ThePlug-in ................................................ 326 Plug-in98:CornerGif ............................................. 327 AboutthePlug-in ........................................... 327 Variables,Arrays,andFunctions .............................. 328 HowItWorks .............................................. 328 HowtoUseIt .............................................. 328 ThePlug-in ................................................ 329 Plug-in99:RoundedTable ......................................... 330 AboutthePlug-in ........................................... 331 Variables,Arrays,andFunctions .............................. 331 HowItWorks .............................................. 331 HowtoUseIt .............................................. 331 ThePlug-in ................................................ 332 Plug-in100:DisplayBingMap ...................................... 332 AboutthePlug-in ........................................... 333 Variables,Arrays,andFunctions .............................. 333 HowItWorks .............................................. 333 HowtoUseIt .............................................. 333 ThePlug-in ................................................ 334
Acknowledgments
Introduction
P
HPisanopen-source(andthereforefree)scriptinglanguageforcreatingdynamic webpages.Sinceitscreationin1995,itspopularityhasgrowntomorethandouble thatofthepreviouslymostusedscriptinglanguage,Perl.Infact,PHPisnowinthetopfivemostpopularandmostusedlanguagesaccordingto amajorityofsurveys,whichishardlysurprisingbecauseitisprovidedwithmostweb hostingaccounts,iseasytointegrateintowebpages,isextremelyfast(giventhatitis interpreted),andithasbuilt-inlinkstoMySQL,theworld’smostpopularopen-source databaseprogram.
Becauseitwaswrittenbyandforprogrammers,PHPcomeswithanextensivelibraryof featuresandfunctionsthatmaybaffleabeginner.Butitispossibletousejustasmallcore subsetofthesetocreatemostofthedynamiccontentawebmastercouldneed,whichis preciselywhatthisbookdemonstrates.
Plug-inPHPisaimedsquarelyatwebsiteownerswhohavelearnedbasicHTMLand PHPandareinterestedindoingmorewiththeirsites.Forexample,youmaywishtocreate memberareasprotectedbyusernamesandpasswords,orwanttowriteasimpleGuestbook andsoon.UsingPlug-inPHP,youwilllearnhowtodoallthesethingsandmuchmore usingverysimpleready-madePHP.
Itisneverassumedthatyoualreadyknowsomething,soyouaretakenthrougheach subjectstepbystepwithfullexplanations,makingsureyouneverhavetogoelsewhereto findtheinformationyouneed.Thisbookalsopurposefullyignoresmoreadvancedtopics suchasobject-orientedprogramming.Instead,thecodesampleslookverymuchlikeacross betweensimpleCandBasic.Elegant,tightstructuresthatmoreadvancedprogrammers mightappreciatearesetasideinpreferenceformoreunderstandablecode,wheretheflow fromanypointtoanyotherisasobviousaspossible.
Alloftheplug-insandexamplesarewritteninacompleteandready-to-useform thatyoucantypeintoyourownwebpages.Evenifyouhavealmostnoknowledgeof programming,youcanstillmakefulluseofthebook,whichcanbedippedintoasrequired sinceeachchapterismostlyself-contained.Thismeansthatwhereveryouhaveaproblem onyourwebsiteyoucansimplyrefertotherelevantchapter,whichshouldbeallyouneed tosolveit.
About PHP
• Yahoo! Apopularsearchengine(seeFigure1)
• Facebook Asocialnetworkingsite
• Wikipedia Acollaborativeencyclopedia
• Photobucket Aphotosharingservice
Actually,Yahoo!shouldn’tbetoomuchofasurprisebecauseRasmusLerdorfhas workedatthecompanyasaDistinguishedEngineersince2002.
SowhyisPHPsopopular?Therearethreemainreasons.First,PHPintegratesseamlessly withHTML.Evenifyouknownexttonoprogramming,it’sveryeasytorenameyour.html filesto.phpandtheywillautomaticallybecomePHPprograms,albeitonesthatdisplay themselvesasanHTMLpage.Butthen,wheneveryouneedalittledynamicfunctionality, youcandropinaquicklineofPHPcode,likethefollowingsnippet,whichwilldisplaythe dayoftheweek:
<?phpechodate("l");?>
Second,it’seasytolearn.WithafewsimplePHPfunctionsunderyourbelt,almost withoutknowingit,you’realreadyaPHPprogrammer.Addinforloopsandacoupleof otherconstructsandyoucanveryquicklystartmakingyourowndynamicwebsites.
Third,there’sexcellentsupportfromthePHPprogrammingcommunityandbooks suchasthis.Justtype“helpPHP”intoGoogleandyou’llbepresentedwithastaggering 125millionsearchresults.
What This Book Provides
HavingaccesstoallofPHP’sfunctionsisn’tveryusefulwhenyouneedtoquicklyput togetheraprojecttoatightdeadline,becausethefunctionstypicallyprovideveryspecific functionality.EvenPEARplug-insarenotalwaysthecompletesolutioneither,sincethey usuallytaketimetolearnandstillmustbewrappedinPHPcodeofyourowndevising.
That’swherethisbookcomesintoitsown,becauseitprovides100ready-to-goplug-ins youcansimplydropintoyourprogramsanduse,normallywithasimple,singlecall.Of course,becauseallprojectsaredifferentIonlyprovidethebarebonesneededandleave layoutandstylingtotheabsoluteminimum.Thisleavesyoufreetograbaplug-in,insertit intoyourownprogram,andthentailorittoyourexactrequirements.
Thetypesofplug-inssuppliedofferquickandsimplesolutionstoaverywiderangeof problemsincludingprocessingtextinavarietyofways,uploadingandmanipulating images,servercontentmanagement,formhandling,userinputvalidation,chatand messaging,userauthenticationandsecurity,integrationwiththird-partywebsites,and muchmorebesides.
Withthemyoucanavoidhavingtoreinventthewheeleachtimeyouneedanew feature,becausethechancesarethatthemoduleyouneed(oroneverysimilar)canbe foundinthisbookasaplug-in.Andevenifitisn’t,becauseeachandeveryplug-inis brokendownintocomponentpartsandexplainedindetail,youshouldfindyoucan cherry-pickcodesegmentsfromdifferentplug-instobuildyourown.
About the Plug-ins
Allofthisbook’splug-insareready-to-runandcanbeeithertypedinifyoudon’thave Internetaccess,oryoucandownloadthemfromwww.pluginphp.com(seeFigure2)where theyarestoredasbothindividualplug-insandalsogroupedintolargercollectionsby theme.Forexample,alltheauthenticationandsecurityplug-inscanbefoundinthefile security.php.
Whenyouvisitthewebsite,youcannavigatethroughtheplug-inschapterbychapter, andalsoviewthePHPprogramcodehighlightedincolorforclarity.Fromthere,youcan copy,paste,ordownloadindividualplug-ins,groups,orthewholecollectiondirectlyto yourcomputer.
What Is and Isn’t Included
AlthoughthefirstaimofthisbookistoprovidenewcomerstoPHPwithacomprehensive resourceoffunctionsandroutinestodrawon,ithasasecondarygoal,whichistohelpyou moveuptothenextlevelandtocreateyourownprogrammingtoolkit.Thereforeevery plug-inisthoroughlydocumentedandexplainedindetail,andadviceisgivenonwaysto improveandextendthem,aswellashowtoadaptthemtoyourownrequirements.
Andwhilethisbookisn’taprogrammingmanualorateachingguide,Idohopethatby readingthroughtheplug-inexplanations,ratherthanjustincludingtheminyourprojects, you’llpickupanumberoftipsandtricksthatmanyprogrammerstakeyearstodiscover, andbyosmosisyouwilllearnmoreaboutthePHPprogramminglanguage.
Plug-in License
Youarefreetouseanyoftheplug-insinthisbookinyourownprojects,andmaymodify themasnecessary,withoutattributingthisbook—althoughifyoudoso,itwillalwaysbe appreciated.
However,youmaynotsell,giveaway,orotherwisedistributetheplug-insthemselves inanymanner,whetherprintedorinelectronicformat,withoutthewrittenpermissionof thepublisher.
Companion Web Site
Thewebsiteisbestusedinconjunctionwiththisbook.Asyoureadachapter,callitup onthewebsite,too,andyoucanlisteachplug-inonscreenwithcolor-highlightedsyntax. Thismakesitveryeasytoseethestructureofeachprogram.
Whenyouwishto,youcanclickalinktocopyandpasteaparticularplug-inrightinto yourownprograms.Or,ifyouprefer,youcandownloadalloftheplug-instoyourcomputer fromwhereyoucanpicktheone(s)touploadtoyourownwebsite.
Tohelpyouwithaccessingthem,theplug-insareallstoredingroupsoftenperfile, eachfilehavingacertaintheme,suchasimagemanipulationortextprocessing,andsoon. Youcanthencopyandpastefromthesefiles,oruseaPHPincludecommandto
incorporatetheminyourownprograms.
CHAPTER 1
W
hencreatingplainHTMLwebsites,it’seasytodevelopthemonapersonalcomputer becausenowebserverisneededtoserveupthepages.Yousimplyloadtheminto yourbrowseranddisplaythem.ThesamegoesforJavaScriptandevenFlash. However,whenitcomestoPHPit’sawholedifferentballgamebecauseyouneeda numberofnewprograms,suchasthePHPparserandinterpreter,andawebservertotake theoutputfromPHPandreturnHTMLpages.Plus,ifyou’llbeaccessinganydata,you’ll alsoneedadatabaseprogramsuchasMySQL.Untilafewyearsago,youronlysimplechoicewastofindahostingcompanythat wouldsetyouupwithaserverwithalltheseoptionsalreadyinplace.Alternatively,ifyou wereanexpert,youcouldinstalleachoftheseitemsseparatelyandconfigurethemtowork witheachother,aprocessoftenfraughtwithmanyhoursoftweakingandhairpulling beforeeverythingwouldworkcorrectly.
Recently,however,anumberofWAMP,MAMP,andLAMPpackageshavesprungup. Respectively,thesestandforWindows/Mac/Linux,Apache,MySQL,andPHPandthey provideanintegratedinstallationenvironmenttoautomaticallyconfigurethevarious elementstoproperlyinteractwitheachother.Evenso,someofthemstillneededabitof tweakingonless-than-standardinstallations.
Early2009,though,sawthereleaseofZendServerCEfromZend,thecompanybehind PHPitself.TheCEstandsforCommunityEdition,whichmeansit’sfreeandcommunity supported,andit’strulyaqualityproduct.WhilenotaspowerfulastheoriginalZend Server,whichwasdesignedforrunningandmanagingbusiness-criticalPHPapplicationsin production,it’sabsolutelyperfecttouseasadevelopmentplatform,andisavailableforall ofthefollowing:
• WindowsXP,servicepack2
• WindowsVista(excludingStarter)
• Windows7
• MostflavorsofLinux
• MacOSX10.4plusrunningonIntelchips
ZendServerCEcomeswitheverythingyouneed,includingApacheandPHP(andwith alittleconfiguring,MySQL,too)andisveryeasytoinstall.However,becausetheprocess variesbyplatform,Ihavedivideditsinstallationintodifferentsectionshere.Soplease choosetheonerelevanttoyourcomputer.
Windows XP, Windows Vista, and Windows 7
ToinstalltheprogramonaWindowsmachine,youneedtovisitthefollowingURLand downloadtheWindowsinstallationfile(seeFigure1-1):www.zend.com/en/products/server/ downloads-all.
FIGURE 1-1 Downloading the Windows Zend Server CE installation program
FIGURE 1-2 If prompted by User Account Control, click Yes to confirm installation.
double-clickthefile.IfyouarerunningWindowsVistaorWindows7,andaUserAccount ControlboxsuchasthatdisplayedinFigure1-2,clickYestocontinue.
ThescreeninFigure1-4willappear.ClicktheNextbuttontocontinue.
Afterawhile,theinstallerwillhavegatheredenoughinformationtocontinuewith theinstallationandyouwillbepromptedtoagreetothetermsoftheEnd-UserLicense Agreement(seeFigure1-5).
NextyouareaskedwhethertheprogramshouldperformaTypical,Full,orCustom installation(seeFigure1-6).SelectCustomatthispointsoyoursetupwillagreewiththe onedescribedinthischapter.Youcanalwaysre-installagainlaterwithdifferentoptionsif youneedto.
FIGURE 1-3 Click Yes when the Zend installer asks if you wish to continue.
Havingtoldtheinstalleryouneedacustominstallation,youmustnowsetanoptionto ensurethatMySQLgetsinstalledaswell.Todothis,scrolldownthroughthelistof
components(showninFigure1-7)until,neartheend,youseeMySQLServer.Clickits checkbox,andthenclickNext.
YouwillbeaskedwhetheryouwishtoinstallanApacheWebServerorconfigurean existingIISserver(seeFigure1-8).ThelatteroptionwillbedisabledifIISisnotinstalled. IrecommendyouchoosetheApacheoptionanyway,atleastuntilyouhaveverifiedthatthe plug-insinthisbookworkcorrectlyforyou.Youcanalsochoosewheretoinstallthe program(bydefaultitwillbeC:\ProgramFiles\Zend).Ifyouchoosetochangethis,then youwillalsoneedtoremembertousetheappropriatedirectorytoaccessthisfolderwhen thepathnameisreferencedlaterinthischapterandelsewhereinthebook.
If,atthenextscreen,youarepromptedforthewebserverportnumber,leavethe defaultvalueof80whichwillbeoffered,andclickNext.Whenfinishedwiththeseinitial settings,you’llbepresentedwithaconfirmationscreenwhereyoucanreviewthem(see Figure1-9).Iftheyarenotcorrect,clicktheBackbuttonandamendthem;otherwise,click theInstallbutton.
Duringinstallation,youmaybeshownthedialoginFigure1-13(seetheWindows SecurityAlertssection).YoumustclickAllowAccessforApachefortheinstallationtowork properly.Uponsuccessfullycompletingtheinstallation,thescreeninFigure1-10will display.HereyoucanchoosewhethertocreateaDesktopshortcutbeforeclickingFinish.
Reinstalling Zend Server CE
IfyouhavealreadyinstalledZendServerCEandarereinstallingit,eithertochangethe installationoptions,ortorepairafaultyinstall,youwillbepresentedwiththescreenin Figure1-11(insteadoftheonementionedearlier),whereyoucanalsochoosetouninstall theprogramifyouwish.
Upgrading Zend Server CE
Theprocessofupgradingtheprogramtoanewerversionismuchquickerthananinitial installation,comprisingonlyasinglemainscreen,asshowninFigure1-12.Notethe warningissuedhere,thatonceupgradedyoucannotrollbacktoanearlierversion.You willnotseethisscreenifyouareonlyreinstallingthesameversionasisalreadyinstalled.
Windows Security Alerts
If,atanypointduringinstallation,youreceiveaWindowsSecurityAlert,suchastheonein Figure1-13,askingwhethertounblocktheApacheserver,clickAllowAccess(onWindowsVista and7)orUnblock(onWindowsXP)tograntfullaccesstoZendServerCEanditscomponents.
After Installation
FIGURE 1-13 If prompted by a Windows Security Alert, you should unblock any Zend Server components.
reinstallingorupgrading,you’llsimplybeaskedtoconfirmthepreviouspasswordyou created.Youcanalsoenteryoure-mailaddressifyou’dliketoreceivetheZendnewsletter.
C
AUTION
IfyouwillbeforwardingHTTPrequestsfromtheInternettoyourserver(not recommendedpermanentlybutusefulforgrantingacolleaguetemporaryaccesstoaprojectin progress),thenit’sparticularlyimportantthatyouchooseaverysecurepassword.Nowyouaresetupandreadytogo,andthescreenshowninFigure1-15willdisplayin yourbrowser.FromthisscreenyoucancontrolvariousaspectsofyourZendServerCE installation.
Youcanverifythateverythingisworkingcorrectlybyenteringhttp://localhostintoyour webbrowser.TheresultshouldlooklikeFigure1-16.
Uninstalling
TouninstallZendServerCE,fromtheStartMenuselectAllPrograms|ZendServer CommunityEdition|UninstallZendServer.
Document Root
Bydefault,yourdocumentroot(theplacewhereallyourHTMLandPHPfilesshouldbe stored)isc:\ProgramFiles\Zend\Apache2\htdocs.Ifyoufindthatyoucannoteditorsave filesintoit,youwillneedtomodifythefolder’spermissionsettings.Youmayfindit convenienttocreateashortcuttothisfolderbynavigatingtoit,rightclicking(andholding) onthehtdocsfolder,anddraggingittotheDesktop.Onceyoureleasethemousebutton,you canthenselectCreateShortcutsHere.
Ubuntu and Debian Linux
OnUbuntuorDebianLinux,youwillneedtoinstalltheMySQLprogramseparatelyifyou don’thaveitalready.It’sveryeasytodobecauseitusesAptitude,afrontendtothe AdvancedPackagingTool(APT)system.
JustopenuptheTerminalbyselectingApplications|Accessories|Terminaland enteringthefollowingtwocommands,thefirstofwhichensuresyouarerunningasroot, whilethesecondinstallstheserver.Ifyouarepromptedforyourpassword,enterit.Atthe endoftheinstallation,youmaybepromptedtoenterarootpasswordasinFigure1-17, which,likeallthefollowingLinuxscreengrabs,isfromUbuntuLinux.
sudo-i
apt-getinstallmysql-server
YouarenowreadytoinstallZendServerCEitself.Theprocesstakesafewcommands tosetupbecauseyoumustfollowseveralsteps.First,stayingintheTerminalwindow,you needtochangetothe/etc/aptfolderandtheneditthefilesources.listbytypingthefollowing (assumingyouarestillloggedinasrootafterinstallingMySQL):
cd/etc/apt nanosources.list
T
IP
IfyouareusingDebianLinuxratherthanUbuntu,andNanoisnotyourdefaulttexteditor, youshouldalterthesecondlineoftheprecedingcodeaccordingtotheeditoryouuse.Oryoucan installNanofirstbyenteringthecommand:apt-getinstallnano.Oncethefileisopen,scrolldownandaddthefollowinglinetotheendofthefilesoit lookslikeFigure1-18.Whendone,pressCTRL-X,followedbyYandthenpressRETURNtosave
themodifiedfile:
debhttp://repos.zend.com/zend-server/debservernon-free
NowyoumustfetchZend’srepositorypublickeysotheinstallationfilecanbeverified oncedownloadedand,havingsetupthesevariousitems,youshouldalsoupdateAptitude. So,enterthefollowingtwocommands,notingthattheoptioninthemiddle,whichlooks like
-O-
,isanuppercaseletterO
sandwichedbetweentwominussigns,ordashes:wgethttp://repos.zend.com/deb/zend.key-O-|apt-keyadd- aptitudeupdate
Finally,youarereadytoinstallZendServerCEitselfwiththefollowingcommand(see Figure1-19):
aptitudeinstallzend-server-ce-php-5.2
Uninstalling
Shouldyouencounteranyproblems,ordecideforanyotherreasontouninstallthe program,youcanissuethefollowingcommand:
aptituderemove'~nzend.*-ce'
After Installation
ThelastthingyouneedtodoinordertoverifywhetherZendServerCEhasactually installedcorrectlyistotestoutthewebserverbyenteringtheURLhttp://localhostinto yourbrowser.Ifeverythingiscorrect,youshouldgetatersemessagesimilartotheone inFigure1-20.YoucannowentertheAdmininterfacebyenteringhttp://localhost:10081 intoyourbrowser.
FIGURE 1-19 The installation of Zend Server CE is successful.