How to use browser sync with php
use gulp-connect-php
npm install --save-dev gulp-connect-php
then setup you gulpfile.js
var gulp = require('gulp'), connect = require('gulp-connect-php'), browserSync = require('browser-sync');gulp.task('connect-sync', function() { connect.server({}, function (){ browserSync({ proxy: '127.0.0.1:8000' }); }); gulp.watch('**/*.php').on('change', function () { browserSync.reload(); });});
see documentation https://www.npmjs.com/package/gulp-connect-php
Also there is a good tutorial here https://phpocean.com/tutorials/front-end/automate-your-workflow-with-gulp-part-3-live-reloading/23
I have the same situation for a few days until I figure out that it happens because I didn't close my html output properly. BrowserSync needs to include some javascript text before to reload the browser. If the html, body tags are NOT closed or NOT present, BrowserSync has nowhere to include the script.
A proxy
option is now available in browser-sync when using an external server.
Config docs : https://browsersync.io/docs/options#option-proxy
// Using a vhost-based urlproxy: "local.dev"// Using a localhost address with a portproxy: "localhost:8888"// Using localhost sub directoriesproxy: "localhost/site1"
Command line : https://browsersync.io/docs/command-line#start
browser-sync start --proxy "localhost:8080" --files "**/*"