Apache httpd
Installation,
server start and stop
Instalace,
spouštění a ukončení serveru

Lukáš Bařinka

© 2021

REV 2.10

TOC

Obsah

  1. Web server implementations and Apache httpd
  2. Architecture and features
  3. Compilation and installation
  4. Server start and stop
  5. Documentation
  6. LAB: Installation
  1. Implementace webového serveru a Apache httpd
  2. Architektura a vlastnosti
  3. Kompilace a instalace
  4. Spuštění a ukončení
  5. Dokumentace
  6. LAB: Instalace

Web server implementations

Implementace webového serveru

Used implementations

Používané implementace

Netcraft webserver survey

Apache httpd history

Historie Apache httpd

  • 1993: NCSA HTTPd National Center for Supercomputing Applications
  • 1994: Main programmer resignation E-mail conference foundation, patches coordination
  • 1995: 1st public version 0.6.2
  • 1996: Most successful webserver
  • 1998: Version 1.3
  • 1999: Apache Software Foundation (ASF)
  • 2000: Version 2.0
  • 2005: Version 2.2
  • 1993: NCSA HTTPd National Center for Supercomputing Applications
  • 1994: Odchod hlavního programátora Založení emailové konference, koordinace patchů
  • 1995: 1. veřejná verze 0.6.2
  • 1996: Nejúspěšnější web server
  • 1998: Verze 1.3
  • 1999: Vznik Apache Software Foundation (ASF)
  • 2000: Verze 2.0
  • 2005: Verze 2.2

Apache httpd present

Současnost Apache httpd

  • 2010: End of 1.3 branch Version 1.3.34
  • 2012: Beginning of 2.4 branch Version 2.2.22
  • 2013: End of 2.0 branch Version 2.0.65
  • 2017: End of 2.2 branch Version 2.2.34
  • 2020: Version 2.4.46
  • 2010: Ukončení řady 1.3 Verze 1.3.34
  • 2012: Vznik nové řady 2.4 Verze 2.2.22
  • 2013: Ukončení řady 2.0 Verze 2.0.65
  • 2017: Ukončení podpory řady 2.2 Verze 2.2.34
  • 2020: Verze 2.4.46

Features and architecture

Vlastnosti a architektura

Features

Vlastnosti

  • Open source, available on many systems
  • Widely configurable using configuration files
  • Support of many programming languages PHP, Perl, Python, TCL, JSP, SSI, …
    and interfaces CGI / FastCGI
  • Wide range of additional modules Virtualhosting, HTTP authentication, proxy server, customizable logging, URL rewriting, I/O filtering, content negotiation, …
  • SSL, TLS, compression support
  • Open source, dostupnost na mnoha systémech
  • Velká konfigurovatelnost pomocí souborů
  • Podpora jazyků PHP, Perl, Python, TCL, JSP, SSI, …
    a rozhraní CGI / FastCGI
  • Velké množství modulů Virtualhosting, HTTP autentizace, proxy server, přizpůsobitelné logování, přepisování URL, filtrování vstupu/výstupu, dojednávání obsahu, …
  • Podpora SSL, TLS, komprese

Architecture

Architektura

  • Server runtime environment APR = Apache Portable Runtime
  • Core
  • MPM Multi-Processing Modules
    • Prefork Processes without threads (for thread-unsafe modules – like PHP)
    • Worker/Event Processes with threads (better performance)
  • Additional modules
    • Filters input / output
    • Handlers request processing
    • Auth, Autoindex, Alias, CGI, Include, Info, Mime, Status, Userdir, …
  • Prostředí pro běh serveru APR = Apache Portable Runtime
  • Core
  • Moduly souběžného zpracování Multi-Processing Module
    • Prefork Procesy bez vláken (pro vláknově ne-bezpečné moduly – např. PHP)
    • Worker/Event Procesy a vlákna (vyšší výkon)
  • Další moduly
    • Filtry vstupní / výstupní
    • Handlery zpracování požadavků
    • Auth, Autoindex, Alias, CGI, Include, Info, Mime, Status, Userdir, …

Architecture overview

Schéma architektury

Architecture overiview scheme

Request processing

Zpracování dotazu

  1. Mapping URI to filename
  2. Access control
    • User authentication
    • Request authorization (based on user/permissions)
    • Request authorization based on other criteria E.g. based on IP address
  3. Assign content data MIME-type
  4. Fixups What was skipped during previous parts
  5. Sending response to client
  6. Logging access (request/result)
  1. Překlad URI na jméno souboru
  2. Kontrola přístupu
    • Autentizace uživatele
    • Kontrola práv pro přístup uživatele
    • Kontrola přístupu založená na jiných kritériích Např. podle IP adresy
  3. Zjištění MIME typu dotazu
  4. Fixups Co se doposud nestihlo udělat
  5. Zaslání požadovaných dat klientovi
  6. Zalogování přístupu (požadavku/výsledku)

