In deze tutorial zullen we enkele van de meest gebruikte Apache (HTTPD) service beheercommando’s beschrijven die u als ontwikkelaar of systeembeheerder zou moeten kennen en deze commando’s bij de hand moeten houden. We zullen commando’s tonen voor zowel Systemd als SysVinit.
Lees ook: 10 Meest Gebruikte Nginx Commando’s Die Elke Linux Gebruiker Moet Kennen
Zorg ervoor dat, de volgende commando’s moeten worden uitgevoerd als een root of sudo gebruiker en zouden moeten werken op elke Linux distributie zoals CentOS, RHEL, Fedora Debian, en Ubuntu.
Installeer Apache Server
Om de Apache webserver te installeren, gebruik uw standaard distributiepakketbeheerder zoals weergegeven.
$ sudo apt install apache2 [On Debian/Ubuntu] $ sudo yum install httpd [On RHEL/CentOS] $ sudo dnf install httpd [On Fedora 22+] $ sudo zypper install apache2 [On openSUSE]
Controleer Apache Versie
Om de geïnstalleerde versie van uw Apache webserver op uw Linux systeem te controleren, voer het volgende commando uit.
$ sudo httpd -v OR $ sudo apache2 -v
Voorbeeld Uitvoer
Server version: Apache/2.4.6 (CentOS) Server built: Nov 5 2018 01:47:09
Als u het Apache versienummer en compileerinstellingen wilt weergeven, gebruik de -V
vlag zoals weergegeven.
$ sudo httpd -V OR $ sudo apache2 -V
Voorbeeld Uitvoer
Server version: Apache/2.4.6 (CentOS) Server built: Nov 5 2018 01:47:09 Server's Module Magic Number: 20120211:24 Server loaded: APR 1.4.8, APR-UTIL 1.5.2 Compiled using: APR 1.4.8, APR-UTIL 1.5.2 Architecture: 64-bit Server MPM: prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/etc/httpd" -D SUEXEC_BIN="/usr/sbin/suexec" -D DEFAULT_PIDLOG="/run/httpd/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf"
Controleer Apache Configuratie Syntax Fouten
Om uw Apache configuratiebestanden te controleren op eventuele syntaxfout
$ sudo httpd -t OR $ sudo apache2ctl -t
Voorbeelduitvoer
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using tecmint.com. Set the 'ServerName' directive globally to suppress this message Syntax OK
Start Apache-service
Om de Apache-service te starten, voer het volgende commando uit.
------------ On CentOS/RHEL ------------ $ sudo systemctl start httpd [On Systemd] $ sudo service httpd start [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl start apache2 [On Systemd] $ sudo service apache2 start [On SysVInit]
Activeer Apache-service
Het vorige commando start alleen de Apache-service voorlopig, om deze automatisch te laten starten bij het opstarten van het systeem, voer het volgende commando uit.
------------ On CentOS/RHEL ------------ $ sudo systemctl enable httpd [On Systemd] $ sudo chkconfig httpd on [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl enable apache2 [On Systemd] $ sudo chkconfig apache2 on [On SysVInit]
Herstart Apache-service
Om Apache te herstarten (stop en vervolgens start de service), voer het volgende commando uit.
------------ On CentOS/RHEL ------------ $ sudo systemctl restart httpd [On Systemd] $ sudo service httpd restart [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl restart apache2 [On Systemd] $ sudo service apache2 restart [On SysVInit]
Bekijk Apache-servicestatus
Om de actuele statusinformatie van de Apache-service te controleren, voer het volgende commando uit.
------------ On CentOS/RHEL ------------ $ sudo systemctl status httpd [On Systemd] $ sudo service httpd status [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl status apache2 [On Systemd] $ sudo service apache2 status [On SysVInit]
Herlaad Apache-service
Als je wijzigingen hebt aangebracht in de configuratie van de Apache-server, kun je de service instrueren om de configuratie opnieuw te laden door het volgende commando uit te voeren.
------------ On CentOS/RHEL ------------ $ sudo systemctl reload httpd [On Systemd] $ sudo service httpd reload [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl reload apache2 [On Systemd] $ sudo service apache2 reload [On SysVInit]
Stop Apache-service
Om de Apache-service te stoppen, gebruik het volgende commando.
------------ On CentOS/RHEL ------------ $ sudo systemctl stop httpd [On Systemd] $ sudo service httpd stop [On SysVInit] ------------ On Ubunt/Debian ------------ $ sudo systemctl stop apache2 [On Systemd] $ sudo service apache2 stop [On SysVInit]
Toon Apache-commandohulp
Tenslotte kun je hulp krijgen over de Apache-servicecommando’s onder systemd door het volgende commando uit te voeren.
$ sudo httpd -h OR $ sudo apache2 -h OR $ systemctl -h apache2
Voorbeelduitvoer
Usage: httpd [-D name] [-d directory] [-f file] [-C "directive"] [-c "directive"] [-k start|restart|graceful|graceful-stop|stop] [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X] Options: -D name : define a name for use in directives -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile -C "directive" : process directive before reading config files -c "directive" : process directive after reading config files -e level : show startup errors of level (see LogLevel) -E file : log startup errors to file -v : show version number -V : show compile settings -h : list available command line options (this page) -l : list compiled in modules -L : list available configuration directives -t -D DUMP_VHOSTS : show parsed vhost settings -t -D DUMP_RUN_CFG : show parsed run settings -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG -t -D DUMP_MODULES : show all loaded modules -M : a synonym for -t -D DUMP_MODULES -t : run syntax check for config files -T : start without DocumentRoot(s) check -X : debug mode (only one worker, do not detach)
Je kunt meer informatie over systemctl vinden door te raadplegen: Hoe ‘Systemd’-services en eenheden beheren met ‘Systemctl’ in Linux.
Je wilt misschien ook de volgende Apache-gerelateerde artikelen lezen.
- 5 Tips om de prestaties van uw Apache-webserver te verbeteren
- Hoe de belasting en paginastatistieken van de Apache-webserver te monitoren
- Hoe de Apache-webserver te beheren met behulp van de “Apache GUI” -tool
- Hoe de Apache HTTP-poort te wijzigen in Linux
- 13 tips voor beveiliging en verharding van de Apache-webserver
- Bescherm Apache tegen brute force- of DDoS-aanvallen met behulp van de modules Mod_Security en Mod_evasive
Dat is alles voor nu! In dit artikel hebben we de meest gebruikte beheeropdrachten voor de Apache/HTTPD -service uitgelegd die u zou moeten kennen, inclusief het starten, inschakelen, herstarten en stoppen van Apache. U kunt ons altijd bereiken via het feedbackformulier hieronder voor vragen of opmerkingen.
Source:
https://www.tecmint.com/manage-apache-web-server-in-linux/