This sample application for Heroku shows how Heroku's support for multiple buildpacks can be used to run both the Node.js and PHP buildpacks during a deploy, which allows using Node from inside the PHP buildpack's bin/compile.
In this example, we're using Bower in a Composer post-install-cmd to install Bootstrap.
To try it out, clone this repo, run heroku create, then heroku buildpacks:add heroku/nodejs followed by heroku buildpacks:add heroku/php, and finally deploy using git push heroku master. If you want to port this to an existing app, you'll need to use a combination of heroku buildpacks:set and heroku buildpacks:add to set the correct buildpack order.
You can also quickly deploy a version of this example to Heroku by clicking the button below:
Example: http://heroku-multipack-nodejs-php-ex.herokuapp.com/
- The
heroku buildpacks:addcommand is used to set multiple buildpacks on an app (seeheroku buildpacks) - The Node.js buildpack installs Bower using NPM (see
package.json/npm-shrinkwrap.json) - The Node.js buildpack makes its binaries available to the next buildpack in the chain
- The PHP buildpack runs and installs dependencies using Composer
- As part of the composer install step, the
post-install-cmdscripts run - That executes
$(npm bin -q)/bower install-bower installwould work too, asnode_modules/.binis on$PATHon Heroku, but it would likely not work on local development environments, hence the more portable use of prefixing the result fromnpm bin -qto retrieve said directory name. - Bower installs Bootstrap
- Done!
