Configuration PHP5

Preview:

DESCRIPTION

Présentation de la configuration PHP5 / php.ini

Citation preview

Jean-Marie Renouard

LightPath 2014©

Le logo PHP est du domaine public http://commons.wikimedia.org/wiki/File:PHP-logo.svg

Ce document est licencié sous licence ◦ Attribution-NonCommercial-ShareAlike

◦ CC BY-NC-SA

Plus de détails: http://creativecommons.org/licenses/by-nc-sa/3.0/fr/

LightPath 2014© - http://www.jmrenouard.fr 2

Les fichiers de paramétrage

Le fichier PHP.ini

Le fichier httpd.conf

Le fichier robots.txt

Le fichier .htaccess

LightPath 2014© - http://www.jmrenouard.fr 3

LightPath 2014© - http://www.jmrenouard.fr 4

php.ini : fichier principal de PHP

httpd.conf : fichier principal d’Apache

robots.txt : fichier d’indexation

.htaccess : fichier spécifique pour un répertoire

My.cnf : fichier de configuration MySQL

LightPath 2014© - http://www.jmrenouard.fr 5

LightPath 2014© - http://www.jmrenouard.fr 6

Retrait de fonctions et classes PHP ◦ disable_functions

◦ disable_classes

Limitation des temps de traitement ◦ max_execution_time

◦ max_input_time

Limitation de consommation mémoire ◦ memory_limit

LightPath 2014© - http://www.jmrenouard.fr 7

Limitation de la taille des données d’entrée ◦ post_max_size

Limitation de la taille des fichiers postés

◦ upload_max_filesize

Interdiction d’ouverture d’URL ◦ allow_url_fopen

Limitation des temps d’attente sur connexion TCP ◦ default_socket_timeout

LightPath 2014© - http://www.jmrenouard.fr 8

Retrait de l’entête HTTP de PHP ◦ explose_php=off

LightPath 2014© - http://www.jmrenouard.fr 9

Modification du report des erreurs ◦ error_reporting = E_ALL & ~E_NOTICE ◦ error_reporting = E_ALL

Interdiction d’affichage des erreurs ◦ display_errors=off ◦ display_startup_errors = Off

Activation de l’écriture des erreurs ◦ log_errors = On ◦ error_log=erreur_php.log

LightPath 2014© - http://www.jmrenouard.fr 10

Interdiction la traduction des variables POST et GET en variables PHP

register_globals = Off

LightPath 2014© - http://www.jmrenouard.fr 11

Gestion des chemins d’inclusion de code ◦ Include_path

◦ Chemins de recherche de include/require

Utilisation de set_include_path dans vos scripts.

LightPath 2014© - http://www.jmrenouard.fr 12

LightPath 2014© - http://www.jmrenouard.fr 13

Limitation des entêtes HTTP pour Apache ◦ ServerSignature Off

◦ ServerTokens Prod

Masquage des URLs réécriture html ->php ◦ RewriteEngine on

◦ RewriteRule ([^.]+)\.html$ $1\.php [L]

LightPath 2014© - http://www.jmrenouard.fr 14

Toutes les pages d’erreur ◦ Replacement par des chaînes

◦ Pas de lecture de fichier sur disque

Exemples: ◦ ErrorDocument 500 "Erreur Interne"

◦ ErrorDocument 404 "Page non trouvée"

◦ ErrorDocument 401 "Erreur authentification "

◦ ErrorDocument 403 "Pas de droits d’accès"

LightPath 2014© - http://www.jmrenouard.fr 15

Limitation de la bande passante à 200ko/s

<IfModule mod_bw.c>

BandwidthModule On

ForceBandWidthModule On

Bandwidth all 200240

MinBandwidth all -1

</IfModule>

LightPath 2014© - http://www.jmrenouard.fr 16

Limitation de la bande passante à 20ko/s pour les fichiers zip

<IfModule mod_bw.c> BandwidthModule On ForceBandWidthModule On LargeFileLimit .zip 1 20000 </IfModule>

LightPath 2014© - http://www.jmrenouard.fr 17

Interdiction du mode TRACE ◦ TraceEnable off

Autorisation exclusive des méthodes GET ou

POST ◦ RewriteEngine On ◦ RewriteCond %{REQUEST_METHOD}

^(TRACE|OPTIONS|CONNECT) ◦ RewriteRule .* - [F]

LightPath 2014© - http://www.jmrenouard.fr 18

Commenter toutes lignes LoadModule

Exemple: mod_proxy

LightPath 2014© - http://www.jmrenouard.fr 19

LightPath 2014© - http://www.jmrenouard.fr 20

Ne rien laisser indexer par les robots ◦ User-agent: *

◦ Disallow: /

Ne pas laisser ses applications Web être indexées par Google

LightPath 2014© - http://www.jmrenouard.fr 21

Interdiction partielle sur /admin, /images et /videos ◦ User-agent: *

◦ Disallow: /admin/*

◦ Disallow: /images/*

◦ Disallow: /videos/*

LightPath 2014© - http://www.jmrenouard.fr 22

LightPath 2014© - http://www.jmrenouard.fr 23

Possibilité d’ajout de réécriture d’URL ◦ RewriteEngine on

◦ RewriteRule ([^.]+)\.html$ $1.php[L]

LightPath 2014© - http://www.jmrenouard.fr 24

Interdiction pour tous sur /admin Autorisation pour l’IP Directives .htaccess dans le répertoire /admin

◦ Order deny,allow ◦ Deny from all ◦ Allow from 192.168.10.1

LightPath 2014© - http://www.jmrenouard.fr 25

Directive du .htaccess dans le répertoire

AuthName "Page d'administration protégée"

AuthType Basic

AuthUserFile ".htpasswd"

Require valid-user

LightPath 2014© - http://www.jmrenouard.fr 26

Création du fichier

Ajout d’un utilisateur jmren

Mot de passe totozero00

◦ htpasswd –b .htpasswd jmren totozero00

LightPath 2014© - http://www.jmrenouard.fr 27

LightPath: ◦ Société de conseil et d’ingénierie

◦ Formations, Conseil, Audit et mise en œuvre

◦ jmrenouard@lightpath.fr

Jean-Marie RENOUARD ◦ jmrenouard@gmail.com

◦ Twitter: @jmrenouard

◦ http://www.jmrenouard.fr

LightPath 2014© - http://www.jmrenouard.fr 28