Session 12 - Apache2 Webserver Configuration in ubuntu

download Session 12 - Apache2 Webserver Configuration in ubuntu

of 28

Transcript of Session 12 - Apache2 Webserver Configuration in ubuntu

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    1/28

    Apache2 Web Server

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    2/28

    Objectives:

    Topic to Cover:

    - What is Web Server?- HTTPD Apache2 Web Server- Basic Setting- HTTPS Confguration

    - Scripting Language

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    3/28

    What is Web Server?

    A Web server is sot!are responsib"e oraccepting HTTP re#uests ro$ c"ients% !hich

    are &no!n as Web bro!sers% an' servingthe$ HTTP responses a"ong !ith optiona"'ata contents% !hich usua""( are Web pagessuch as HT)L 'ocu$ents an' "in&e' ob*ects

    +i$ages% etc,,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    4/28

    HTTPD - Apache2 WebServer

    Apache is the $ost co$$on"( use' Web Server on Linu.s(ste$s, Web Servers are use' to serve Web Pages re#ueste'b( c"ient co$puters, C"ients t(pica""( re#uest an' vie! Web

    Pages using Web Bro!ser app"ications such as /ireo.% 0pera%or )o1i""a,

    sers enter a nior$ 3esource Locator +3L to point to aWeb server b( $eans o its /u""( 4ua"ife' Do$ain 5a$e

    +/4D5 an' a path to the re#uire' resource, /or e.a$p"e% tovie! the ho$e page o the buntu Web site a user !i"" enteron"( the /4D5, To re#uest specifc inor$ation about pai'support% a user !i"" enter the /4D5 o""o!e' b( a path,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    5/28

    HTTPD - Apache2 WebServer

    The $ost co$$on protoco" use' to transer Web pages is theH(per Te.t Transer Protoco" +HTTP,Protoco"s such as H(per Te.t Transer Protoco" over Secure

    Soc&ets La(er +HTTPS% an' /i"e Transer Protoco" +/TP% aprotoco" or up"oa'ing an' 'o!n"oa'ing f"es% are a"sosupporte',Apache Web Servers are oten use' in co$bination !ith the

    )(S4L 'atabase engine% the H(perTe.t Preprocessor +PHPscripting "anguage% an' other popu"ar scripting "anguagessuch as P(thon an' Per", This confguration is ter$e' LA)P+Linu.% Apache% )(S4L an' Per"7P(thon7PHP an' or$s apo!eru" an' robust p"ator$ or the 'eve"op$ent an'

    'ep"o($ent o Web-base' app"ications,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    6/28

    1.1. Installation

    The Apache2 !eb server is avai"ab"e in buntuLinu., To insta"" Apache28

    9 At a ter$ina" pro$pt enter the o""o!ingco$$an'8su'o apt-get insta"" apache2

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    7/28

    1.2. Con!"ration

    Apache2 is confgure' b( p"acing 'irectives in p"ainte.t confguration f"es, These 'irectives areseparate' bet!een the o""o!ing f"es an'

    'irectories8

    9 apache2,con8 the $ain Apache2 confgurationf"e, Contains settings that are g"oba" to Apache2,

    9 con,'8 contains confguration f"es !hich app"(g"oba""( to Apache2, 0ther pac&ages that useApache2 to serve content $a( a'' f"es% ors($"in&s% to this 'irector(,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    8/28

    1.2. Con!"ration

    9 envvars8 f"e !here Apache2 environ$ent variab"es are set,9 http',con8 historica""( the $ain Apache2 confguration f"e%

    na$e' ater the http' 'ae$on, The f"e can be use' or userspecifc confguration options that g"oba""( e:ect Apache2,9 $o's-avai"ab"e8 this 'irector( contains confguration f"es toboth "oa' $o'u"es an' confgure the$, 5ot a"" $o'u"es !i""have specifc confguration f"es% ho!ever,9 $o's-enab"e'8 ho"'s s($"in&s to the f"es in7etc7apache27$o's-avai"ab"e, When a $o'u"e confgurationf"e is s($"in&e' it !i"" be enab"e' the ne.t ti$e apache2 isrestarte',

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    9/28

    1.2. Con!"ration

    9 ports,con8 houses the 'irectives that 'eter$ine !hich TCPports Apache2 is "istening on,

    9 sites-avai"ab"e8 this 'irector( has confguration f"es orApache2 ;irtua" Hosts, ;irtua" Hosts a""o! Apache2 to beconfgure' or $u"tip"e sites that have separateconfgurations,9 sites-enab"e'8 "i&e $o's-enab"e'% sites-enab"e' containss($"in&s to the 7etc7apache27sites-avai"ab"e 'irector(, Si$i"ar"(!hen a confguration f"e in sites-avai"ab"e is s($"in&e'% thesite confgure' b( it !i"" be active once Apache2 is restarte',

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    10/28

    1.2.1. #asic Settin!

    This section e.p"ains Apache2 server essentia" confgurationpara$eters, 3eer to the Apache2 Docu$entation< or $ore'etai"s,

    9 Apache2 ships !ith a virtua"-host-rien'"( 'eau"tconfguration, That is% it is confgure' !ith a sing"e 'eau"tvirtua" host +using the ;irtua"Host 'irective !hich can$o'ife' or use' as-is i (ou have a sing"e site% or use' as ate$p"ate or a''itiona" virtua" hosts i (ou have $u"tip"e sites,= "eta"one% the 'eau"t virtua" host !i"" serve as (our 'eau"t site% orthe site users !i"" see i the 3L the( enter 'oes not $atchthe Server5a$e 'irective o an( o (our custo$ sites, To$o'i( the 'eau"t virtua" host% e'it the f"e 7etc7apache27sites-

    avai"ab"e7'eau"t,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    11/28

    1.2.1. #asic Settin!

    This section e.p"ains Apache2 server essentia" confgurationpara$eters, 3eer to the Apache2 Docu$entation< or $ore'etai"s,

    9 Apache2 ships !ith a virtua"-host-rien'"( 'eau"tconfguration, That is% it is confgure' !ith a sing"e 'eau"tvirtua" host +using the ;irtua"Host 'irective !hich can$o'ife' or use' as-is i (ou have a sing"e site% or use' as ate$p"ate or a''itiona" virtua" hosts i (ou have $u"tip"e sites,= "eta"one% the 'eau"t virtua" host !i"" serve as (our 'eau"t site% orthe site users !i"" see i the 3L the( enter 'oes not $atchthe Server5a$e 'irective o an( o (our custo$ sites, To$o'i( the 'eau"t virtua" host% e'it the f"e 7etc7apache27sites-

    avai"ab"e7'eau"t,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    12/28

    1.2.1. #asic Settin!

    The 'irectives set or a virtua" host on"( app"( to thatparticu"ar virtua" host, = a 'irectiveis set server-!i'e an' not 'efne' !ithin the virtua" host

    settings% the 'eau"t setting isuse', /or e.a$p"e% (ou can 'efne a Web$aster e$ai" a''ressan' not 'efne in'ivi'ua"e$ai" a''resses or each virtua" host,= (ou !ish to confgure a ne! virtua" host or site% cop( thatf"e into the sa$e 'irector( !ith a na$e (ou choose, /ore.a$p"e8su'o cp 7etc7apache27sites-avai"ab"e7'eau"t7etc7apache27sites-avai"ab"e7$(ne!site

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    13/28

    1.2.1. #asic Settin!

    >'it the ne! f"e to confgure the ne! site using so$e o the'irectives 'escribe' be"o!,

    9 The ServerA'$in 'irective specifes the e$ai" a''ress to bea'vertise' or the servers a'$inistrator, The 'eau"t va"ue is!eb$aster@"oca"host, This shou"' be change' to an e$ai"a''ress that is 'e"ivere' to (ou +i (ou are the serversa'$inistrator, = (our !ebsite has a prob"e$% Apache2 !i""'isp"a( an error $essage containing this e$ai" a''ress toreport the prob"e$ to, /in' this 'irective in (our sitesconfguration f"e in 7etc7apache27sites-avai"ab"e,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    14/28

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    15/28

    1.2.1. #asic Settin!

    The Server5a$e 'irective is optiona" an' specifes!hat /4D5 (our site shou"' ans!er to, The 'eau"tvirtua" host has no Server5a$e 'irective specife'%

    so it !i"" respon' to a"" re#uests that 'o not $atch aServer5a$e 'irective in another virtua" host, = (ouhave *ust ac#uire' the 'o$ain na$eubunturoc&s,co$ an' !ish to host it on (our buntu

    server% the va"ue o the Server5a$e 'irective in(our virtua" host confguration f"e shou"' beubunturoc&s,co$,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    16/28

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    17/28

    1.2.1. #asic Settin!

    ServerA"ias F,ubunturoc&s,co$9 The Docu$ent3oot 'irective specifes !here Apache2

    shou"' "oo& or the f"es that $a&e up the site, The'eau"t va"ue is 7var7!!!, 5o site is confgure' there% buti (ou unco$$ent the 3e'irect)atch 'irective in7etc7apache27apache2,con re#uests !i"" be re'irecte' to7var7!!!7 apache2-'eau"t !here the 'eau"t Apache2

    site a!aits, Change this va"ue in (our sites virtua" hostf"e% an' re$e$ber to create that 'irector( i necessar(G

    The 7etc7apache27sites-avai"ab"e 'irector( is not parse'b( Apache2, S($bo"ic "in&s in 7etc7apache27sites-enab"e'point to avai"ab"e sites,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    18/28

    1.2.1. #asic Settin!

    The 7etc7apache27sites-avai"ab"e 'irector( is not parse' b(Apache2, S($bo"ic "in&s in 7etc7apache27sites-enab"e' point toavai"ab"e sites,

    >nab"e the ne! ;irtua"Host using the a2ensite uti"it( an'restart Apache28

    su'o a2ensite $(ne!sitesu'o 7etc7init,'7apache2 restart

    Be sure to rep"ace $(ne!site !ith a $ore 'escriptive na$eor the ;irtua"Host, 0ne $etho' is to na$e the f"e ater theServer5a$e 'irective o the ;irtua"Host,Si$i"ar"(% use the a2'issite uti"it( to 'isab"e sites, This is canbe useu" !hen troub"eshooting confguration prob"e$s !ith

    $u"tip"e ;irtua"Hosts8

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    19/28

    1.2.1. #asic Settin!

    The 7etc7apache27sites-avai"ab"e 'irector( is not parse' b( Apache2,S($bo"ic "in&s in 7etc7apache27sites-enab"e' point to avai"ab"e sites,>nab"e the ne! ;irtua"Host using the a2ensite uti"it( an' restart

    Apache28su'o a2ensite $(ne!sitesu'o service apache2 re"oa'

    Be sure to rep"ace $(ne!site !ith a $ore 'escriptive na$e or the;irtua"Host, 0ne $etho' is to na$e the f"e ater the Server5a$e

    'irective o the ;irtua"Host, Si$i"ar"(% use the a2'issite uti"it( to'isab"e sites, This is can be useu" !hen troub"eshootingconfguration prob"e$s !ith $u"tip"e ;irtua"Hosts8

    su'o a2'issite $(ne!sitesu'o service apache2 restart

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    20/28

    1.2.2. Apache2 $o%"les

    Apache2 is a $o'u"ar server, This i$p"ies that on"( the $ostbasic unctiona"it( is inc"u'e' in the core server, >.ten'e'eatures are avai"ab"e through $o'u"es !hich can be "oa'e'

    into Apache2, B( 'eau"t% a base set o $o'u"es is inc"u'e' inthe server at co$pi"e-ti$e, = the server is co$pi"e' to use'(na$ica""( "oa'e' $o'u"es% then $o'u"es can be co$pi"e'separate"(% an' a''e' at an( ti$e using the Loa')o'u"e'irective, 0ther!ise% Apache2 $ust be reco$pi"e' to a'' orre$ove $o'u"es,

    buntu co$pi"es Apache2 to a""o! the '(na$ic "oa'ing o$o'u"es, Confguration 'irectives $a( be con'itiona""(inc"u'e' on the presence o a particu"ar $o'u"e b( enc"osingthe$ in an I=)o'u"eJ b"oc&,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    21/28

    1.2.2. Apache2 $o%"les

    Eou can insta"" a''itiona" Apache2 $o'u"es an' use the$ !ith (ourWeb server, /or e.a$p"e% run the o""o!ing co$$an' ro$ a ter$ina"pro$pt to insta"" the )(S4L Authentication $o'u"e8

    su'o apt-get insta"" "ibapache2-$o'-auth-$(s#"See the 7etc7apache27$o's-avai"ab"e 'irector(% or a''itiona"$o'u"es,se the a2en$o' uti"it( to enab"e a $o'u"e8 su'o a2en$o' authK$(s#"

    su'o 7etc7init,'7apache2 restartSi$i"ar"(% a2'is$o' !i"" 'isab"e a $o'u"e8 su'o a2'is$o' authK$(s#"

    su'o 7etc7init,'7apache2 restart

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    22/28

    1.&. HTTPS Con!"ration

    The $o'Kss" $o'u"e a''s an i$portant eature to theApache2 server - the abi"it( to encr(pt co$$unications,

    Thus% !hen (our bro!ser is co$$unicating using SSL%

    the https877 pref. is use' at the beginning o the nior$3esource Locator +3L in the bro!ser navigation bar,

    The $o'Kss" $o'u"e is avai"ab"e in apache2-co$$onpac&age, >.ecute the o""o!ing co$$an' ro$ a

    ter$ina" pro$pt to enab"e the $o'Kss" $o'u"e8su'o a2en$o' ss"

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    23/28

    1.&. HTTPS Con!"ration

    There is a 'eau"t HTTPS confguration f"e in7etc7apache27sites-avai"ab"e7'eau"t-ss", =nor'er or Apache2 to provi'e HTTPS% a certifcate an' &e( f"e

    are a"so nee'e', The 'eau"t HTTPS confguration !i"" use acertifcate an' &e( generate' b( the ss"-cert pac&age, The(are goo' or testing% but the auto-generate' certifcate an'&e( shou"' be rep"ace' b( a certifcate specifc to the site orserver,

    To confgure Apache2 or HTTPS% enter the o""o!ing8su'o a2ensite 'eau"t-ss"

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    24/28

    1.&. HTTPS Con!"ration

    The 'irectories 7etc7ss"7certs an' 7etc7ss"7private are the'eau"t "ocations, = (ou insta"" the certifcate an' &e( inanother 'irector( $a&e sure to change SSLCertifcate/i"e an'

    SSLCertifcatee(/i"e appropriate"(,

    With Apache2 no! confgure' or HTTPS% restart the service toenab"e the ne! settings8su'o 7etc7init,'7apache2 restart

    Depen'ing on ho! (ou obtaine' (our certifcate (ou $a(nee' to enter a passphrase !hen Apache2 starts, Eou canaccess the secure server pages b( t(pinghttps877(ourKhostna$e7ur"7 in (our bro!ser a''ress bar,

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    25/28

    1.'. Scriptin! (an!"a!e

    PHP is a genera"-purpose scripting "anguage suite' or Web'eve"op$ent, The PHP script can be e$be''e' into HT)L, Thissection e.p"ains ho! to insta"" an' confgure PHPM in buntu S(ste$!ith Apache2 an' )(S4L,

    This section assu$es (ou have insta""e' an' confgure' Apache2 WebServer an' )(S4L Database Server, Eou can reer to Apache2 sectionan' )(S4L sections in this 'ocu$ent to insta"" an' confgureApache2 an' )(S4L respective"(,

    1.'.1. Installation

    su'o apt-get insta"" phpM "ibapache2-$o'-phpM

    Eou can run PHPM scripts ro$ co$$an' "ine, To run PHPM scriptsro$ co$$an' "ine (ou shou"' insta"" phpM-c"i pac&age,

    su'o apt-get insta"" phpM-c"i

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    26/28

    1.'. Scriptin! (an!"a!e

    Eou can a"so e.ecute PHPM scripts !ithout insta""ing PHPMApache $o'u"e, To acco$p"ish this% (ou shou"' insta"" phpM-cgi pac&age, Eou can run the o""o!ing co$$an' in a ter$ina"pro$pt to insta"" phpM-cgi pac&age8su'o apt-get insta"" phpM-cgi, To use )(S4L !ith PHPM (oushou"' insta"" phpM-$(s#" pac&age, To insta"" phpM-$(s#" (oucan enter the o""o!ing co$$an' in the ter$ina" pro$pt8su'o apt-get insta"" phpM-$(s#"

    Si$i"ar"(% to use PostgreS4L !ith PHPM (ou shou"' insta""phpM-pgs#" pac&age, To insta"" phpM-pgs#" (ou can enter theo""o!ing co$$an' in the ter$ina" pro$pt8

    su'o apt-get insta"" phpM-pgs#"

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    27/28

    1.'. Scriptin! (an!"a!e

    1.'.2. Con!"ration0nce (ou insta"" PHPM% (ou can run PHPM scripts ro$ (our !ebbro!ser, = (ou have insta""e' phpM-c"i pac&age% (ou can run PHPMscripts ro$ (our co$$an' pro$pt,

    B( 'eau"t% the Apache 2 Web server is confgure' to run PHPMscripts, =n other !or's% the PHPM $o'u"e is enab"e' in Apache2 Webserver auto$atica""( !hen (ou insta"" the $o'u"e, P"ease veri( i thef"es 7etc7apache27$o's-enab"e'7phpM,con an' 7etc7apache27$o's-enab"e'7phpM,"oa' e.ist, = the( 'o not e.ists% (ou can enab"e the

    $o'u"e using a2en$o' co$$an',0nce (ou insta"" PHPM re"ate' pac&ages an' enab"e' PHPM Apache 2$o'u"e% (ou shou"' restart Apache2 Web server to run PHPM scripts,

    su'o 7etc7init,'7apache2 restart

  • 7/26/2019 Session 12 - Apache2 Webserver Configuration in ubuntu

    28/28

    1.'. Scriptin! (an!"a!e

    1.'.&. Testin!

    To veri( (our insta""ation% (ou can run o""o!ing PHPM phpinoscript8I?php phpino+N?J

    Eou can save the content in a f"e phpino,php an' p"ace itun'er Docu$ent3oot 'irector( o Apache2 Web server, Whenpoint (our bro!ser to http877hostna$e7phpino,php% it !ou"''isp"a( va"ues o various PHPM confguration para$eters,