Tải bản đầy đủ - 0 (trang)
Chapter 3. Installing and Configuring PHP

Chapter 3. Installing and Configuring PHP

Tải bản đầy đủ - 0trang

CurrentandFutureVersionsofPHP

TheinstallationinstructionsinthischapterrefertoPHPversion

4.3.3,whichisthecurrentversionofthesoftware.ThePHP

Groupusesminorreleasenumbersforupdatescontaining

securityenhancementsorbugfixes.Minorreleasesdonot

followasetreleaseschedule;whenenhancementsorfixesare

addedtothecodeandthoroughlytested,thePHPGroupwill

releasesanewversion,withanewminorversionnumber.

Itispossiblethatbythetimeyoupurchasethisbook,theminor

versionnumberwillhavechanged,to4.3.4orbeyond.Ifthatis

thecase,youshouldreadthelistofchangesat

http://www.php.net/ChangeLog-4.phpforanychanges

regardingtheinstallationorconfigurationprocess,whichmakes

upthebulkofthischapter.

Althoughitisunlikelythatanyinstallationinstructionswill

changebetweenminorversionupdates,youshouldgetinthe

habitofalwayscheckingthechangelogofsoftwarethatyou

installandmaintain.Ifaminorversionchangedoesoccur

duringthetimeyouarereadingthisbook,butnoinstallation

changesarenotedinthechangelog,simplymakeamentalnote

andsubstitutethenewversionnumberwhereveritappearsin

theinstallationinstructionsandaccompanyingfigures.

ForinstructionsoninstallingPHPfromtheCD,pleasereferto

AppendixA,"InstallingMySQL,Apache,andPHPfromtheCDROM."



BuildingPHPonLinux/UnixwithApache

Inthissection,wewilllookatonewayofinstallingPHPwith

ApacheonLinux/Unix.Theprocessismoreorlessthesamefor

anyUnixoperatingsystem.Althoughyoumightbeabletofind

pre-builtversionsofPHPforyoursystem,compilingPHPfrom

thesourcegivesyougreatercontrol.

TodownloadthePHPdistributionfiles,gotothehomeofPHP,

http://www.php.net/,andfollowthelinktotheDownloads

section.Grabthelatestversionofthesourcecodeforthis

example,weareusing4.3.3.Yourdistributionwillbenamed

somethingsimilartophp-version.tar.gz,whereversionis

themostrecentreleasenumber.Thisarchivewillbea

compressedtarfile,soyouwillneedtounpackit:



#gunzip
Keepthedownloadedfileinadirectoryreservedforsourcefiles,

suchas/usr/src/or/usr/local/src/.Afteryourdistribution

isunpacked,youshouldmovetothePHPdistributiondirectory:



#cdphp-version



Withinyourdistributiondirectory,youwillfindascriptcalled

configure.Thisscriptacceptsadditionalinformationthatis

providedwhentheconfigurescriptisrunfromthecommand

line.Thesecommand-lineargumentscontrolthefeaturesthat

PHPwillsupport.Inthisexample,wewillincludethebasic

optionsyouneedtousetoinstallPHPwithApacheandMySQL

support.Wewilldiscusssomeoftheavailableconfigure

optionslaterinthechapter,andthroughoutthebookasthey

becomerelevant.



#./configure--prefix=/usr/local/php--with-mysql\

--with-apxs2=/usr/local/apache2/bin/apxs

Oncetheconfigurescripthasrun,youwillbereturnedtothe

promptafterreceivinginformationalnotesfromthePHPGroup:



+--------------------------------------------------------------



|License:



|ThissoftwareissubjecttothePHPLicense,availableinthi



|distributioninthefileLICENSE.Bycontinuingthisinstall



|process,youareboundbythetermsofthislicenseagreement



|Ifyoudonotagreewiththetermsofthislicense,youmust



|theinstallationprocessatthispoint.



+--------------------------------------------------------------



|***NOTE***



|Thedefaultforregister_globalsisnowOFF!



|



|Ifyourapplicationreliesonregister_globalsbeingON,you



|shouldexplicitlysetittooninyourphp.inifile.



|Notethatyouarestronglyencouragedtoread



|http://www.php.net/manual/en/security.registerglobals.php



|abouttheimplicationsofhavingregister_globalssettoon,



|avoidusingitifpossible.



+--------------------------------------------------------------



ThankyouforusingPHP.

Next,issuethemakecommand,followedbythemakeinstall

command.ThesecommandsshouldendtheprocessofPHP

compilationandinstallationandreturnyoutoyourprompt.

Youwillneedtoensurethattwoveryimportantfilesarecopied

totheircorrectlocations.First,issuethefollowingcommandto



copythedistributedversionofphp.initoitsdefaultlocation.

Youwilllearnmoreaboutphp.inilaterinthischapter.



#cpphp.ini-dist/usr/local/lib/php.ini

Next,copythePHPsharedobjectfiletoitsproperplaceinthe

Apacheinstallationdirectory,ifithasnotalreadybeenplaced

therebytheinstallationprocess:



#cplibs/libphp4.so/usr/local/apache2/modules/

YoushouldnowbeabletoconfigureandrunApache,butlet's

coversomeadditionalconfigurationoptionsbeforeheadingon

tothe"IntegratingPHPwithApacheonLinux/Unix"section.



AdditionalConfigurationOptions

Whenwerantheconfigurescript,weincludedsome

command-lineargumentsthatdeterminedsomefeaturesthat

