SlideShare una empresa de Scribd logo
1 de 42
Apache pour développeur PHP




16 novembre 2009          ALTERWAY Apache pour développeur PHP   1
Hébergement                                             Conseil




                   Formation                                    Solutions




16/11/09                             ALTER WAY GROUP                          2


16 novembre 2009           ALTERWAY - Apache pour développeur PHP             2
Who is talking ?
 Julien Pauli
 Expert certifié PHP& Zend Framework
 Formateur – Consultant - groupe AlterWay

 "ZendFramework, bien développer en PHP" :
  Eyrolles
 Contributeur ZendFramework - PHP - Apache

 http://julien-pauli.developpez.com

 LAMP stack user



    16 novembre 2009    ALTERWAY - Apache pour développeur PHP   3
Ordre du jour
              A patchy server : historique
                      1995 à nos jours

              Modules Apache
                      Fonctionnement interne

              Liaisons PHP et Apache
                      CGI - mod_php - others

              Apache-PHP et HTTP

              Apache en puissance
                      Autorisations, compressions, cache ...

16 novembre 2009              ALTERWAY - Apache pour développeur PHP   4
Sondage
 Qui utilise Apache ?

 Depuis combien de temps ?
        depuis toujours ?
        depuis peu ?

 Quelle version ?
        1.x
        2.x

 Utilisez-vous un autre serveur Web ?



       16 novembre 2009   ALTERWAY - Apache pour développeur PHP   5
Non, pas pour aujourd'hui :




               Apache !=




16 novembre 2009        ALTERWAY - Apache pour développeur PHP   6
Apache, c'est quoi ?




16 novembre 2009      ALTERWAY - Apache pour développeur PHP   7
Apache, c'est avant tout...
 Le nom d'une fondation, l'ASF
 Apache Software Foundation : équivalent "association" en France

         Investisseurs privés (Google, Microsoft, IBM)
         But non lucratif
         ~300 membres (contributeurs)
         Fondée en 1999 (10ans)
 Une licence : Apache Licence
 Une adresse : http://www.apache.org/
 Des tonnes de projets :
        HTTPD, couchdb, tomcat, geronimo, jakarta, struts,
         spamassassin,

       16 novembre 2009          ALTERWAY - Apache pour développeur PHP   8
Historique du web



 1990, Sir Tim Berners Lee invente le www
      http://info.cern.ch/default-fr.html

 1993, premier serveur Web : NCSA httpd
      http://hoohoo.ncsa.illinois.edu/docs/info/Features.html

 1995 : Apache 1 : fork de NCSA httpd
      "A Patchy httpd Server" : une suite de patchs sur NCSA
       httpd



  16 novembre 2009     ALTERWAY - Apache pour développeur PHP   9
Historique Apache
 1995 : Apache 1
     Bases : fonctionnement très proche d'UNIX

 2003 : Apache 2
     Cross-Platform (Multi Processing Modules)
     Apache Portable Runtime (APR, APR-Util)
     IPV6 et support des threads Linux

 2005 : Apache 2.2
     Supports de bases de données
     Amélioration du cache et de l'authentification
     Filtres
     Proxy et proxy load balancing

   16 novembre 2009     ALTERWAY - Apache pour développeur PHP   10
Ouvrons le capot




16 novembre 2009     ALTERWAY - Apache pour développeur PHP   11
Une structure modulaire
 Un core (écrit en C)
      mod_core , mpm, http_core ...


 Des modules d'extension (écrits en C)
      mod_rewrite, mod_deflate, .... mod_php
      Compilables statiquement ou dynamiquement (mod_so)



 Très fléxible
 Beaucoup de modules dans la nature (~600 ,
  probablement plus)
      http://modules.apache.org/search.php?query=true


   16 novembre 2009        ALTERWAY - Apache pour développeur PHP   12
Fonctionnement d'Apache
 Les modules sont connectés via des "hooks"
  (évènements)
      PHP est générateur de contenu
                                 Mapping URI vers fichier sur le disque

                                             Authentification

                                             Permissions

                                             Type du fichier

                                             Traitement (génération de contenu)

                                             Réponse au client

                                             Stockage des erreurs (log)

   16 novembre 2009        ALTERWAY - Apache pour développeur PHP         13
Lier PHP et Apache




16 novembre 2009      ALTERWAY - Apache pour développeur PHP   14
Liaison Apache - PHP
 Différentes liaisons :
        module : mod_php
          – Cas le plus courant
          – liaison forte (crashs, droits)
        CGI
          – Peu performant à haute charge
          – Indépendant d'Apache (crashs)
          – Tourne avec ses droits
       FastCGI
         – CGI : donc même spécifications
         – Mais FastCGI gère un pool de processus et une file
           d'attente
              Bien plus performant que CGI
       Autre module - per_user, itk, suexec, suphp
       16 novembre 2009       ALTERWAY - Apache pour développeur PHP   15
Liaison Apache - PHP : module
 mod_php
          Fournit un handler (générateur de contenu) à Apache
          Définit des directives

php_value              Définit une valeur de php.ini
php_admin_value        Définit une valeur de php.ini (hors .htaccess)
php_flag               Définit une valeur bool. de php.ini
php_admin_flag         Définit une valeur bool. de php.ini (hors .htaccess)
PHPINIDir              Localise le fichier php.ini à utiliser


          Définit des types MIMEs reconnus par le handler

                       application/x-httpd-php
                       application/x-httpd-php-source
                       text/html
    16 novembre 2009         ALTERWAY - Apache pour développeur PHP       16
mod_php : activation
 Chargement module PHP via mod_so

             LoadModule php5_module modules/libphp5.so


 Déclenchement du gestionnaire PHP

   AddType application/x-httpd-php .php                             Forçage du type (1)

                      OU

   <FilesMatch .php$>
      SetHandler application/x-httpd-php                      Déclenchement du handler
   </FilesMatch>



   16 novembre 2009        ALTERWAY - Apache pour développeur PHP                     17
