2

I'm looking to transition over from grunt to gulp. However I'm not finding a way to serve PHP files with livereload support, such as gateway (https://www.npmjs.org/package/gateway) using mounts. Are ther any plugins out there for running/server PHP using a gulp task?

user1795832
  • 2,080
  • 8
  • 29
  • 50
  • I don't understand what has livereload to do with PHP... Are you trying to "watch" some PHP files and do something with their output? – coma Oct 07 '14 at 01:23
  • Sort of. I want it to serve PHP files because that is what I am scripting with (using include for header, footer), but also want the benefits of sass, livereload, etc for developing the UI. – user1795832 Oct 07 '14 at 01:56
  • did you find out how to do it? – zok Dec 02 '14 at 12:35

2 Answers2

1

I asked totally the same question few weeks ago. I want to start a native PHP server under Gulp, because I like the syntax better than Grunt. I also want to use PHP just to include other HTML files. :) It turns out there is a 'gulp-connect-php' plugn which has a very similar syntax to 'grunt-php' plugin.

https://www.npmjs.com/package/gulp-connect-php

https://www.npmjs.com/package/grunt-php

Here is my code to Gulp:

var gulp = require('gulp'),
    livereload = require('gulp-livereload'),
    connectPHP = require('gulp-connect-php');

gulp.task('connect', function() {
  connectPHP.server({
    hostname: '0.0.0.0',
    bin: 'C:/php/php.exe',
    ini: 'C:/php/php.ini',
    port: 8000,
    base: 'dev',
    livereload: true
  });
});

I also setted the exe and ini file location.

If you interested in, this is the code for Grunt:

php: {
  watch: {
    options: {
      livereload: true,
      bin: 'C:/php/php.exe',
      ini: 'C:/php/php.ini',
      base: '../development',
      port: 8000
    }
  }
}

I hope it helps!

Lanti
  • 2,299
  • 2
  • 36
  • 69
0

I ended up using gulp-connect-php with http-proxy. In the end, my php serve task looked like this:

gulp.task('php-serve', ['styles', 'fonts'], function () {
connect.server({
    port: 9001,
    base: 'app',
    open: false
});

var proxy = httpProxy.createProxyServer({});

browserSync({
    notify: false,
    port  : 9000,
    server: {
        baseDir   : ['.tmp', 'app'],
        routes    : {
            '/bower_components': 'bower_components'
        },
        middleware: function (req, res, next) {
            var url = req.url;

            if (!url.match(/^\/(styles|fonts|bower_components)\//)) {
                proxy.web(req, res, { target: '{ip address taken out}:9001' });
            } else {
                next();
            }
        }
    }
});

// watch for changes
gulp.watch([
    'app/*.html',
    'app/*.php',
    'app/scripts/**/*.js',
    'app/images/**/*',
    '.tmp/fonts/**/*'
]).on('change', reload);

gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/fonts/**/*', ['fonts']);
gulp.watch('bower.json', ['wiredep', 'fonts']);
});
user1795832
  • 2,080
  • 8
  • 29
  • 50