25
bdNOG7 18-22 November 2017 | Dhaka, Bangladesh Apache + PHP + MySQL

New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

bdNOG718-22 November 2017| Dhaka,

Bangladesh

Apache+PHP+MySQL

Page 2: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

Outline

q Introduction toApachehttpd webserver

q BasicCompilation, Installation andConfiguration

q ApacheFilesystem

q ApacheLogging&Status

q Security&Performance Features

q VirtualHosting

q ApacheApplications

2

Page 3: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

AboutApache

� APAtCHy server:developedbytheApachegroupformed2/95aroundbyanumberofpeoplewhoprovidedpatchfilesforNCSAhttpd 1.3byRobMcCool.

� ApacheHTTPserverprojecthttp://httpd.apache.org

� History-http://httpd.apache.org/ABOUT_APACHE.html

� Apachefoundationstartedtosupportthewebserverproject,butnowextends toamultitudeofotherprojects

� Firstofficialpublic release (0.6.2)inApril1995

� Addedadaptivepre-forkchildprocesses(veryimportant!).

� ModularstructureandAPIforextensibility (BobThau)

� Porttomultipleplatforms.

� Apache1.0wasreleased on12/1/95.PassNCSAhttpd tobe#1server inInternet.

� Reference:� http://httpd.apache.org/docs/current/

Page 4: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

TaxonomyofInternetServices

4

Page 5: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

StatsofWebServertypes

Page 6: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

Web Server Installation Statistics

• See survey statistics in à W3Techs.com & 6

Page 7: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

ApacheInstallation

• Thecurrentstablerelease isApache2.4.25• Canbeinstalledviapackagemanager• Orcustominstallationfromsourceifonerequiresamorerecentversion

• InourtrainingmachineswewillinstallApache2.4.7

• LinuxPackageManager:• Ubuntu/Debian:apt-getinstallapache2• CentOS/Redhat/Fedora:yuminstallhttpd

• Forwin32version,youcandownloadfromanyofmirrorservers.Win32BinaryincludingOpenSSL 0.x.x(MSIInstaller).http://httpd.apache.org/download.cgi

Page 8: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

ApacheInstallation:Custom

� Download httpd-2.4.x.tar.bz2 from http://httpd.apache.org/download.cgi or closer mirror sites

� $tar xjf httpd-2.4.x.tar.bz2 � $ cd httpd-2.4..x

� $ ./configure --prefix=PREFIX� $ Make� $ sudo make install� $ sudo PREFIX/bin/apache2ctl start

� Here PREFIX is the prefix of the directory containing the distribution, typically it is /usr/local/apache.

� Since as a normal user, we do not have permission to install there, you need to have sudo privileges for your user.

� For configuring the apache with specific features, we can specify the corresponding features as option to the configure command. You can find the list of features by “./configure –help”

Page 9: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

FileSystemLayout(viaPackageManager)

• config filesarein/etc/apache2/ (Ubuntu/Debian)/etc/httpd/conf (CentOS/Redhat/Fedora)• filesthewebserverwillservearein/var/www/html/• Startup scriptis/etc/init.d/apache2(Ubuntu/Debian)• Run$ sudo /etc/init.d/apache2 start$ sudo service apache2 start$ sudo systemctl start apache2

• Restart$ sudo /etc/init.d/apache2 restart$ sudo service apache2 restart$ sudo systemctl restart apache2

Page 10: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

ApacheFiles(Ubuntu/Debian)

Configurationfile:/etc/apache2

Logfiles:/var/log/apache2/access_log

/var/log/apache2/error_log

Modules/etc/apache2/mods-available/

DefaultDocumentRoot/var/www/html/

DefaultCGIRoot/var/www/cgi-bin/

Page 11: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

Appachelog

• EnableApacheLogging• ApacheallowsyoutologgingindependentlyofyourOSlogging.ItiswisetoenableApachelogging,becauseitprovidesmoreinformation,suchasthecommandsenteredbyusersthathaveinteractedwithyourWebserver.

• Todosoyouneedtoincludethemod_log_configmodule.Therearethreemainlogging-relateddirectivesavailablewithApache.– TransferLog:Creatingalogfile.– LogFormat :Specifyingacustomformat.– CustomLog :Creatingandformattingalogfile.

• YoucanalsousethemforaparticularwebsiteifyouaredoingVirtualhostingandforthatyouneedtospecifyitinthevirtualhostsection.Forexample,hereisthemywebsitevirtualhostconfigurationwithloggingenabled.

Page 12: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

Enablelog

• <VirtualHost *:80>ServerName example.comServerAlias www.example.comServerAdmin webmaster@localhostDirectoryIndex index.htm index.html index.php

