title | subtitle | author | date |
---|---|---|---|
4.1. Installatie van een webserver (Debian) |
Linux for Data Scientists<br/>HOGENT toegepaste informatica |
Thomas Parmentier, Andy Van Maele, Bert Van Vreckem |
2024-2025 |
- LAMP-stack: Linux + Apache + MariaDB + PHP
- Website bekijken in de browser
$ sudo apt install apache2 mariadb-server php
/etc/apache2/
: configuratie Apache/etc/apache2/apache2.conf
/etc/apache2/conf-enabled/*.conf
/etc/apache2/mods-enabled/*.conf
/etc/apache2/sites-enabled/*.conf
/var/www/html/
: Apache DocumentRoot/var/log/apache2/
: logbestandenaccess.log
error.log
- Bij installatie worden services automatisch opgestart
- Na rebooten eveneens
- Controleer!
systemctl status mariadb
systemctl status apache2
ss -tlnp
$ sudo systemctl start <service>
$ sudo systemctl stop <service>
$ sudo systemctl restart <service>
$ sudo systemctl enable <service>
$ sudo systemctl disable <service>
ss = Show Sockets
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
linuxmint@linuxmint21:~$ sudo ss -tlnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 80 127.0.0.1:3306 0.0.0.0:* users:(("mariadbd",pid=45957,fd=20))
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=850,fd=3))
LISTEN 0 511 *:80 *:* users:(("apache2",pid=52633,fd=4),[...])
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=850,fd=4))
- CLI webbrowser op de VM
- surf naar http://localhost/
curl localhost
curl 127.0.0.1
- PHP testen: maak bestand
/var/www/html/info.php
- Surf naar: http://localhost/info.php
<?php phpinfo(); ?>
Voorbeeld voor Apache:
$ sudo journalctl
$ sudo journalctl -u apache2
$ sudo journalctl -flu apache2
$ sudo tail -f /var/log/apache2/access_log
$ sudo tail -f /var/log/apache2/error_log
journalctl
vereist root-permissies- Of voeg gebruiker toe aan groep
adm
ofsystemd-journal
- Of voeg gebruiker toe aan groep
- Andere logbestanden:
/var/log/syslog
(hoofd-logbestand)/var/log/dmesg
(log bootproces)- ...
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!
- Controleer IP-adres VM:
ip a
- VBox NAT-interface: 10.0.2.15
- Stel port forwarding regels in
- Open webbrowser op fysiek systeem
- surf naar http://127.0.0.1:8080/info.php
$ sudo mysql_secure_installation
- Volg de instructies!
- (optioneel) kies MariaDB root-wachtwoord
- ≠ wachtwoord Linux root!
- bevestig andere vragen (ENTER)
Hou je wachtwoorden goed bij!
$ sudo mysql mysql
...
MariaDB [mysql]> SHOW DATABASES;
MariaDB [mysql]> SELECT user,password from user;
MariaDB [mysql]> quit
sudo
=> inloggen als MariaDB-rootmysql
: inloggen op databasemysql
Ga nu zelf verder met de labo-oefening! Leerpad 4.4.1