Browse files

blogged about serving php files with yeoman

  • Loading branch information...
1 parent 4c2a87d commit 67aad1cb1e28694d6057647370dc84009b99e853 @fgnass committed Aug 30, 2012
Showing with 49 additions and 0 deletions.
  1. +43 −0 _posts/
  2. +6 −0 assets/default.css
  3. BIN assets/yeoman.jpg
  4. BIN assets/yeoman.mp4
@@ -0,0 +1,43 @@
+layout: post
+title: Serving PHP files with Yeoman
+I recently did some PHP development and thought it would be nice if I could use
+[Yeoman's]( built-in development server to serve dynamic files,
+The first step was to install `php-cgi` which isn't included with OS X.
+ brew tap homebrew/dupes
+ brew tap josegonzalez/homebrew-php
+ brew install php54
+<img src="/assets/yeoman.jpg" style="float:left;margin:0 10px 0 -10px; border:none">
+The next step was to add a middleware to Yeoman's server in order to invoke
+the PHP interpreter for all files ending with `.php`.
+I found the [node-cgi]( module that
+Nathan ([@TooTallNate]( had written to serve
+the GitWeb interface through Node, but unfortunately node-cgi only handles
+scripts with a shebang that are located in a `cgi-bin` directory.
+I needed a module that would serve scripts from arbitrary locations and
+choose the interpreter based on the file's extension. As it should also support
+welcome-files so I decided to [roll my own](
+While Yeoman was now able to serve PHP files, one important aspect was still
+missing: The server had to inject the liverelaad snippet into the response that
+was generated by the PHP interpreter.
+Hence I wrote a second middleware called
+[tamper]( What tamper does is that it
+temporarily overwrites the `write()`, `writeHead()` and `end()` methods of the
+ServerResponse object. Before the headers are sent to the client, tamper invokes
+a callback function that decides whether the response body should be captured or
+whether it should be streamed to the client without further tampering.
+With these two little patches `yeoman server` now happily serves PHP files.
+You can watch the screencast below to see the live reloading in action:
+<video src="assets/yeoman.mp4" controls="true"></video>
@@ -285,6 +285,12 @@ pre, code {
+.content video {
+ max-width:100%;
+ box-shadow: 0 0 10px rgba(0,0,0,0.5);
+ margin-bottom: 2em;
.content code,
.content tt {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.

0 comments on commit 67aad1c

Please sign in to comment.