Wiki Gerfon

web

Installer LAMP (Linux, Apache, MySQL, PHP)

Pré-requis

Installer les paquets apache :

apt-get install apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php

Installer les paquets php :

apt-get install php php-common php-curl php-intl php-mbstring php-mysql php-gd php-imagick php-xml php-simplexml php-cli php-zip php-apcu unzip

Installer les paquets MariaDB :

apt install mariadb-client mariadb-server

Sécuriser MariaDB :

mysql_secure_installation

Modules Apache2

Afficher les modules chargés :

apachectl -t -D DUMP_MODULES

Activer les modules indispensables :

a2enmod ssl
a2enmod headers
a2enmod rewrite

APCU (gestion du cache)

Editer le fichier de configuration apcu.ini :

vi /etc/php/8.x/mods-available/apcu.ini

En fin de fichier, ajouter la ligne suivante :

apc.enable_cli=1

PHP

Editer le fichier de configuration PHP :

vi /etc/php/8.x/apache2/php.ini

Modifier les valeurs suivantes :

post_max_size = 500M
upload_max_filesize = 500M
max_file_uploads = 20

Virtualhost

Exemple :

<VirtualHost mon.site.fr:443>
ServerAdmin mail_admin@domain.fr
ServerName mon.site.fr
DocumentRoot /var/www/site
SSLEngine on
SSLCertificateFile /etc/ssl/site.pem
SSLCertificateKeyFile /etc/ssl/site.key
ErrorLog ${APACHE_LOG_DIR}/error.site.log
CustomLog ${APACHE_LOG_DIR}/access.site.log combined
<Directory /var/www/site/>
Options -Indexes +FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>

Activer un site :

a2ensite site.conf

Désactiver :

a2dissite site.conf

Désactiver ipv6

Editer le fichier ports.conf :

vi /etc/apache2/ports.conf

Modifier comme dans l’exemple suivant :

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 0.0.0.0:80
<IfModule ssl_module>
Listen 0.0.0.0:443
</IfModule>
<IfModule mod_gnutls.c>
Listen 0.0.0.0:443
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Certificats

Installer les paquets suivants :

apt install certbot python3-certbot-apache -y

Commande pour générer des certificats Let’s Encrypt :

certbot --apache

Sécurité

Masquer version Apache2

Pour empêcher Apache d’envoyer trop infos au navigateur, éditer :

vi /etc/apache2/conf-available/security.conf

Rentrer les valeurs suivantes :

ServerTokens Prod
...
ServerSignature Off

Permissions des fichiers

chown -R www-data:www-data /var/www/
chmod -R 755 /var/www/
<FilesMatch "\.(htaccess|htpasswd|ini|log|conf)$">
Require all denied
</FilesMatch>

ModSecurity (WAF pour Apache)

apt install libapache2-mod-security2
a2enmod security2
systemctl restart apache2
cp /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf
vi /etc/modsecurity/modsecurity.conf
puis
SecRuleEngine On
tail -f /var/log/apache2/modsec_audit.log

mod_evasive (protection contre DoS)

apt install libapache2-mod-evasive
a2enmod evasive
systemctl restart apache2
↑