Installer un serveur Web (LAMP
)
Serveur Apache | Module php | Serveur MariaDB | Transférer son site Web |
Installer le serveur Apache (Serveur Web)
Documentation : Apache HTTP Server Documentation
Installer
pi@raspberrypi:~ $ sudo apt-get update pi@raspberrypi:~ $ sudo apt-get install apache2
Valider l'installation
Vérifier que le processus est démarré
pi@raspberrypi:~ $ ps -e | grep apache 17293 ? 00:00:00 apache2 17294 ? 00:00:00 apache2 17295 ? 00:00:00 apache2
Vérifier que le port utilisé par Apache
(80
par défaut) est ouvert
Commande ss
: another utility to investigate sockets
Options :
-l, --listening : Display only listening sockets.
-n, --numeric : Do not try to resolve service names.
-t, --tcp : Display TCP sockets.
pi@raspberrypi:~ $ ss -lnt sport = :80 State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:80 *:*
Le port 80
accepte les connexions IPv4
et IPv6
.
Vérifier l'état du serveur
pi@raspberrypi:~ $ sudo systemctl status apache2 ● apache2.service - The Apache HTTP Server ... Active: active (running) ... ... ................ raspberrypi systemd[1]: Starting The Apache HTTP Server... ................ raspberrypi apachectl[1319]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message ................ raspberrypi systemd[1]: Started The Apache HTTP Server.
La commande précédente indique que le serveur est démarré mais que son nom n'a pas pu être déterminé. On doit affecter la directive ServerName
dans le fichier /etc/apache2/apache2.conf
après en avoir fait une sauvegarde.
Sauvegarder la configuration initiale
pi@raspberrypi:~ $ sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.origin
Modifier /etc/apache2/apache2.conf
Ajoutez la modification à la fin du fichier à l'aide de l'éditeur de votre choix : nano
, ...
Résultat de la modification :
pi@raspberrypi:~ $ tail -1 /etc/apache2/apache2.conf ServerName raspberrypi.mazone.lan
Redémarrer Apache et vérifiez de l'état du serveur
pi@raspberrypi:~ $ sudo systemctl restart apache2 pi@raspberrypi:~ $ sudo systemctl status apache2 ● apache2.service - The Apache HTTP Server ... Active: active (running) ... ... ................ raspberrypi systemd[1]: Starting The Apache HTTP Server... ................ raspberrypi systemd[1]: Started The Apache HTTP Server.
Tester
- Page par défaut
Dans un navigateur, saisissez l'adresse IP de votre RPI, la page par défaut ci-dessous doit apparaître :

Les pages du site Web se trouvent dans le répertoire /var/www/html
.
- Une autre page
Après avoir sauvegardé la page par défaut index.html, créez la page index.html ci-dessous :
pi@raspberrypi:~ $ sudo mv /var/www/html/index.html /var/www/html/indexDefault.html pi@raspberrypi:~ $ sudo nano /var/www/html/index.html pi@raspberrypi:~ $ cat /var/www/html/index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Ma première page</title> </head> <body> <p>Bonjour en HTML</p> </body> </html>

Installer le module PHP
Installer
J'installe le module php-mysql
car il est utile si on souhaite communiquer avec une base MySQL
ce qui est la plupart du temps le cas.
pi@raspberrypi:~ $ sudo apt-get install php libapache2-mod-php php-mysql
Recharger la configuration
pi@raspberrypi:~ $ sudo service apache2 restart
Valider l'installation
Tester
Créez la page index.php
ci-dessous :
pi@raspberrypi:~ $ sudo nano /var/www/html/index.php pi@raspberrypi:~ $ cat /var/www/html/index.php <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Ma première page</title> </head> <body> <?php echo "<p>Bonjour en PHP</p>\n"; ?> </body>
Pour que la page se charge automatiquement en entrant l'URL
du site, il faut supprimer la page
index.html
.
pi@raspberrypi:~ $ sudo rm /var/www/html/index.html
Résultat :

Transférer son site Web
Créer un groupe pour les administrateurs du site
Créer le groupe webMaster
pi@raspberrypi:~ $ sudo groupadd webMaster
Vérifier en consultant le fichier des groupes : /etc/group
pi@raspberrypi:~ $ cat /etc/group | grep webMaster webMaster:x:1001:
Créer un utilisateur webMaster1
membre du groupe webMaster
et lui attribuer un mot de passe
Créer l'utilisateur
J'attribue à l'utilisateur le répertoire de travail /var/www/html
qui est la racine des sites Web utilisé par Apache
.
pi@raspberrypi:~ $ sudo useradd webMaster1 -g webMaster -d /var/www/html
Verifier la création de l'utilisateur
pi@raspberrypi:~ $ cat /etc/passwd | grep webMaster1 webMaster1:x:1001:1001::/var/www/html/:/bin/bash
Attribuer un mot de passe à l'utilisateur webMaster1
pi@raspberrypi:~ $ sudo passwd webMaster1
Changer les droits sur le répertoire /var/www/html
Droits avant modification
pi@raspberrypi:~ $ ls -l /var/www/ total 4 drwxr-xr-x 2 root root 4096 oct. 24 20:56 html
Attribuer le répertoire /var/www/html
(et les sous répertoires) au groupe webMaster
pi@raspberrypi:~ $ sudo chgrp -R webMaster /var/www/html
Donner le droit d'écriture
aux membres du groupe webMaster
pi@raspberrypi:~ $ sudo chmod g+w /var/www/html
Vérifier l'attribution des droits
pi@raspberrypi:~ $ ls -l /var/www/ drwxrwxr-x 2 root webMaster 4096 oct. 24 20:56 html
Tester en transférant son site Web
Transférer vos fichiers comme indiqué dans l'article : Raspberry Pi : Transférer des fichiers
Eventuellement :
Résultat :
