Printah Migunani kanggo Ngatur Server Web Apache ing Linux


Ing tutorial iki, kita bakal njlèntrèhaké sawetara perintah manajemen layanan Apache (HTTPD) sing paling umum digunakake sing kudu sampeyan ngerti minangka pangembang utawa administrator sistem lan sampeyan kudu nyimpen printah kasebut ing pucuk driji. Kita bakal nuduhake printah kanggo Systemd lan SysVinit.

Priksa manawa, perintah ing ngisor iki kudu dieksekusi minangka pangguna root utawa sudo lan kudu digunakake ing distribusi Linux kayata CentOS, RHEL, Fedora Debian, lan Ubuntu.

Instal Server Apache

Kanggo nginstal server web Apache, gunakake manajer paket distribusi standar kaya sing ditampilake.

$ 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]

Priksa Versi Apache

Kanggo mriksa versi server web Apache sing wis diinstal ing sistem Linux, jalanake printah ing ngisor iki.

$ sudo httpd -v
OR
$ sudo apache2 -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09

Yen sampeyan pengin nampilake nomer versi Apache lan ngumpulake setelan, gunakake gendera -V kaya sing ditampilake.

$ sudo httpd -V
OR
$ sudo apache2 -V
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"

Priksa Kesalahan Sintaks Konfigurasi Apache

Kanggo mriksa file konfigurasi Apache kanggo kesalahan sintaks, gunakake printah ing ngisor iki, sing bakal mriksa kesahihan file konfigurasi, sadurunge miwiti maneh layanan.

$ sudo httpd -t
OR
$ sudo apache2ctl -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using linux-console.net. 
Set the 'ServerName' directive globally to suppress this message
Syntax OK

Miwiti Layanan Apache

Kanggo miwiti layanan Apache, jalanake printah ing ngisor iki.

------------ 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]

Aktifake Layanan Apache

Printah sadurunge mung miwiti layanan Apache sauntara, kanggo ngaktifake otomatis nalika boot sistem, jalanake printah ing ngisor iki.

------------ 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]

Wiwiti maneh Layanan Apache

Kanggo miwiti maneh Apache (mandheg banjur miwiti layanan), jalanake printah ing ngisor iki.

------------ 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]

Deleng Status Layanan Apache

Kanggo mriksa informasi status wektu mlaku layanan Apache, jalanake printah ing ngisor iki.

------------ 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]

Muat ulang Layanan Apache

Yen sampeyan wis nggawe owah-owahan ing konfigurasi server Apache, sampeyan bisa nglatih layanan kasebut kanggo ngunggah maneh konfigurasi kasebut kanthi nggunakake printah ing ngisor iki.

------------ 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]

Mungkasi Layanan Apache

Kanggo mungkasi layanan Apache, gunakake printah ing ngisor iki.

------------ 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]

Tampilake Bantuan Komando Apache

Paling ora, sampeyan bisa njaluk bantuan babagan printah layanan Apache ing systemd kanthi nglakokake printah ing ngisor iki.

$ sudo httpd -h
OR
$ sudo apache2 -h		
OR
$ systemctl -h apache2	
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)

Sampeyan bisa nemokake informasi luwih lengkap babagan systemctl kanthi konsultasi: Cara Ngatur Layanan lan Unit 'Systemd' Nggunakake 'Systemctl' ing Linux.

Sampeyan bisa uga seneng maca artikel sing gegandhengan karo Apache iki.

  1. 5 Tips kanggo Ningkatake Kinerja Server Web Apache
  2. Carane Ngawasi Muatan Server Web Apache lan Statistik Halaman
  3. Carane Ngatur Server Web Apache Nggunakake Alat \Apache GUI
  4. Carane Ngganti Port HTTP Apache ing Linux
  5. 13 Tip Keamanan lan Pengerasan Server Web Apache
  6. Lindungi Apache Saka Brute Force utawa Serangan DDoS Nggunakake Modul Mod_Security lan Mod_evasive

Iku kabeh kanggo saiki! Ing artikel iki, kita wis nerangake perintah manajemen layanan Apache/HTTPD sing paling umum digunakake sing kudu sampeyan ngerti, kalebu miwiti, ngaktifake, miwiti maneh lan mungkasi Apache. Sampeyan bisa tekan kita liwat formulir umpan balik ing ngisor iki kanggo pitakon utawa komentar.