DocumentRoot /var/www/html/example.com<Directory"/var/www/html/example.com/"> OptionsFollowSymLinks AllowOverrideAll Allowfromall

</Directory>ErrorDocument 404/story.php

ErrorLog /var/log/httpd/example.com_error_logCustomLog /var/log/httpd/example.com_access_log combined

• </VirtualHost>

Page 13: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

ApachePerformanceTuning

<IfModulempm_prefork_module>StartServers 2 MinSpareServers 5 MaxSpareServers 10 ServerLimit 256 MaxClients 600 MaxRequestWorkers 600MaxRequestsPerChild 1000

</IfModule>

KeepAlive

Page 14: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

ApachePerformanceTuning

• KeepAlivedirectives

• ApacheRuntimeloadedmodules

• Application/scriptsRuntimeloadedmodules

• Memorymapping

Page 15: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

Hardeningapache

HideApacheVersionandOSIdentityfromErrors

$ sudo vim /etc/httpd/conf/httpd.conf (RHEL/CentOS/Fedora)$ sudo vim /etc/apache/mods_available/security (Debian/Ubuntu)

ServerSignature OffServerTokens ProdTraceEnable Off

$ sudo service apache2 restart

Page 16: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

DisableDirectoryListing

<Directory /var/www/html> Options –Indexes

</Directory>

Page 17: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

ApacheSSL

SecureSocketLayer(SSL)portis443SSLisimportanttoprotectcommunicationbetweenbrowserandweb-serverRequiresthecreationofSSLcertificatesandCertificateSigningRequests(CSR)ForintegritySSLcertificatesaresignedbyaCertificateAuthority’s(CA)suchasNetSol,Symantec,Comodo,etc.SelfsignedCertificateswillalsoworkbutyourbrowserwillnottrustitandwillgiveawarningtousers(whichmostdon’tread)RefertotheCreatingSSLCertificateExerciseSection

Page 18: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

HowSSLWorks

1. Browser connects to a web server (website) secured with SSL (https). Browser requests that the server identify itself.

2. Server sends a copy of its SSL Certificate, including the server’s public key.3. Browser checks the certificate root against a list of trusted CAs and that the

certificate is unexpired, unrevoked, and that its common name is valid for the website that it is connecting to. If the browser trusts the certificate, it creates, encrypts, and sends back a symmetric session key using the server’s public key.

4. Server decrypts the symmetric session key using its private key and sends back an acknowledgement encrypted with the session key to start the encrypted session.

5. Server and Browser now encrypt all transmitted data with the session key.

Page 19: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

RoleofCertificateAuthority

• ThereareanumberofCAthatcertifycertificates

• Mostbrowsershavepre-includedpublicKeysfromtheCA’s

• ACAcertifiedcertificatewillhavevalidationinformationsignedbytheCA’sprivatekey

• ThebrowserwilldecryptthevalidationinformationusingthepublickeyandverifythatthecertificateiscertifiedbytheCA

• Ifthisfailsawarningisgiven

Page 20: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

VirtualHosting

• ApacheProvidesmultipleoptionsofvirtualhostingandscales– NameBasedvirtualhosts– IPBasedVirtualHosts– Aliases

• ItsrecommendedtouseanIPaddressoverhostnamesinvirtualhostingconfiguration

Page 21: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

VirtualHosting

NameVirtualHost*:80

<VirtualHost *:80>ServerNameserver-nameDocumentRootpath-to-virtual-document-root</VirtualHost>

<VirtualHost*:80>ServerNameserver-nameDocumentRootpath-to-virtual-document-root</VirtualHost>

Page 22: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

ApacheandIPv6

• ApachesupportsIPv4andIPv6bydefault• Setthelistenoptiontoport80willlistenforbothIPv4andIPv6• listenoptionwithIPv4andIPv6specificaddresseswillinvokedifferentsocketsforeachprotocolListen196.200.219.xx:80Listen[2001:4348:0:219:196.200.219:xx]:80

Page 23: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

InstallingPHP&Mysql

PhPandMysqlimplementationshaveincreaseddrivenmainlybydevelopment requestsLAMPandWAMParethemostcommonimplementationsFreeBSD=“FAMP”?http://geekybits.blogspot.com/2007/09/creating-famp-server.htmlInstallationviaportsisrelatively straightforwardSeePHP&Mysqlinstallationexercisesection

Page 24: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

Apacheimplementations

• Apacheiswidelyusedtoservemanycontentapplications

• Webmail,Blogs,Wiki’s,CMSetc

Page 25: New bdNOG7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/3.1.web_service.pdf · 2017. 11. 21. · q Introduction to Apache httpd web server q Basic Compilation, Installation and Configuration

StartExercises