Compilation and installation

Kompilace a instalace

Installation methods

Způsoby instalace

  • Installation of compiled/binary files
  • Compilation and installation from source code
  • Binární instalace
  • Instalace ze zdrojových kódů

Binary installation from distribution packages

Binární instalace z balíčků

  • Debian/Linux distribution system Distribuční systémem Debian/Linuxu
    • apache2
    • apache2-mpm-?
    • apache2-utils
    • apache2-bin
    • apache2-common
    • libapache2-mod-*
  • RedHat/Linux distribution system Distribuční systémem RedHat/Linuxu
    • httpd
    • httpd-manual
    • apr-util
    • postgresql-libs

Installation from source code

Instalace ze zdrojových kódů

  1. Download Stažení https://httpd.apache.org/download.cgi Latest available version → Source → *.gz | *.bz2 + SHA256
    
    									wget https://www.apache.org/dist/httpd/httpd-2.4.46.tar.gz
    									wget https://www.apache.org/dist/httpd/httpd-2.4.46.tar.gz.sha256
    								
    It can be used curl -O instead of curl It's better to use address from local mirror Místo wget lze použít také curl -O Adresu lépe z lokálního zrcadla
  2. Check SHA256sum Kontrola SHA256sum
    
    									sha256sum -c httpd-2.4.46.tar.gz.sha256
    								
  3. Extract files from archive Rozbalení archivu
    
    									gunzip httpd-2.4.46.tar.gz
    									tar xf httpd-2.4.46.tar
    									cd httpd-2.4.46
    								

Source codes compilation

Kompilace zdrojových kódů

  1. Configuration → Compilation → Installation Konfigurace → Kompilace → Instalace
    
    									./configure && make && make install
    								

Configuration

Konfigurace

  • ./configure --help
  • --enable-layout=LAYOUT
  • --prefix=DIR
  • --enable-FEATURE / --disable-FEATURE Zahrne/nezahrne danou vlastnost do instalace
  • --enable-modules=MODULE-LIST all | most | module1,..,moduleN
  • --with-PACKAGE / --without-PACKAGE Použije/nepoužije balík

Directory structure (Debian)

Adresářová struktura (Debian)

/etc/apache2/global configuration
/etc/apache2/mods-availablemodules configuration
/etc/apache2/sites-availablevirtualhosts configuration
/etc/apache2/conf-availableadditional features configuration
/usr/lib64/apache2/compiled libraries
/usr/lib64/apache2/modulescompiled modules
/usr/sbinbinary files
/usr/sharedocumentation, manual
/usr/share/manpages, examples
/var/log/apache2logs
/var/wwwweb pages (resources)
/varin subdirectories more files, locks, …
/etc/apache2/globální konfigurace
/etc/apache2/mods-availablekonfigurace modulů
/etc/apache2/sites-availablekonfigurace virtuálních hostitelů
/etc/apache2/conf-availablerozšiřující konfigurace
/usr/lib64/apache2/zkompilované knihovny
/usr/lib64/apache2/moduleszkompilované moduly
/usr/sbinbinární soubory
/usr/sharedokumentace, manuálové
/usr/share/manstránky, příklady
/var/log/apache2logy
/var/wwwwebové stránky
/varv dalších podadresářích další soubory, zámky …

Directory structure (RedHat)

Adresářová struktura (RedHat)

/etc/httpd/global configuration
/etc/httpd/conf.dparts of server configuration
/etc/sysconfig/httpdserver start configuration
/usr/lib/httpd/modulescompiled modules
/usr/sbinbinary files
/usr/share/doc/httpd-2 …documentation
/usr/share/manmanual pages
/var/log/httpdlogs
/var/wwwweb pages (resources)
/etc/httpd/globální konfigurace
/etc/httpd/conf.ddílčí konfigurace serveru
/etc/sysconfig/httpdkonfigurace startu serveru
/usr/lib/httpd/moduleszkompilované moduly
/usr/sbinbinární soubory
/usr/share/doc/httpd-2 …dokumentace
/usr/share/manmanuálové stránky
/var/log/httpdlogy
/var/wwwwebové stránky

All files are placed into /usr/local in case of compilation and standard installation (unless another layout is chosen during configuration) For easy uninstallation

V případě instalace do /usr/local jsou všechny součásti webserveru umístěny do jeho podadresářů snadnější odinstalace

Start and stop

Spuštění a ukončení

Basic operations

