28
Jean-Marie Renouard LightPath 2014©

Configuration PHP5

Embed Size (px)

DESCRIPTION

Présentation de la configuration PHP5 / php.ini

Citation preview

Page 1: Configuration PHP5

Jean-Marie Renouard

LightPath 2014©

Page 2: Configuration PHP5

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

Page 3: Configuration PHP5

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

Page 4: Configuration PHP5

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

Page 5: Configuration PHP5

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

Page 6: Configuration PHP5

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

Page 7: Configuration PHP5

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

Page 8: Configuration PHP5

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

Page 9: Configuration PHP5

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

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

Page 10: Configuration PHP5

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

Page 11: Configuration PHP5

Interdiction la traduction des variables POST et GET en variables PHP

register_globals = Off

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

Page 12: Configuration PHP5

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

Page 13: Configuration PHP5

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

Page 14: Configuration PHP5

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

Page 15: Configuration PHP5

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

Page 16: Configuration PHP5

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

Page 17: Configuration PHP5

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

Page 18: Configuration PHP5

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

Page 19: Configuration PHP5

Commenter toutes lignes LoadModule

Exemple: mod_proxy

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

Page 20: Configuration PHP5

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

Page 21: Configuration PHP5

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

Page 22: Configuration PHP5

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

◦ Disallow: /admin/*

◦ Disallow: /images/*

◦ Disallow: /videos/*

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

Page 23: Configuration PHP5

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

Page 24: Configuration PHP5

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

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

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

Page 25: Configuration PHP5

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

Page 26: Configuration PHP5

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

Page 27: Configuration PHP5

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

Page 28: Configuration PHP5

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

◦ Formations, Conseil, Audit et mise en œuvre

[email protected]

Jean-Marie RENOUARD ◦ [email protected]

◦ Twitter: @jmrenouard

◦ http://www.jmrenouard.fr

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