Coder Social home page Coder Social logo

php-from-yeoman's Introduction

(from Coderwall proptip published at https://coderwall.com/p/bal2_a)

Ever needed to use a PHP script in your Yeoman project? It's quite straightforward to do so while keeping all of the goodness that Yeoman brings together for you (particularly live reloading).

The integration is accomplished via a middleware by Felix Gnass named gateway. Gateway enables you to specify CGI handlers for requests matching certain extensions (.php in our case). Mr. Gnass wrote a blog post on this protip's topic, but didn't include step-by-step instructions for the middleware integration, which took me a while to figure out.

Generate an app with Yeoman

$ mkdir php-from-yeoman
$ cd php-from-yeoman
$ yo webapp

Ensure that php-cgi is in your $PATH

$ which php-cgi

If you get php-cgi not found, here's how to install it using Homebrew on OS X (for other OS's, Google is your friend):

brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install php54

Setup gateway module

$ npm install gateway

Modify Gruntfile.js by adding the following near the top:

var gateway = require('gateway');

Modify the array returned by the function at connect.livereload.options.middleware to look like this:

middleware: function (connect) {
  return [
    lrSnippet,
    gateway(__dirname + '/app', {
      '.php': 'php-cgi'
    }),
    mountFolder(connect, '.tmp'),
    mountFolder(connect, 'app')
  ];
}

Rename app/index.html and test

$ mv app/index.html app/index.php

Add <?php echo "<h1>Hello from PHP!</h1>"; within the body tag of app/index.php.

Then fire up your development server:

$ grunt server

Assuming that your browser launched and load http://localhost:9000/, you should see Hello from PHP! on the page.

Make some changes to app/index.php, save the file, and you should your browser should automatically reload.

Note: due a to naïve conditional in the livereload library, live reloading will only work for PHP files when the URL ends with a '/' (so basically, index.php files).

php-from-yeoman's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

php-from-yeoman's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.