Start php server with livereload with Gulp

Asked

Viewed 1,042 times

0

I started my studies with Gulp and loved livereload, but I could only with static files like this link. My goal is to start Gulp, but on the built-in php server (localhost -s Localhost:8000) or on the server with Xampp or Lampp, instead of the Node server. I saw some people talking about a solution with browsersync and another with Gulp-connect-php but I couldn’t implement both. If you know any solution and that is not a plugin for the browser I am grateful.

1 answer

4


After a few days I managed to solve my problem using Gulp-connect-php and browser-Sync in Gulp. The official documentation shows exactly an example how it is done. Look how it turned out my file gulpfile.js:

var gulp        = require('gulp');
var browserSync = require('browser-sync');
var reload      = browserSync.reload;
var connectPHP  = require('gulp-connect-php');

var paths = {
      php:['*.php'],
      css:['*.css']
    };

gulp.task('php', function(){
    gulp.src(paths.php)
    .pipe(reload({stream:true}));
});

gulp.task('watcher',function(){
    gulp.watch(paths.css).on('change', function () {
      browserSync.reload();
    });
    gulp.watch(paths.php).on('change', function () {
      browserSync.reload();
    });
});

gulp.task('php', function() {
  connectPHP.server({}, function (){
    browserSync({
      proxy: 'localhost:8000'
    });
  });
});

gulp.task('default', ['php', 'watcher']);

For those who have problem in the implantation I created a repository on Github as an example for those who have difficulty.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.