4.1. Installatie van een webserver (EL)

Linux for Operations
HOGENT toegepaste informatica

Thomas Parmentier, Andy Van Maele, Bert Van Vreckem

2024-2025

Webserver installatie

Doelstelling

  • LAMP-stack: Linux + Apache + MariaDB + PHP
  • Website bekijken vanop de andere VM (Linux Mint)

Installatie software

$ sudo dnf install httpd mariadb-server php

Belangrijke directories

  • /etc/httpd/: configuratie Apache
    • /etc/httpd/conf/httpd.conf
    • /etc/httpd/conf.d/*.conf
  • /var/www/html/: Apache DocumentRoot
  • /var/log/httpd/: logbestanden
    • access_log
    • error_log

Services opstarten

$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb
$ sudo systemctl start httpd
$ sudo systemctl enable httpd
  • start: nu opstarten
  • enable: automatisch opstarten bij booten

Test de services

$ systemctl status httpd
$ systemctl status mariadb
<?php phpinfo(); ?>

Toon sockets/poorten in gebruik

Show sockets: ss

  • netstat is obsolete, replaced by ss
    • netstat uses /proc/net/tcp
    • ss directly queries the kernel
  • Similar options

ss Options

Task Command
Show server sockets ss -l, --listening
Show TCP sockets ss -t, --tcp
Show UDP sockets ss -u, --udp
Show port numbers(*) ss -n, --numeric
Show process(†) ss -p, --processes

(*) instead of service names from /etc/services

(†) root permissions required

Example

$ sudo ss -tlnp
State   Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN  0      128                *:22              *:*    users:(("sshd",pid=1290,fd=3))
LISTEN  0      100        127.0.0.1:25              *:*    users:(("master",pid=1685,fd=13))
LISTEN  0      128               :::80             :::*    users:(("httpd",pid=4403,fd=4),("httpd",pid=4402,fd=4),("httpd",pid=4401,fd=4),("httpd",pid=4400,fd=4),("httpd",pid=4399,fd=4),("httpd",pid=4397,fd=4))
LISTEN  0      128               :::22             :::*    users:(("sshd",pid=1290,fd=4))
LISTEN  0      100              ::1:25             :::*    users:(("master",pid=1685,fd=14))
LISTEN  0      128               :::443            :::*    users:(("httpd",pid=4403,fd=6),("httpd",pid=4402,fd=6),("httpd",pid=4401,fd=6),("httpd",pid=4400,fd=6),("httpd",pid=4399,fd=6),("httpd",pid=4397,fd=6))

Logbestanden

Voorbeeld voor Apache:

$ sudo journalctl
$ sudo journalctl -u httpd
$ sudo journalctl -flu httpd
$ sudo tail -f /var/log/httpd/access_log
$ sudo tail -f /var/log/httpd/error_log

journalctl

  • journalctl requires root permissions
    • Or, add user to group adm or systemd-journal
  • Some “traditional” text-based log files still exist (for now?):
    • /var/log/messages (gone in Fedora!)
    • /var/log/httpd/access_log and error_log

Options

Action Command
Show latest log and wait for changes journalctl -f, --follow
Show only log of SERVICE journalctl -u SERVICE, --unit=SERVICE
Match executable, e.g. dhclient journalctl /usr/sbin/dhclient
Match device node, e.g. /dev/sda journalctl /dev/sda
Show auditd logs journalctl _TRANSPORT=audit
Action Command
Show log since last boot journalctl -b, --boot
Kernel messages (like dmesg) journalctl -k, --dmesg
Reverse output (newest first) journalctl -r, --reverse
Show only errors and worse journalctl -p err, --priority=err
Since yesterday journalctl --since=yesterday

Filter on time (example):

journalctl --since=2018-06-00 \
           --until="2018-06-07 12:00:00"

Much more options in the man-page!

Website vanaf GUI Linux VM bekijken

  • Controleer IP-adres VM: ip a
    • waarschijnlijk 192.168.76.2
      • verifieer dat je GUI Linux VM een IP-adres in dit netwerk heeft
      • ping ?!
  • Open webbrowser op fysiek systeem

Database beveiligen

$ sudo mysql_secure_installation
  • Volg de instructies!
  • kies MariaDB root-wachtwoord
    • ≠ wachtwoord Linux root!
  • bevestig andere vragen (ENTER)

Hou je wachtwoorden goed bij!

Database testen: root

$ mysql -uroot -pR2rrbLV02TA1hAjN mysql
...
MariaDB [mysql]> SHOW DATABASES;
MariaDB [mysql]> SELECT user,password from user;
MariaDB [mysql]> quit
  • -uroot: inloggen als MariaDB-root
  • -pR2rrbLV02TA1hAjN: gekozen wachtwoord
    • (GEEN spatie na -p)
  • mysql: inloggen op database mysql