{{tag>matériel}}
====== LAMP : un serveur HTTP sous Linux, Apache 2, MySQL et PHP ======
Un serveur **LAMP** est un serveur Web basé sur **Apache**
L'acronyme **LAMP** signifie **L**inux **A**pache **M**ySQL **P**HP :
? Linux
: système d'exploitation du système
? Apache
: serveur HTTP
? MySQL
: système de gestion de base de données.
? PHP/Python/Perl
: langage de programmation associé
===== Compatibilité =====
===== Pré-requis =====
===== Installation =====
==== Méthode avec tasksel ====
- **Installez Tasksel** :~$ sudo apt install tasksel
- **Lancez ** :~$ sudo tasksel
- **Avec les flèches, sélectionner web server**, une tabulation pour choisir OK et Entrée pour accepter
- **Attendre un peu** : le serveur LAMP est installé.
==== Méthode complète, détaillée ====
- **LAMP** :
- **Apache** :
- **[[apt>apache2,apache2-utils]]** :~$ sudo apt install {apache2,apache2-utils}
- **Vérifier le status d'Apache** :~$ sudo systemctl status apache2S'il n’est pas démarré :~$ sudo systemctl start apache2
- **Faire démarrer Apache au démarrage système** :~$ sudo systemctl enable apache2
- **vérifier la version d’Apache** :~$ apache2 -v
- **Ouvrir l'adresse [[http://localhost]]**La page "It works !" d'Apache doit s'afficher
- **[[apt>libncurses5]]** :~$ sudo apt install libncurses5
- **MariaDb**
- **Installer [[apt>mariadb-server,mariadb-client]]** :~$ sudo apt install {mariadb-server,mariadb-client}
- **Vérifier le status de MariaDb** :~$ systemctl status mariadbSi MariaDB n’est pas active, le lancer :~$ sudo systemctl start mariadb
- **Faire démarrer MariaDb au démarrage système** :~$ sudo systemctl enable mariadb
- **vérifier la version de MariaDB** :~$ mariadb --version
- **PHP**
- **[[apt>php-fpm]]**~$ sudo apt install php-fpminstalle aussi les dépendances : php8.1-cli, php-common, php8.1-opcache, php8.1-readline
- **Vérifier la version de PHP** :~$ php --version
PHP 8.1.2-1ubuntu2.15 (cli)...
- **Activer les modules proxy_fcgi et setenvif** :~$ sudo a2enmod proxy_fcgi setenvif
Modules activés à ce stade :
access_compat.load
alias.conf
alias.load
auth_basic.load
authn_core.load
authn_file.load
authz_core.load
authz_host.load
authz_user.load
autoindex.conf
autoindex.load
deflate.conf
deflate.load
dir.conf
dir.load
env.load
filter.load
mime.conf
mime.load
mpm_prefork.conf
mpm_prefork.load
negotiation.conf
negotiation.load
php8.1.conf
php8.1.load
proxy.conf
proxy_fcgi.load
proxy.load
reqtimeout.conf
reqtimeout.load
setenvif.conf
setenvif.load
status.conf
status.load
vhost_alias.load
- **Transmettre toutes requête destinée à php** (pour tous les vhosts ; mettre la bonne version de php) :~$ sudo a2enconf php8.1-fpm
- **Modules PHP : [[apt>php-apcu,php-curl,php-gd,php-imagick,php-imap,php-intl,php-json,php-mbstring,php-mysql,php-xml,php-zip]]**
- **Activer vhost_alias** :~$ sudo a2enmod vhost_alias
~$ sudo systemctl restart apache2
==== Fichiers sur framboise4 ====
# fermier dokufarmer
ServerName dokufarmer.framboise4.parc
DocumentRoot /var/www/html/framboise4/dokufarmer
AllowOverride All
Require all granted
DirectoryIndex index.php index.html index.htm
Require all denied
Satisfy All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# sous-domaine ferme.framboise4.parc
ServerName ferme.framboise4.parc
ServerAlias www.ferme.framboise4.parc
DocumentRoot /var/www/html/dokuwiki
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ErrorLog ${APACHE_LOG_DIR}/ferme.framboise4.parc_error.log
CustomLog ${APACHE_LOG_DIR}/ferme.framboise4.parc_access.log combined
# sous-domaine doc.framboise4.parc
ServerName doc.framboise4.parc
ServerAlias www.doc.framboise4.parc
DocumentRoot /var/www/html/dokuwiki
php_admin_value post_max_size 1000M
php_admin_value upload_max_filesize 1000M
php_admin_value memory_limit 2000M
# php_admin_value max_execution_time 360
# php_admin_value max_input_time 360
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ErrorLog ${APACHE_LOG_DIR}/doc.framboise4.parc_error.log
CustomLog ${APACHE_LOG_DIR}/doc.framboise4.parc_access.log combined
# sous-domaine doc1.framboise4.parc
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ServerName doc1.framboise4.parc
ServerAlias www.doc1.framboise4.parc
DocumentRoot /var/www/html/dokuwiki
ErrorLog ${APACHE_LOG_DIR}/doc1.framboise4.parc_error.log
CustomLog ${APACHE_LOG_DIR}/doc1.framboise4.parc_access.log combined
# sous-domaine doc0.framboise4.parc
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ServerName doc0.framboise4.parc
ServerAlias www.doc0.framboise4.parc
DocumentRoot /var/www/html/doc0
ErrorLog ${APACHE_LOG_DIR}/doc0.framboise4.parc_error.log
CustomLog ${APACHE_LOG_DIR}/doc0.framboise4.parc_access.log combined
# sous-domaine perso.framboise4.parc
ServerName perso.framboise4.parc
ServerAlias www.perso.framboise4.parc
DocumentRoot /var/www/html/perso
ErrorLog ${APACHE_LOG_DIR}/doc.framboise4.parc_error.log
CustomLog ${APACHE_LOG_DIR}/doc.framboise4.parc_access.log combined
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
# sous-domaine php.framboise4.parc
ServerName php.framboise4.parc
ServerAlias www.php.framboise4.parc
DocumentRoot /var/www/html/php
ErrorLog ${APACHE_LOG_DIR}/php.framboise4.parc_error.log
CustomLog ${APACHE_LOG_DIR}/php.framboise4.parc_access.log combined
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ServerAlias *.framboise4.parc
ServerAdmin root@localhost
UseCanonicalName Off
DocumentRoot /var/www/html
VirtualDocumentRoot /var/www/html/%1
Options Indexes FollowSymLinks MultiViews
ServerSignature Off
ErrorLog /var/log/apache2/error.site.fr.log
LogLevel warn
CustomLog /var/log/apache2/access.log "%{%Y-%m-%d %H:%M:%S}t # %a # %>s # %f # %q # %H # %l # %m # %u # %b # \" %{User-agent}i\""
===== Configuration =====
==== Apache ====
- **Créer la structure du site** sur un disque et la monter sur /var/www/
- **rendre www-data (utilisateur Apache) propriétaire de la racine Web** :~$ sudo chown www-data:www-data /var/www/html/ -R
- **Validation de la configuration par défaut** :~$ sudo apachectl -t
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK**Pour supprimer ce message d'erreur** s'il se produit :
- **Éditer ou créer avec les droits d'administration le fichier /etc/apache2/conf-available/servername.conf** pour y ajouter la ligne :ServerName localhost
- **Activer ce fichier de configuration** :~$ sudo a2enconf servername.conf
- **Relancer apache** :~$ sudo systemctl reload apache2
- L'erreur a disparu :~$ sudo apachectl -t
Syntax OK
==== MariaDb ====
- **Lancer le script de configuration** :
* À la première étape, appuyer sur la touche entrée pour valider que le mot de passe actuel est vide.
* puis choisir un nouveau mot de passe
* pour le reste, appuyer sur Entrée à chaque fois~$ sudo mysql_secure_installation
...
Enter current password for root (enter for none):
...
Switch to unix_socket authentication [Y/n]
...
Change the root password? [Y/n]
New password:
Re-enter new password:
...
Remove anonymous users? [Y/n]
...
Disallow root login remotely? [Y/n]
...
Remove test database and access to it? [Y/n]
...
Reload privilege tables now? [Y/n]
...
Thanks for using MariaDB!
==== Hôtes virtuels ====
=== chateau.parc ===
- Fichier :
# chateau.parc
UseCanonicalName Off
ServerName chateau.parc
DocumentRoot /var/www/html
Require all granted
DirectoryIndex index.php index.html index.htm index.html.apache
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# dolibarr.chateau.parc
UseCanonicalName Off
ServerName dolibarr.chateau.parc
VirtualDocumentRoot /var/www/html/%-3/htdocs
Require all granted
DirectoryIndex index.php index.html index.htm
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
#########
# Wikis #
#########
# Ferme wiki.chateau.parc
# fermier : chateau/fermier (wiki.chateau.parc)
UseCanonicalName Off
ServerName wiki.chateau.parc
ServerAlias *.wiki.chateau.parc
VirtualDocumentRoot /var/www/html/chateau/fermier
Require all granted
DirectoryIndex index.php index.html index.htm
Require all denied
Satisfy All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# doc.chateau.parc, doc0.chateau.parc, doc-old.chateau.parc
# essai.chateau.parc
# perso.chateau.parc, perso-old.chateau.parc, perso0.chateau.parc
# kine.chateau.parc
# magie.chateau.parc
UseCanonicalName Off
ServerName doc.chateau.parc
ServerAlias doc*.chateau.parc
ServerAlias essai.chateau.parc kine.chateau.parc magie.chateau.parc
ServerAlias perso.chateau.parc perso*.chateau.parc
VirtualDocumentRoot "/var/www/html/%-3"
Require all granted
DirectoryIndex index.php index.html index.htm
Require all denied
Satisfy All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# adminer.chateau.parc
# glpi.chateau.parc
# php.chateau.parc
# awstats.chateau.parc
UseCanonicalName Off
ServerName chateau.parc
ServerAlias *.chateau.parc
VirtualDocumentRoot "/var/www/html/%-3"
#~ AllowOverride All
Require all granted
DirectoryIndex index.php index.html index.htm
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
- **Activer l'hôte chateau.parc** :~$ sudo a2ensite chateau.parc.conf
~$ sudo systemctl reload apache2.service
===== Utilisation =====
===== Problèmes connus =====
===== Voir aussi =====
* **(fr)** [[https://www.tech2tech.fr/installation-de-lamp-sur-ubuntu-20-04/|]]
* **(fr)** [[https://www.paperblog.fr/9623121/2-facons-d-installer-le-serveur-lamp-sur-ubuntu-2204-2004/]]
----
//Basé sur << [[https://www.tech2tech.fr/installation-de-lamp-sur-ubuntu-20-04/|Installation de LAMP (Serveur Web) sur Ubuntu 20.04|]] >> par tech2tech.//