You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
File changes not detected in WSL2 (Ubuntu) with polling enabled #2096
I’m using BrowserSync in a WSL2 (Ubuntu) environment on Windows 11. While BrowserSync starts successfully and proxies my PHP project, it doesn’t detect file changes or reload the browser automatically, even with --use-polling enabled.
BrowserSync Not Reloading in WSL2 (Ubuntu)
Issue Description
BrowserSync is not detecting file changes or reloading the browser in a PHP project running on WSL2 (Ubuntu) with Apache. The site is proxied through BrowserSync but does not refresh when files are modified.
Steps to Reproduce
Set up a PHP project in WSL2 (Ubuntu) under /var/www/html/phpLab/day4.
Have you tried with absolute path instead of relative path for the files array? ./**/*.php -> /var/www/html/phpLab/day4/**/*.php
I had this exact same problem with WSL2 + Dockerized PHP-FPM, so I've decided to create a custom bs-config.js file for Browsersync:
/* |-------------------------------------------------------------------------- | Browser-sync config file |-------------------------------------------------------------------------- | | For up-to-date information about the options: | http://www.browsersync.io/docs/options/ | | There are more options than you see here, these are just the ones that are | set internally. See the website for more info. | | */constpath=require("path");constresolve=(...segments)=>path.join(__dirname, ...segments);constPATHS={// File patterns to monitor for changes (relative to project root)files: ["src/core/Views/**/*.php","src/public/css/*.css","src/public/js/*.js",],// Legacy watch patterns (use only for special cases)watch: [],// Directories/files to ignoreignore: ["src/vendor/**"],};module.exports={ui: {port: 3001,},files: [...PATHS.files].map((pattern)=>resolve(pattern)),watchEvents: ["change"],watch: [...PATHS.watch].map(resolve),ignore: [...PATHS.ignore].map((pattern)=>resolve(pattern)),single: false,watchOptions: {ignoreInitial: true,},server: false,proxy: "localhost:80",port: 3000,middleware: false,serveStatic: [],ghostMode: {clicks: true,scroll: true,location: true,forms: {submit: true,inputs: true,toggles: true,},},logLevel: "info",logPrefix: "Browsersync",logConnections: true,logFileChanges: true,logSnippet: true,rewriteRules: [],open: "local",browser: "default",cors: true,hostnameSuffix: false,reloadOnRestart: false,notify: false,scrollProportionally: true,scrollThrottle: 0,scrollRestoreTechnique: "window.name",scrollElements: [],scrollElementMapping: [],reloadDelay: 0,reloadDebounce: 500,reloadThrottle: 0,plugins: [],injectChanges: true,startPath: null,minify: true,host: null,localOnly: false,codeSync: true,timestamps: true,clientEvents: ["scroll","scroll:element","input:text","input:toggles","form:submit","form:reset","click",],socket: {socketIoOptions: {log: false,},socketIoClientConfig: {reconnectionAttempts: 50,},path: "/browser-sync/socket.io",clientPath: "/browser-sync",namespace: "/browser-sync",clients: {heartbeatTimeout: 5000,},},tagNames: {less: "link",scss: "link",css: "link",jpg: "img",jpeg: "img",png: "img",svg: "img",gif: "img",js: "script",},injectNotification: false,};
Must place it in the base root of your PHP folder and then fire it up with the following command: browser-sync start --config /var/www/html/phpLab/day4/bs-config.js
This is how I fixed it personally, hope it helps :)
@virtualabishek, have you tried the bs-config.js way too? What's the path to the PHP files you want to watch? I think you should run Browsersync in Windows Terminal and not in VSCode. It's definitely worth a try.
Activity
edxeth commentedon Feb 19, 2025
Have you tried with absolute path instead of relative path for the
filesarray?./**/*.php->/var/www/html/phpLab/day4/**/*.phpI had this exact same problem with WSL2 + Dockerized PHP-FPM, so I've decided to create a custom
bs-config.jsfile for Browsersync:Must place it in the base root of your PHP folder and then fire it up with the following command:
browser-sync start --config /var/www/html/phpLab/day4/bs-config.jsThis is how I fixed it personally, hope it helps :)
virtualabishek commentedon Feb 20, 2025
I tried what you told me, but faced the same issue. After autosaving, the page doesn't refresh. Thanks for the detailed comment!
edxeth commentedon Feb 20, 2025
@virtualabishek, have you tried the
bs-config.jsway too? What's the path to the PHP files you want to watch? I think you should run Browsersync in Windows Terminal and not in VSCode. It's definitely worth a try.denisenadal commentedon Apr 15, 2025
Hey did you ever solve this issue? I'm experiencing the same thing and would love to know how to resolve
virtualabishek commentedon Apr 17, 2025
No. I still can't solve this issue
edxeth commentedon Apr 23, 2025
@virtualabishek the solution I proposed does not work for you?
Are you running browser-sync in a Docker container, maybe?
virtualabishek commentedon Apr 26, 2025
Yes, It didn't work for me. I did it on the WSL2 Ubuntu Terminal.