Základní činnosti

  • Manual operations using apachectl wrapper Manuální ovládání pomocí wrapperu apachectl
    
    									apachectl [-k] start -D DEF...
    									apachectl [-k] stop
    									apachectl [-k] test
    								
  • Configuration check Kontrola konfigurace
    
    									apachectl -t
    									apachectl -t -D INFO ...
    								
  • Log files check Kontrola log souborů
    
    									tail -f /usr/local/apache2/logs{error,access}_log
    								
  • Automated operations using Init scripts call apachectl … commands In case of webserver incorporation into standard server infrastructure Automatické ovládání Init skripty volání příkazu apachectl … V případě začlenění webserveru do infrastruktury serveru

Notes

Poznámky

SignalAction-k
SignálAkce-k
TERMstop nowstop
USR1graceful restartgraceful
HUPrestart nowrestart
WINCHgraceful stopgraceful-stop
  • Syntax check considers mainly to syntax or just small logical issues. It's recommended to full configuration check to run the server (under non-privileged user) again.
  • The server will fail to listen on port that is already used even if there is no configuration problem. You will see an error message in log file in that case or error message about configuration problem.
  • Kontrola konfiguračního souboru se zaměřuje především na jeho syntaxi, případně drobné logické problémy. Pro kompletní otestování konfigurace se doporučuje spustit web server (pod neprivilegovaným uživatelem) znovu.
  • Pokud není problém v konfiguraci, web server se spustí a pokusí poslouchat na již používaném portu, což skončí s chybou. V opačném případě se vypíše chyba v konfiguraci.

apachectl

  • apachectl is just a script calling httpd program apachectl je pouze skript volající program httpd
    
    									file -b /usr/local/apache2/bin/apachectl
    									POSIX shell script, ASCII text executable
    								
  • The script uses its arguments as arguments for httpd program Skript předává své argumenty programu httpd
    
    									grep HTTPD /usr/local/apache2/bin/apachectl
    									HTTPD='/usr/local/apache2/bin/httpd'
    									  $HTTPD -k $ARGV
    									  $HTTPD -t
    									  $HTTPD $ARGV
    
    									file -b /usr/local/apache2/bin/httpd
    									ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, …
    								

Configuration

Konfigurace

  • Alternate configuration file Volba konfiguračního souboru
    
    									apachectl -f /usr/local/apache2/conf/httpd.conf
    								
  • Compiled modules (static) list Seznam zakompilovaných (statických) modulů
    
    									apachectl -l
    								
  • Loading modules (dynamic/static) list according to configuration Seznam načítaných (dynamických/statických) modulů podle konfigurace
    
    									apachectl -M
    								

Documentation

Dokumentace

Local documentation

Lokální dokumentace

  • In case of incorporation into server infrastructure V případě začlenění do infrastruktury
    
    									man apachectl
    									man apache2
    								
  • In case of compilation and installation into /usr/local/apache2 V případě kompilace a instalace do /usr/local/apache2
    
    									man /usr/local/apache2/man/man8/apachectl.8
    									man /usr/local/apache2/man/man8/httpd.8
    									export MANPATH=$MANPATH:/usr/local/apache2/man
    									man apachectl
    									man httpd
    								
  • Local web-based documentation (HTML) Lokální webová dokumentace (HTML)

On-line documentation

On-line dokumentace

httpd.apache.org/docs/2.4/

  • Reference Manual
    • Compiling and Installing
    • Directive Quick-Reference
    • Modules
    • Server and Supporting Programs
    • Glossary
  • Users' Guide
  • How-To / Tutorials
  • Platform Specific Notes
  • Other Topics

LAB: Installation

LAB: Instalace

Download and compile

Stažení a kompilace

The goal is to download and compile webserver from source code, to start and test running webserver. The small changes in configuration files to enable local web documentation are parts of that task.

Cílem je stažení a kompilace ze zdrojových kódů, spuštění serveru a jeho otestování. Součástí úlohy je také úprava konfigurace a zpřístupnění lokální webové dokumentace.

  • Download, compile and start web server
  • Check whether the web server is running
  • Change configuration and restart web server
  • Display local web-based documentation
  • Stažení, kompilace a start serveru
  • Kontrola běhu serveru
  • Změna konfigurace a restart serveru
  • Zobrazení lokální dokumentace

Compilation notes

Poznámka ke kompilaci

  • The APR is not default part of Apache httpd version 2.4. source codes any more
  • The APR is self standing now It is possible to use APR that is already installed
  • That's why the apr and apr-util source codes are needed to be downloaded otherwise
  • APR usage information is in INSTALL file inside Apache httpd source codes
  • Kompilace apache 2.4. již neobsahuje automaticky APR
  • APR se nyní dodává zvlášť Je možné použít již nainstalované APR
  • Proto je potřeba stáhnout zdrojové kódy apr a apr-util
  • Informace o použití APR při kompilaci jsou v souboru INSTALL zdrojových kódů Apache

Another Apache httpd server is already installed using package manager at this system. That's why is important to call newly compiled programs within pathname!

