Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Tuesday, December 29, 2009

Zend Framework avec lighthttpd

Je vais travailler sur un projet en PHP avec Zend Framework. Venant du monde Rails, on s'habitue assez vite à lancer son serveur web dans un terminal, voir plusieurs en parallèle sans avoir à manipuler la configuration d'un Apache qui tourne sous un autre compte utilisateur.

En PHP je n'ai pas trouvé d'équivalent à Webrick ou Mongrel intégré à ZF, mais je m'en suis finalement sorti avec lighthttpd.

A la racine du projet ZF, créez un lighthttpd.conf dans lequel vous configurez entre autres:
  • le port 3000 (on ne change pas de vieilles habitudes :)
  • l'URL rewriting pour que toutes les requêtes passent par index.php (l'équivalent du .htaccess tel que créé par ZF)
  • l'accès à votre application via FastCGI


ce qui donne quelque chose comme suit:


server.document-root = env.PWD + "/public"
server.port = 3000

server.modules = (
  "mod_rewrite",
  "mod_fastcgi"
)


mimetype.assign = (
  ".html" => "text/html", 
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png" 
)

url.rewrite-once = (
  ".*\?(.*)$" => "/index.php?$1",
  ".*\.(js|ico|gif|jpg|png|css)$" => "$0",
  "" => "/index.php"
)

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

server.indexfiles = ( "index.php" )

fastcgi.server = (
  ".php" =>
    ( "localhost" =>
      (
        "socket" => "/tmp/php-fastcgi.socket",
        "bin-path" => "/usr/bin/php-cgi"
      )
    )
)

Ensuite un petit script bash pour nous faciliter le lancement du serveur et l'initialisation de l'environnement ZF, par exemple start_zf.sh.

#!/bin/sh
export APPLICATION_ENV=development
lighttpd -f lighthttpd.conf -D

N'oubliez pas de rendre le script exécutable:
chmod +x start_zf.sh

puis lancez l'accès à votre projet ZF:

./start_zf.sh

Si tout va bien le site est accessible sur http://localhost:3000