PHPInfo() nous informe




16 novembre 2009        ALTERWAY - Apache pour développeur PHP   18
PHP en module, c'est aussi :
 Des directives dans php.ini

                           engine
                           child_terminate
                           last_modified
                           xbithack

 Et des fonctions PHP parfois bien utiles

                      apache_getenv()
                      apache_request_headers()
                      apache_response_headers()
                      apache_lookup_uri()
                      ...



   16 novembre 2009         ALTERWAY - Apache pour développeur PHP   19
PHP en CGI
 Un process PHP est crée par requête
         Peut vite devenir pénalisant
         Le CGI tourne avec les droits apache (suExec évite celà)

                   php53-src> ./configure
Compilation
                   php52-src> ./configure --enable-force-cgi-redirect
                                          --enable-discard-path

                   ScriptAlias /cgi
                   path/to/php/cgi
      Activation   <Directory /var/www>
                     addHandler php .php
                     Action php /cgi/php-cgi
                   </Directory>
16 novembre 2009        ALTERWAY - Apache pour développeur PHP      20
PHP en CGI




16 novembre 2009   ALTERWAY - Apache pour développeur PHP   21
PHP en FastCGI
 Pas de support natif de FCGI sur Apache 2.2 jusqu'à
  septembre 2009
 mod_fastcgi ou mod_fcgid existent
      mod_fcgid plus récent et plus performant
      mod_fcgid intégré dans Apache 2.3 (à venir)
        – http://httpd.apache.org/mod_fcgid

 Process PHP détachés d'Apache
      Connexions persistantes plus efficaces
      Isolation mémoire (crashs)
   Communication par sockets
 Contrôle fin sur la création des process
 PHP-FPM (http://php-fpm.org)

       16 novembre 2009    ALTERWAY - Apache pour développeur PHP   22
PHP en FastCGI : configuration
                       LoadModule fcgid_module modules/mod_fcgid.so
                       addHandler fcgid-script .php
   httpd.conf          MaxRequestsPerProcess 10000
                       <Directory /var/www>
                         Options ExecCGI
                         FcgiWrapper /usr/local/bin/php-fcgiwrapper
                       </Directory>


                       #!/bin/sh
 php-fcgiwrapper       PHP_FCGI_MAX_REQUESTS=10000
                       export PHP_FCGI_MAX_REQUESTS
                       exec /usr/local/bin/php-cgi

 <php-sources>/sapi/cgi/README.FastCGI
 http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html

    16 novembre 2009   ALTERWAY - Apache pour développeur PHP   23
Au secours, j'ai perdu mon php.ini !




16 novembre 2009   ALTERWAY - Apache pour développeur PHP   24
Spécifier manuellement php.ini
 via mod_php : PHPIniDir

             LoadModule php5_module modules/libphp5.so
             PHPIniDir /etc/php5/apache/php.ini
 CGI : variable d'environnement PHPRC
                                                                                    myphpcgi
         ScriptAlias /cgi /usr/bin/php/                         #!/bin/sh
         <Directory /var/www>                                   export PHPRC=/etc/php5/cgi
           addHandler php .php                                  exec /usr/bin/php/php-cgi
           Action php /cgi/myphpcgi
         </Directory>
 CGI : option de lancement "-c"
                                                              myphpcgi
                      #!/bin/sh
                      exec /usr/bin/php/php-cgi -c /etc/php5/cgi/php.ini

 CGI : variable env. sapi PHP_INI_SCAN_DIR (PHP>=5.2.7)
   16 novembre 2009              ALTERWAY - Apache pour développeur PHP               25
php.ini par défaut
 Si rien n'est précisé, la recherche s'effectue dans cet ordre :


    1. Le dossier du binaire Apache (httpd)
    2. Le DocumentRoot /!
    3. Windows : Le registre puis le PATH système
    4. le dossier renseigné via l'option de configuration
       --with-config-file-path ou --with-config-file-scan-dir



    Il n'est pas conseillé de laisser le système choisir le php.ini
    PHP sait démarrer sans aucun fichier php.ini
    --with-config-file-scan-dir pratique pour éclater sa conf
    php.ini actuellement utilisé ? => php_ini_loaded_file() (PHP 5.2.4)

       16 novembre 2009     ALTERWAY - Apache pour développeur PHP   26
Développer en PHP avec Apache
                tous les jours




16 novembre 2009   ALTERWAY - Apache pour développeur PHP   27
HTTP
 GET
     Récupération d'une ressource (cachable)
 POST
     Création ou maj. d'une ressource via un script de traitement
 PUT
     Dépôt de données brutes, création ou mise à jour d'une ressource
 DELETE (coule de source)
 OPTIONS
     Liste des méthodes supportées par le serveur web
 TRACE
   Traçage d'informations (rebonds de proxies)
 HEAD
     Informations sur une ressource
      16 novembre 2009    ALTERWAY - Apache pour développeur PHP   28
Apache et HTTP
 Apache sait tout gérer nativement sauf DELETE

               OPTIONS / HTTP/1.1
               Host: localhost

               HTTP/1.1 200 OK
               Date: Fri, 18 Sep 2009 19:50:25 GMT
               Server: Apache/2.2.13 (Unix) PHP/5.2.11
               Allow: GET,HEAD,POST,OPTIONS,TRACE,PUT
               Content-Length: 0
               Content-Type: httpd/unix-directory


 Apache reconnaît PUT
     Mais a besoin d'aide pour l'utiliser
     Traitement via programme externe (PHP ?)

      16 novembre 2009       ALTERWAY - Apache pour développeur PHP   29
Apache : méthode PUT
 Script => activer la méthode PUT (entre autre...)

                           Script PUT /put.php


                                                         put.php
 <?php
 $file = basename($_SERVER['PATH_TRANSLATED']);
 $code = file_exists($file) ? 204 : 201;
 $uri = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PATH_INFO'];

 $return = file_put_contents($file, file_get_contents("php://input"));
 $header = $return === false ? null : "Location: $url";

 header($header, true, $code);



    16 novembre 2009       ALTERWAY - Apache pour développeur PHP        30
Apache : méthode PUT

                           Script PUT /put.php




PUT /foo HTTP/1.1                          HTTP/1.1 201 Created
host: afup                                 Date: Fri, 18 Sep 2009 20:09:48 GMT
Content-type: text/plain                   Server: Apache/2.2.13 (Unix) PHP/5.2.11
Content-Lenght: 14                         X-Powered-By: PHP/5.2.11
                                           Location: http://afup/foo
hello from foo




   16 novembre 2009        ALTERWAY - Apache pour développeur PHP          31
Apache : Limit
 <Limit> : limite l'accès par méthodes HTTP
 Concerne GET(HEAD), POST, PUT, DELETE, OPTIONS
 Pour TRACE => TraceEnable


  DocumentRoot /var/www                          POST /some/path/file.txt HTTP/1.1
  <Directory /var/www>                           Host: afup
    <Limit POST PUT>
         order allow,deny
         Deny from all
    </Limit>
    Order allow, deny
    Allow from all
  </Directory>                                           HTTP/1.1 403 Forbidden



   16 novembre 2009     ALTERWAY - Apache pour développeur PHP                32
Apache : .htaccess




   .htaccess, tout le monde connait
   Permet d'ajouter des directives à la volée, par répertoire
   Peut être renommé (directive AccessFileName)
   Ralentit Apache !




    16 novembre 2009     ALTERWAY - Apache pour développeur PHP   33
.htaccess autorisé ?
 AllowOverride ->directives que .htaccess sera autorisé à modifier
 N'est valide que dans un conteneur <Directory>


 <Directory />
   AllowOverride none           ignore .htaccess dans tous les dossiers
 </Directory>                Autorise .htaccess dans le dossier /var/www
                         Il ne pourra rajouter que des options pour les droits
 <Directory /var/www>
   AllowOverride limit
 </Directory>


 Par défaut AllowOverride = All
 Enlever AllowOverride sur / -> économies de ressources (défaut)
 Il est toujours mieux de ne pas utiliser .htaccess

    16 novembre 2009       ALTERWAY - Apache pour développeur PHP       34
PHP ou Apache ?
      PHP
              Générer du contenu (sic!)
              Gérer les en-têtes de ce contenu
      Apache
                  Gérer HTTP
                  Gérer les couches basses (TCP, processus)
                  Gérer ... ce que PHP ne gère pas

                     Mapping URI vers fichier sur le disque
                     Authentification
                     Permissions
                     Type du fichier
                     Génération de contenu (PHP)
                     Réponse au client
                     Stockage des erreurs (log)

16 novembre 2009              ALTERWAY - Apache pour développeur PHP   35
Apache : quelques exemples
 Touche pas à mes images !

SetEnvIfNoCase Referer "^http://mysite.com/" good
SetEnvIfNoCase Referer "^$" good
SetEnvIfNoCase ^User-Agent$ .*(badbot|spider|attacker) !good

<FilesMatch ".(png|jpg|jpeg|gif|bmp|swf|flv)$">
Order Deny,Allow
Deny from all
Allow from env=good
ErrorDocument 403 "Voleur de bande passante"
</FilesMatch>

 Proposer la boite de dialogue "sauver sous" :

AddType application/octet-stream .pdf .avi .mp4

16 novembre 2009      ALTERWAY - Apache pour développeur PHP   36
Autorisations
 Autorise certaines IP, identification (RFC2617)
 "Ce site est en construction" :

                   <Directory /var/www>
                   AuthType basic
                   AuthName "Ce site est en construction"
                   AuthUserFile /.htpasswd
                   Require valid-user

                   Order Deny,Allow
                   Deny from all
                   Allow from 1.2.3.4/16 // mon parc
                   Allow from googlebot.com // Google vient

                   Satisfy Any
                   </Directory>
16 novembre 2009                  ALTERWAY - Apache pour développeur PHP   37
Apache : gestion du cache
 mod_expires sait envoyer les en-têtes de cache
 HTTP ?: http://julien-pauli.developpez.com/tutoriels/web/http/
 mod_headers : contrôle manuel des en-têtes
ExpiresActive On                                                     GET /page HTTP/1.1
ExpiresByType image/* "access plus 1 month"                          Host: afup
ExpireDefault "modification plus 2 hours"

                                     HTTP/1.x 200 OK
                                     Date: Fri, 18 Sep 2009 18:44:18 GMT
                                     Server: Apache/2.2.13 (Unix) PHP/5.2.11
                                     Cache-Control: max-age=7200
                                     Expires: Sat, 19 Sep 2009 18:44:18 GMT
                                     Content-Length: 0
                                     Content-Type: text/html; charset=ISO-8859-1
                                     Content-Language: fr

   16 novembre 2009         ALTERWAY - Apache pour développeur PHP                 38
Apache : gestion du cache
 ExpireDefault concerne aussi le contenu servi par PHP
 sessions PHP? cache invalidé
      Réglages dans php.ini ou avec session_cache_limiter()


                           HTTP/1.x 200 OK
                           Date: Fri, 18 Sep 2009 18:48:13 GMT
                           Server: Apache/2.2.13 (Unix) PHP/5.2.11
<?php                      Expires: Thu, 19 Nov 1981 08:52:00 GMT
session_start()            Cache-Control: no-store, no-cache, must-
                                        revalidate, post-check=0, pre-check=0
                           Pragma: no-cache
                           Content-Length: 3
                           Content-Type: text/html; charset=ISO-8859-1
                           Content-Language: fr



   16 novembre 2009         ALTERWAY - Apache pour développeur PHP     39
Apache : compression
 mod_deflate
      Compresse / décompresse à la volée

 Economisez de la bande passante / du temps de transfert


               AddOutputFilterByType DEFLATE text/* image/*




   16 novembre 2009          ALTERWAY - Apache pour développeur PHP   40
Les modules "exotiques"
 mod_bw
   Limitez la bande passante (dans les 2 sens)
 mod_jsmin
   Minifiez vos js ou css à la volée avec un cache
 mod_tidy
   Nettoyez votre (x)Html à la volée en sortie
 mod_concat
   1 seule requête qui concatène le résultat de X requêtes
 mod_qos - mod_slotlimit
   Contrôler finement la qualité de service
 mod_hitlog
      Ajoutez un contenu à toutes vos pages ("include")


    16 novembre 2009        ALTERWAY - Apache pour développeur PHP   41
Merci,


                      Question ?




 http://julien-pauli.developpez.com
   16 novembre 2009   ALTERWAY - Apache pour développeur PHP   42

Más contenido relacionado

La actualidad más candente

Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009Philippe Gamache
 
Gestion des dépendances dans un projet PHP - RMLL 2012
Gestion des dépendances dans un projet PHP - RMLL 2012Gestion des dépendances dans un projet PHP - RMLL 2012
Gestion des dépendances dans un projet PHP - RMLL 2012Jean-Marc Fontaine
 
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)Fabien Potencier
 
Audit openERP 7.0: Mise en place &Optimisation de Performances
Audit openERP 7.0: Mise en place &Optimisation de Performances Audit openERP 7.0: Mise en place &Optimisation de Performances
Audit openERP 7.0: Mise en place &Optimisation de Performances Firas Kouẞàa
 
symfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les Professionnelssymfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les ProfessionnelsFabien Potencier
 
PHP Composer : Pourquoi ? Comment ? Et plus ...
PHP Composer : Pourquoi ? Comment ? Et plus ...PHP Composer : Pourquoi ? Comment ? Et plus ...
PHP Composer : Pourquoi ? Comment ? Et plus ...Romain Cambien
 
Installation de PHP
Installation de PHPInstallation de PHP
Installation de PHPMoncef Essid
 
Installation configuration OpenERP 7 - Windows
Installation   configuration OpenERP 7 - WindowsInstallation   configuration OpenERP 7 - Windows
Installation configuration OpenERP 7 - WindowsSanae BEKKAR
 
Symfony2 Presentation
Symfony2 PresentationSymfony2 Presentation
Symfony2 Presentationyllieth
 
Introduction à eZ Publish Platform 5.3
Introduction à eZ Publish Platform 5.3 Introduction à eZ Publish Platform 5.3
Introduction à eZ Publish Platform 5.3 Roland Benedetti
 
wallabag, comment on a migré vers symfony3
wallabag, comment on a migré vers symfony3wallabag, comment on a migré vers symfony3
wallabag, comment on a migré vers symfony3Nicolas Lœuillet
 
Conference drupal 8 au Forum PHP 2013 à Paris
Conference drupal 8 au Forum PHP 2013 à ParisConference drupal 8 au Forum PHP 2013 à Paris
Conference drupal 8 au Forum PHP 2013 à ParisChipway
 
Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014Ippon
 
Formation html5 CSS3 offerte par ippon 2014
Formation html5 CSS3 offerte par ippon 2014Formation html5 CSS3 offerte par ippon 2014
Formation html5 CSS3 offerte par ippon 2014Ippon
 
AFUP Aix/Marseille - 16 mai 2017 - Open API
AFUP Aix/Marseille - 16 mai 2017 - Open APIAFUP Aix/Marseille - 16 mai 2017 - Open API
AFUP Aix/Marseille - 16 mai 2017 - Open APIRomain Cambien
 
Presentation du framework symfony
Presentation du framework symfonyPresentation du framework symfony
Presentation du framework symfonyJeremy Gachet
 

La actualidad más candente (20)

Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009Une application en deux heure - PHP Québec Janvier 2009
Une application en deux heure - PHP Québec Janvier 2009
 
Gestion des dépendances dans un projet PHP - RMLL 2012
Gestion des dépendances dans un projet PHP - RMLL 2012Gestion des dépendances dans un projet PHP - RMLL 2012
Gestion des dépendances dans un projet PHP - RMLL 2012
 
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)
 
Symfony Best Practices
Symfony Best PracticesSymfony Best Practices
Symfony Best Practices
 
Audit openERP 7.0: Mise en place &Optimisation de Performances
Audit openERP 7.0: Mise en place &Optimisation de Performances Audit openERP 7.0: Mise en place &Optimisation de Performances
Audit openERP 7.0: Mise en place &Optimisation de Performances
 
Lp web tp3_idse
Lp web tp3_idseLp web tp3_idse
Lp web tp3_idse
 
symfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les Professionnelssymfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les Professionnels
 
PHP Composer : Pourquoi ? Comment ? Et plus ...
PHP Composer : Pourquoi ? Comment ? Et plus ...PHP Composer : Pourquoi ? Comment ? Et plus ...
PHP Composer : Pourquoi ? Comment ? Et plus ...
 
Php
PhpPhp
Php
 
Installation de PHP
Installation de PHPInstallation de PHP
Installation de PHP
 
Installation configuration OpenERP 7 - Windows
Installation   configuration OpenERP 7 - WindowsInstallation   configuration OpenERP 7 - Windows
Installation configuration OpenERP 7 - Windows
 
Symfony2 Presentation
Symfony2 PresentationSymfony2 Presentation
Symfony2 Presentation
 
Introduction à eZ Publish Platform 5.3
Introduction à eZ Publish Platform 5.3 Introduction à eZ Publish Platform 5.3
Introduction à eZ Publish Platform 5.3
 
wallabag, comment on a migré vers symfony3
wallabag, comment on a migré vers symfony3wallabag, comment on a migré vers symfony3
wallabag, comment on a migré vers symfony3
 
Conference drupal 8 au Forum PHP 2013 à Paris
Conference drupal 8 au Forum PHP 2013 à ParisConference drupal 8 au Forum PHP 2013 à Paris
Conference drupal 8 au Forum PHP 2013 à Paris
 
Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014
 
Formation html5 CSS3 offerte par ippon 2014
Formation html5 CSS3 offerte par ippon 2014Formation html5 CSS3 offerte par ippon 2014
Formation html5 CSS3 offerte par ippon 2014
 
AFUP Aix/Marseille - 16 mai 2017 - Open API
AFUP Aix/Marseille - 16 mai 2017 - Open APIAFUP Aix/Marseille - 16 mai 2017 - Open API
AFUP Aix/Marseille - 16 mai 2017 - Open API
 
Installation open erp
Installation open erpInstallation open erp
Installation open erp
 
Presentation du framework symfony
Presentation du framework symfonyPresentation du framework symfony
Presentation du framework symfony
 

Similar a Apache for développeurs PHP

hassclic270.ppt
hassclic270.ppthassclic270.ppt
hassclic270.pptadiouf2
 
08 01 mise en place d'un serveur web
08 01 mise en place d'un serveur web08 01 mise en place d'un serveur web
08 01 mise en place d'un serveur webNoël
 
cours-gratuit.com--coursMySql-id2218.pdf
cours-gratuit.com--coursMySql-id2218.pdfcours-gratuit.com--coursMySql-id2218.pdf
cours-gratuit.com--coursMySql-id2218.pdfGroupeExcelMarrakech
 
Communications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPCommunications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPjulien pauli
 
Mysql Apche PHP sous linux
Mysql Apche PHP sous linuxMysql Apche PHP sous linux
Mysql Apche PHP sous linuxKhalid ALLILI
 
Alphorm.com Formation Apache - Le Guide Complet de l'administrateur
Alphorm.com Formation Apache - Le Guide Complet de l'administrateurAlphorm.com Formation Apache - Le Guide Complet de l'administrateur
Alphorm.com Formation Apache - Le Guide Complet de l'administrateurAlphorm
 
Mieux Développer en PHP avec Symfony
Mieux Développer en PHP avec SymfonyMieux Développer en PHP avec Symfony
Mieux Développer en PHP avec SymfonyHugo Hamon
 
Cours IEF - Présentation de PHP
Cours IEF - Présentation de PHPCours IEF - Présentation de PHP
Cours IEF - Présentation de PHPRégis Lutter
 
Introduction à Symfony2
Introduction à Symfony2Introduction à Symfony2
Introduction à Symfony2Hugo Hamon
 
Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]Wixiweb
 
Presentation Symfony2
Presentation Symfony2Presentation Symfony2
Presentation Symfony2Ahmed ABATAL
 
Apache server configuration & sécurisation -
Apache server configuration & sécurisation  -Apache server configuration & sécurisation  -
Apache server configuration & sécurisation -achraf_ing
 
Optimiser les performances dans Wordpress
Optimiser les performances dans WordpressOptimiser les performances dans Wordpress
Optimiser les performances dans WordpressNicolas Juen
 
Puppet, la philosophie DevOps
Puppet, la philosophie DevOpsPuppet, la philosophie DevOps
Puppet, la philosophie DevOpsJeoffrey Bauvin
 
Partie 1_Matriser les bases PHP v0555555555555.pptx
Partie 1_Matriser les bases PHP v0555555555555.pptxPartie 1_Matriser les bases PHP v0555555555555.pptx
Partie 1_Matriser les bases PHP v0555555555555.pptxHamzaElgari
 
Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Les-Tilleuls.coop
 

Similar a Apache for développeurs PHP (20)

hassclic270.ppt
hassclic270.ppthassclic270.ppt
hassclic270.ppt
 
08 01 mise en place d'un serveur web
08 01 mise en place d'un serveur web08 01 mise en place d'un serveur web
08 01 mise en place d'un serveur web
 
cours-gratuit.com--coursMySql-id2218.pdf
cours-gratuit.com--coursMySql-id2218.pdfcours-gratuit.com--coursMySql-id2218.pdf
cours-gratuit.com--coursMySql-id2218.pdf
 
Communications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPCommunications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHP
 
Mysql Apche PHP sous linux
Mysql Apche PHP sous linuxMysql Apche PHP sous linux
Mysql Apche PHP sous linux
 
Alphorm.com Formation Apache - Le Guide Complet de l'administrateur
Alphorm.com Formation Apache - Le Guide Complet de l'administrateurAlphorm.com Formation Apache - Le Guide Complet de l'administrateur
Alphorm.com Formation Apache - Le Guide Complet de l'administrateur
 
Mieux Développer en PHP avec Symfony
Mieux Développer en PHP avec SymfonyMieux Développer en PHP avec Symfony
Mieux Développer en PHP avec Symfony
 
Cours IEF - Présentation de PHP
Cours IEF - Présentation de PHPCours IEF - Présentation de PHP
Cours IEF - Présentation de PHP
 
Introduction à Symfony2
Introduction à Symfony2Introduction à Symfony2
Introduction à Symfony2
 
Apache Open SSL
Apache Open SSLApache Open SSL
Apache Open SSL
 
Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]Présentation de PHP 5.4 [FR]
Présentation de PHP 5.4 [FR]
 
Presentation Symfony2
Presentation Symfony2Presentation Symfony2
Presentation Symfony2
 
43_pps.pdf
43_pps.pdf43_pps.pdf
43_pps.pdf
 
Apache server configuration & sécurisation -
Apache server configuration & sécurisation  -Apache server configuration & sécurisation  -
Apache server configuration & sécurisation -
 
Optimiser les performances dans Wordpress
Optimiser les performances dans WordpressOptimiser les performances dans Wordpress
Optimiser les performances dans Wordpress
 
Puppet, la philosophie DevOps
Puppet, la philosophie DevOpsPuppet, la philosophie DevOps
Puppet, la philosophie DevOps
 
Mysql
MysqlMysql
Mysql
 
Partie 1_Matriser les bases PHP v0555555555555.pptx
Partie 1_Matriser les bases PHP v0555555555555.pptxPartie 1_Matriser les bases PHP v0555555555555.pptx
Partie 1_Matriser les bases PHP v0555555555555.pptx
 
Présentation de PHP
Présentation de PHPPrésentation de PHP
Présentation de PHP
 
Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014
 

Más de julien pauli

Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019julien pauli
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension reviewjulien pauli
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machinejulien pauli
 
Basics of Cryptography - Stream ciphers and PRNG
Basics of Cryptography - Stream ciphers and PRNGBasics of Cryptography - Stream ciphers and PRNG
Basics of Cryptography - Stream ciphers and PRNGjulien pauli
 
Mastering your home network - Do It Yourself
Mastering your home network - Do It YourselfMastering your home network - Do It Yourself
Mastering your home network - Do It Yourselfjulien pauli
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesjulien pauli
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTSjulien pauli
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performancesjulien pauli
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshopjulien pauli
 
Profiling php5 to php7
Profiling php5 to php7Profiling php5 to php7
Profiling php5 to php7julien pauli
 
PHP 7 performances from PHP 5
PHP 7 performances from PHP 5PHP 7 performances from PHP 5
PHP 7 performances from PHP 5julien pauli
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionjulien pauli
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshopjulien pauli
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objectsjulien pauli
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13julien pauli
 

Más de julien pauli (20)

Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019
 
Php engine
Php enginePhp engine
Php engine
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension review
 
Dns
DnsDns
Dns
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machine
 
Basics of Cryptography - Stream ciphers and PRNG
Basics of Cryptography - Stream ciphers and PRNGBasics of Cryptography - Stream ciphers and PRNG
Basics of Cryptography - Stream ciphers and PRNG
 
Mastering your home network - Do It Yourself
Mastering your home network - Do It YourselfMastering your home network - Do It Yourself
Mastering your home network - Do It Yourself
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performances
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTS
 
Tcpip
TcpipTcpip
Tcpip
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performances
 
PHP 7 new engine
PHP 7 new enginePHP 7 new engine
PHP 7 new engine
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshop
 
Profiling php5 to php7
Profiling php5 to php7Profiling php5 to php7
Profiling php5 to php7
 
PHP 7 performances from PHP 5
PHP 7 performances from PHP 5PHP 7 performances from PHP 5
PHP 7 performances from PHP 5
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshop
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objects
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
 

Apache for développeurs PHP

  • 1. Apache pour développeur PHP 16 novembre 2009 ALTERWAY Apache pour développeur PHP 1
  • 2. Hébergement Conseil Formation Solutions 16/11/09 ALTER WAY GROUP 2 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 2
  • 3. Who is talking ?  Julien Pauli  Expert certifié PHP& Zend Framework  Formateur – Consultant - groupe AlterWay  "ZendFramework, bien développer en PHP" : Eyrolles  Contributeur ZendFramework - PHP - Apache  http://julien-pauli.developpez.com  LAMP stack user 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 3
  • 4. Ordre du jour  A patchy server : historique  1995 à nos jours  Modules Apache  Fonctionnement interne  Liaisons PHP et Apache  CGI - mod_php - others  Apache-PHP et HTTP  Apache en puissance  Autorisations, compressions, cache ... 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 4
  • 5. Sondage  Qui utilise Apache ?  Depuis combien de temps ?  depuis toujours ?  depuis peu ?  Quelle version ?  1.x  2.x  Utilisez-vous un autre serveur Web ? 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 5
  • 6. Non, pas pour aujourd'hui :  Apache != 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 6
  • 7. Apache, c'est quoi ? 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 7
  • 8. Apache, c'est avant tout...  Le nom d'une fondation, l'ASF  Apache Software Foundation : équivalent "association" en France  Investisseurs privés (Google, Microsoft, IBM)  But non lucratif  ~300 membres (contributeurs)  Fondée en 1999 (10ans)  Une licence : Apache Licence  Une adresse : http://www.apache.org/  Des tonnes de projets :  HTTPD, couchdb, tomcat, geronimo, jakarta, struts, spamassassin, 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 8
  • 9. Historique du web  1990, Sir Tim Berners Lee invente le www  http://info.cern.ch/default-fr.html  1993, premier serveur Web : NCSA httpd  http://hoohoo.ncsa.illinois.edu/docs/info/Features.html  1995 : Apache 1 : fork de NCSA httpd  "A Patchy httpd Server" : une suite de patchs sur NCSA httpd 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 9
  • 10. Historique Apache  1995 : Apache 1  Bases : fonctionnement très proche d'UNIX  2003 : Apache 2  Cross-Platform (Multi Processing Modules)  Apache Portable Runtime (APR, APR-Util)  IPV6 et support des threads Linux  2005 : Apache 2.2  Supports de bases de données  Amélioration du cache et de l'authentification  Filtres  Proxy et proxy load balancing 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 10
  • 11. Ouvrons le capot 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 11
  • 12. Une structure modulaire  Un core (écrit en C)  mod_core , mpm, http_core ...  Des modules d'extension (écrits en C)  mod_rewrite, mod_deflate, .... mod_php  Compilables statiquement ou dynamiquement (mod_so)  Très fléxible  Beaucoup de modules dans la nature (~600 , probablement plus)  http://modules.apache.org/search.php?query=true 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 12
  • 13. Fonctionnement d'Apache  Les modules sont connectés via des "hooks" (évènements)  PHP est générateur de contenu Mapping URI vers fichier sur le disque Authentification Permissions Type du fichier Traitement (génération de contenu) Réponse au client Stockage des erreurs (log) 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 13
  • 14. Lier PHP et Apache 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 14
  • 15. Liaison Apache - PHP  Différentes liaisons :  module : mod_php – Cas le plus courant – liaison forte (crashs, droits)  CGI – Peu performant à haute charge – Indépendant d'Apache (crashs) – Tourne avec ses droits  FastCGI – CGI : donc même spécifications – Mais FastCGI gère un pool de processus et une file d'attente  Bien plus performant que CGI  Autre module - per_user, itk, suexec, suphp 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 15
  • 16. Liaison Apache - PHP : module  mod_php  Fournit un handler (générateur de contenu) à Apache  Définit des directives php_value Définit une valeur de php.ini php_admin_value Définit une valeur de php.ini (hors .htaccess) php_flag Définit une valeur bool. de php.ini php_admin_flag Définit une valeur bool. de php.ini (hors .htaccess) PHPINIDir Localise le fichier php.ini à utiliser  Définit des types MIMEs reconnus par le handler application/x-httpd-php application/x-httpd-php-source text/html 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 16
  • 17. mod_php : activation  Chargement module PHP via mod_so LoadModule php5_module modules/libphp5.so  Déclenchement du gestionnaire PHP AddType application/x-httpd-php .php Forçage du type (1) OU <FilesMatch .php$> SetHandler application/x-httpd-php Déclenchement du handler </FilesMatch> 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 17
  • 18. PHPInfo() nous informe 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 18
  • 19. PHP en module, c'est aussi :  Des directives dans php.ini engine child_terminate last_modified xbithack  Et des fonctions PHP parfois bien utiles apache_getenv() apache_request_headers() apache_response_headers() apache_lookup_uri() ... 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 19
  • 20. PHP en CGI  Un process PHP est crée par requête  Peut vite devenir pénalisant  Le CGI tourne avec les droits apache (suExec évite celà) php53-src> ./configure Compilation php52-src> ./configure --enable-force-cgi-redirect --enable-discard-path ScriptAlias /cgi path/to/php/cgi Activation <Directory /var/www> addHandler php .php Action php /cgi/php-cgi </Directory> 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 20
  • 21. PHP en CGI 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 21
  • 22. PHP en FastCGI  Pas de support natif de FCGI sur Apache 2.2 jusqu'à septembre 2009  mod_fastcgi ou mod_fcgid existent  mod_fcgid plus récent et plus performant  mod_fcgid intégré dans Apache 2.3 (à venir) – http://httpd.apache.org/mod_fcgid  Process PHP détachés d'Apache  Connexions persistantes plus efficaces  Isolation mémoire (crashs) Communication par sockets  Contrôle fin sur la création des process  PHP-FPM (http://php-fpm.org) 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 22
  • 23. PHP en FastCGI : configuration LoadModule fcgid_module modules/mod_fcgid.so addHandler fcgid-script .php httpd.conf MaxRequestsPerProcess 10000 <Directory /var/www> Options ExecCGI FcgiWrapper /usr/local/bin/php-fcgiwrapper </Directory> #!/bin/sh php-fcgiwrapper PHP_FCGI_MAX_REQUESTS=10000 export PHP_FCGI_MAX_REQUESTS exec /usr/local/bin/php-cgi  <php-sources>/sapi/cgi/README.FastCGI  http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 23
  • 24. Au secours, j'ai perdu mon php.ini ! 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 24
  • 25. Spécifier manuellement php.ini  via mod_php : PHPIniDir LoadModule php5_module modules/libphp5.so PHPIniDir /etc/php5/apache/php.ini  CGI : variable d'environnement PHPRC myphpcgi ScriptAlias /cgi /usr/bin/php/ #!/bin/sh <Directory /var/www> export PHPRC=/etc/php5/cgi addHandler php .php exec /usr/bin/php/php-cgi Action php /cgi/myphpcgi </Directory>  CGI : option de lancement "-c" myphpcgi #!/bin/sh exec /usr/bin/php/php-cgi -c /etc/php5/cgi/php.ini  CGI : variable env. sapi PHP_INI_SCAN_DIR (PHP>=5.2.7) 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 25
  • 26. php.ini par défaut  Si rien n'est précisé, la recherche s'effectue dans cet ordre : 1. Le dossier du binaire Apache (httpd) 2. Le DocumentRoot /! 3. Windows : Le registre puis le PATH système 4. le dossier renseigné via l'option de configuration --with-config-file-path ou --with-config-file-scan-dir  Il n'est pas conseillé de laisser le système choisir le php.ini  PHP sait démarrer sans aucun fichier php.ini  --with-config-file-scan-dir pratique pour éclater sa conf  php.ini actuellement utilisé ? => php_ini_loaded_file() (PHP 5.2.4) 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 26
  • 27. Développer en PHP avec Apache tous les jours 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 27
  • 28. HTTP  GET  Récupération d'une ressource (cachable)  POST  Création ou maj. d'une ressource via un script de traitement  PUT  Dépôt de données brutes, création ou mise à jour d'une ressource  DELETE (coule de source)  OPTIONS  Liste des méthodes supportées par le serveur web  TRACE  Traçage d'informations (rebonds de proxies)  HEAD  Informations sur une ressource 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 28
  • 29. Apache et HTTP  Apache sait tout gérer nativement sauf DELETE OPTIONS / HTTP/1.1 Host: localhost HTTP/1.1 200 OK Date: Fri, 18 Sep 2009 19:50:25 GMT Server: Apache/2.2.13 (Unix) PHP/5.2.11 Allow: GET,HEAD,POST,OPTIONS,TRACE,PUT Content-Length: 0 Content-Type: httpd/unix-directory  Apache reconnaît PUT  Mais a besoin d'aide pour l'utiliser  Traitement via programme externe (PHP ?) 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 29
  • 30. Apache : méthode PUT  Script => activer la méthode PUT (entre autre...) Script PUT /put.php put.php <?php $file = basename($_SERVER['PATH_TRANSLATED']); $code = file_exists($file) ? 204 : 201; $uri = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PATH_INFO']; $return = file_put_contents($file, file_get_contents("php://input")); $header = $return === false ? null : "Location: $url"; header($header, true, $code); 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 30
  • 31. Apache : méthode PUT Script PUT /put.php PUT /foo HTTP/1.1 HTTP/1.1 201 Created host: afup Date: Fri, 18 Sep 2009 20:09:48 GMT Content-type: text/plain Server: Apache/2.2.13 (Unix) PHP/5.2.11 Content-Lenght: 14 X-Powered-By: PHP/5.2.11 Location: http://afup/foo hello from foo 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 31
  • 32. Apache : Limit  <Limit> : limite l'accès par méthodes HTTP  Concerne GET(HEAD), POST, PUT, DELETE, OPTIONS  Pour TRACE => TraceEnable DocumentRoot /var/www POST /some/path/file.txt HTTP/1.1 <Directory /var/www> Host: afup <Limit POST PUT> order allow,deny Deny from all </Limit> Order allow, deny Allow from all </Directory> HTTP/1.1 403 Forbidden 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 32
  • 33. Apache : .htaccess  .htaccess, tout le monde connait  Permet d'ajouter des directives à la volée, par répertoire  Peut être renommé (directive AccessFileName)  Ralentit Apache ! 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 33
  • 34. .htaccess autorisé ?  AllowOverride ->directives que .htaccess sera autorisé à modifier  N'est valide que dans un conteneur <Directory> <Directory /> AllowOverride none ignore .htaccess dans tous les dossiers </Directory> Autorise .htaccess dans le dossier /var/www Il ne pourra rajouter que des options pour les droits <Directory /var/www> AllowOverride limit </Directory>  Par défaut AllowOverride = All  Enlever AllowOverride sur / -> économies de ressources (défaut)  Il est toujours mieux de ne pas utiliser .htaccess 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 34
  • 35. PHP ou Apache ?  PHP  Générer du contenu (sic!)  Gérer les en-têtes de ce contenu  Apache  Gérer HTTP  Gérer les couches basses (TCP, processus)  Gérer ... ce que PHP ne gère pas Mapping URI vers fichier sur le disque Authentification Permissions Type du fichier Génération de contenu (PHP) Réponse au client Stockage des erreurs (log) 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 35
  • 36. Apache : quelques exemples  Touche pas à mes images ! SetEnvIfNoCase Referer "^http://mysite.com/" good SetEnvIfNoCase Referer "^$" good SetEnvIfNoCase ^User-Agent$ .*(badbot|spider|attacker) !good <FilesMatch ".(png|jpg|jpeg|gif|bmp|swf|flv)$"> Order Deny,Allow Deny from all Allow from env=good ErrorDocument 403 "Voleur de bande passante" </FilesMatch>  Proposer la boite de dialogue "sauver sous" : AddType application/octet-stream .pdf .avi .mp4 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 36
  • 37. Autorisations  Autorise certaines IP, identification (RFC2617)  "Ce site est en construction" : <Directory /var/www> AuthType basic AuthName "Ce site est en construction" AuthUserFile /.htpasswd Require valid-user Order Deny,Allow Deny from all Allow from 1.2.3.4/16 // mon parc Allow from googlebot.com // Google vient Satisfy Any </Directory> 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 37
  • 38. Apache : gestion du cache  mod_expires sait envoyer les en-têtes de cache  HTTP ?: http://julien-pauli.developpez.com/tutoriels/web/http/  mod_headers : contrôle manuel des en-têtes ExpiresActive On GET /page HTTP/1.1 ExpiresByType image/* "access plus 1 month" Host: afup ExpireDefault "modification plus 2 hours" HTTP/1.x 200 OK Date: Fri, 18 Sep 2009 18:44:18 GMT Server: Apache/2.2.13 (Unix) PHP/5.2.11 Cache-Control: max-age=7200 Expires: Sat, 19 Sep 2009 18:44:18 GMT Content-Length: 0 Content-Type: text/html; charset=ISO-8859-1 Content-Language: fr 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 38
  • 39. Apache : gestion du cache  ExpireDefault concerne aussi le contenu servi par PHP  sessions PHP? cache invalidé  Réglages dans php.ini ou avec session_cache_limiter() HTTP/1.x 200 OK Date: Fri, 18 Sep 2009 18:48:13 GMT Server: Apache/2.2.13 (Unix) PHP/5.2.11 <?php Expires: Thu, 19 Nov 1981 08:52:00 GMT session_start() Cache-Control: no-store, no-cache, must- revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Length: 3 Content-Type: text/html; charset=ISO-8859-1 Content-Language: fr 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 39
  • 40. Apache : compression  mod_deflate  Compresse / décompresse à la volée  Economisez de la bande passante / du temps de transfert AddOutputFilterByType DEFLATE text/* image/* 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 40
  • 41. Les modules "exotiques"  mod_bw Limitez la bande passante (dans les 2 sens)  mod_jsmin Minifiez vos js ou css à la volée avec un cache  mod_tidy Nettoyez votre (x)Html à la volée en sortie  mod_concat 1 seule requête qui concatène le résultat de X requêtes  mod_qos - mod_slotlimit Contrôler finement la qualité de service  mod_hitlog  Ajoutez un contenu à toutes vos pages ("include") 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 41
  • 42. Merci, Question ?  http://julien-pauli.developpez.com 16 novembre 2009 ALTERWAY - Apache pour développeur PHP 42