V systému je nainstalovaný ještě Apache z balíčkovacího systému, proto je potřeba volat programy zkompilovaného Apache včetně cesty!

  1. Download and check source codes integrity from Stažení a kontrola zdrojových kódů z http://httpd.apache.org
    
    									sha256sum -c *.sha256
    								
  2. Extract source codes from archive Rozbalení zdrojových kódů
    
    									tar xzf httpd*.gz
    								
  3. Compilation and installation Kompilace/instalace
    
    									./configure && make && make install
    								
  4. Run compiled web server Spuštění severu
    
    									/usr/local/apache2/bin/apachectl start
    								
  1. Check whether the webserver is running Kontrola běhu serveru
    
    									telnet localhost 80
    									GET / HTTP/1.0
    
    									netstat -tapln
    
    									pgrep -l httpd
    								
  2. Check the web server is running using web browser Kontrola běhu serveru v prohlížeči
  3. List static modules and modules that are loaded dynamically (shared) Zjištění staticky zkompilovaných modulů a načítaných dynamických (shared) modulů
    
    									/usr/local/apache2/bin/apachectl -l
    									/usr/local/apache2/bin/apachectl -M
    								
    The status module is being loaded but info module is not Je načítán modul status a není načítán modul info

Tips

Tipy

  • List of open files (TCP ports), 80/http Seznam otevřených souborů (TCP portů), 80/http
    
    									lsof -i :80
    									lsof -i :http
    								
  • Basic curl usage Použití příkazu curl
    
    									# prints out response body (GET method)
    									curl URI
    									# prints out head and body of response (GET method)
    									curl -i URI
    									# prints out only head of response (HEAD method)
    									curl -I URI
    								
  • Basic wget usage Použití příkazu wget
    
    									# saves reponse body into file
    									wget URL
    									# prints out response body
    									wget -O - URL
    									# prints out response body to stdout and response head to stderr
    									wget -S -O - URL
    								

Vim tip

  • Case-insensitive search
    • /\ctext
    • set ignorecase
    • Save set ignorecase into vim configuration file ~/.vimrc
  • Vyhledávání bez ohledu na velikost písmen
    • /\ctext
    • set ignorecase
    • Uložit set ignorecase do souboru ~/.vimrc
  1. Load status module (mod_status) configuration Uncomment line: Include conf/extra/httpd-info.conf in /usr/local/apache2/conf/httpd.conf file Konfigurace status modulu (mod_status) - Načtení konfigurace Odkomentujte řádky: Include conf/extra/httpd-info.conf v souboru /usr/local/apache2/conf/httpd.conf
    
    									vi /usr/local/apache2/conf/httpd.conf
    									/usr/local/apache2/bin/apachectl -M | grep info
    								
  2. Allow access to status information from mod_status Edit line: Require host … in /usr/local/apache2/conf/extra/httpd-info.conf file Povolení přístupu k informacím z mod_status Modifikace řádky Require host … v souboru /usr/local/apache2/conf/extra/httpd-info.conf
    
    									vi /usr/local/apache2/conf/extra/httpd-info.conf
    									Require host .example.com → Require host localhost
    								
  1. Restart server Restart serveru
    
    									/usr/local/apache2/bin/apachectl restart
    								
  2. Check whether the module is working using web browser: Ověření funkčnosti modulu v prohlížeči: http://localhost/server-status
  3. Uncomment info module loading (LoadModule) Odkomentovat načtení modulu info (LoadModule)
    
    									vi /usr/local/apache2/conf/httpd.conf
    								
  4. Restart server Restart serveru
    
    									/usr/local/apache2/bin/apachectl restart
    								
  5. Check whether the module is working using web browser: Ověření funkčnosti modulu v prohlížeči: http://localhost/server-info
  1. Enable local web-based documentation Uncomment line Include conf/extra/httpd-manual.conf in /usr/local/apache2/conf/httpd.conf file Zpřístupnění lokální webové dokumentace Odkomentování řádky Include conf/extra/httpd-manual.conf v souboru /usr/local/apache2/conf/httpd.conf
    
    									vi /usr/local/apache2/conf/httpd.conf
    								
  2. Restart server Restart serveru
    
    									/usr/local/apache2/bin/apachectl restart
    								
  3. Display local web-based documentation: Zobrazení lokální webové dokumentace: http://localhost/manual

Troubleshooting

  1. Unknown directive LanguagePriority
  2. Find out module that defines that directive in documentation
  3. Find out configuration line that enables that module
  4. Uncomment that line containing LoadModule …
  5. Find out the address that local documentation starts with
  1. Neznámá direktiva LanguagePriority
  2. Najít v dokumentaci modul, který ji definuje
  3. Najít v konfiguraci řádku pro načtení daného modulu
  4. Odkomentovat řádku LoadModule …
  5. Najít v konfiguraci, pod jakou adresou je manuál dostupný