thePHPenginewillinclude.Theconfigurescriptitselfgives

youalistofavailableoptions,includingtheonesweused.From

thePHPdistributiondirectory,typethefollowing:



#./configure--help

Thisproducesalonglist,soyoumightwanttoaddittoafile

andreaditatyourleisure:



#./configure--help>configoptions.txt

IfyoudiscoveradditionalfunctionalityyouwishtoaddtoPHP

afterithasbeeninstalled,simplyruntheconfigurationand

buildprocessagain.Doingsowillcreateanewversionof

libphp4.soandplaceitintheApachedirectorystructure.All

youhavetodoisrestartApacheinorderforthenewfiletobe

loaded.



IntegratingPHPwithApacheonLinux/Unix

ToensurethatPHPandApachegetalongwithoneanother,you

needtocheckforandpotentiallyaddafewitemstothe

httpd.confconfigurationfile.First,lookforalinelikethe

following:



LoadModulephp4_modulemodules/libphp4.so

Ifthislineisnotpresent,oronlyappearswithapoundsign(#)

atthebeginningoftheline,youmustaddthelineorremove

the#.ThislinetellsApachetousethePHPsharedobjectfile

thatwascreatedbythePHPbuildprocess(libphp4.so).

Next,lookforthissection:



#



#AddTypeallowsyoutoaddtooroverridetheMIMEconfigurati

#filemime.typesforspecificfiletypes.

#

Addthefollowingline:



AddTypeapplication/x-httpd-php.php.phtml.html

ThisensuresthatthePHPenginewillparsefilesthatendwith

the.php,.phtml,and.htmlextensions.Yourselectionof

filenamesmightdiffer,andyoumightwanttoadd.php3asan

extension,forbackwardcompatibilitywithanyveryoldscripts



youmayhave.

Savethisfile,andthenrestartApache.Whenyoulookinyour

error_log,youshouldseesomethinglikethefollowingline:



[SunSep2810:42:472002][notice]Apache/2.0.47(Unix)PHP/4.

PHPisnowpartoftheApacheWebserver.Ifyouwanttolearn

howtoinstallPHPonaWindowsplatform,keepreading.

Otherwise,youcanskipaheadtothe"TestingYourInstallation"

section.



InstallingPHPFilesonWindows

UnlikebuildingandinstallingPHPonLinux/Unix,installingPHP

onWindowsrequiresnothingmorethandownloadingthe

distributionandmovingafewfilesaround.TodownloadthePHP

distributionfiles,gotothehomeofPHP,http://www.php.net/,

andfollowthelinktotheDownloadssection.Grabthelatest

versionofthezippackage(nottheinstaller!)fromtheWindows

Binariessectionforthisexample,weareusing4.3.3.Your

distributionwillbenamedsomethingliketophp-version.zip,

whereversionisthemostrecentreleasenumber.

Oncethefileisdownloadedtoyoursystem,double-clickonitto

launchyourunzippingsoftware.Thedistributionispackedup

withpathnamesalreadyinplace,soextractthefilestotheroot

ofyourdrive,whereitwillcreateadirectorycalledphpversion-Win32,andplaceallthefilesandsubdirectoriesunder

thatnewdirectory.

NowthatyouhaveallthebasicPHPdistributionfiles,youjust

needtomoveafewofthemaround:

1. InthePHPinstallationdirectory,findthephp.inidistfileandrenameitphp.ini.

Copythephp.inifiletoC:\WINDOWS\orwhereveryou

usuallyputyour*.inifiles.

Copythephp4ts.dllfiletoC:\WINDOWS\SYSTEM\or

whereveryouusuallyputyour*.dllfiles.

TogetabasicversionofPHPworkingwithApache,you'llneed

tomakeafewminormodificationstotheApacheconfiguration

file.



IntegratingPHPwithApacheonWindows

ToensurethatPHPandApachegetalongwithoneanother,you

needtoaddafewitemstothehttpd.confconfigurationfilein

theApachedirectoryonyourcomputer.First,findasectionthat

lookslikethis:



#Example:

#LoadModulefoo_modulemodules/mod_foo.so

#

LoadModuleaccess_modulemodules/mod_access.so

LoadModuleactions_modulemodules/mod_actions.so

LoadModulealias_modulemodules/mod_alias.so

LoadModuleasis_modulemodules/mod_asis.so

LoadModuleauth_modulemodules/mod_auth.so

#LoadModuleauth_anon_modulemodules/mod_auth_anon.so

#LoadModuleauth_dbm_modulemodules/mod_auth_dbm.so

#LoadModuleauth_digest_modulemodules/mod_auth_digest.so

LoadModuleautoindex_modulemodules/mod_autoindex.so



#LoadModulecern_meta_modulemodules/mod_cern_meta.so

LoadModulecgi_modulemodules/mod_cgi.so

#LoadModuledav_modulemodules/mod_dav.so

#LoadModuledav_fs_modulemodules/mod_dav_fs.so

LoadModuledir_modulemodules/mod_dir.so

LoadModuleenv_modulemodules/mod_env.so

#LoadModuleexpires_modulemodules/mod_expires.so

#LoadModulefile_cache_modulemodules/mod_file_cache.so

#LoadModuleheaders_modulemodules/mod_headers.so

Attheendofthissection,addthefollowing:



LoadModulephp4_modulec:/php-version/sapi/php4apache2.dll

Next,lookforthissection:



#



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 3. Installing and Configuring PHP

Tải bản đầy đủ ngay(0 tr)

×