Search code examples
gulpgulp-watch

Gulp plugin for running a PHP server?


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?


Solution

  • 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!