Skip to content

File changes not detected in WSL2 (Ubuntu) with polling enabled #2096

@virtualabishek

Description

@virtualabishek

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

  1. Set up a PHP project in WSL2 (Ubuntu) under /var/www/html/phpLab/day4.
  2. Install BrowserSync globally:
    sudo npm install -g browser-sync
  3. Create a bs-config.js file:
    module.exports = {
      proxy: "localhost/phpLab/day4",
      files: ["./**/*.php", "./**/*.css", "./**/*.js"],
      watchOptions: {
        usePolling: true,
        interval: 1000
      },
      ghostMode: false,
      open: false,
      reloadDelay: 500,
      injectChanges: true,
    };
  4. Start BrowserSync:
    browser-sync start --config bs-config.js --host 0.0.0.0 --watch --use-polling
  5. Make changes to files in the project directory.
  6. Observe that BrowserSync does not detect changes or reload the browser.

Expected Behavior

BrowserSync should detect file changes and reload the browser automatically when files are modified.

Actual Behavior

BrowserSync starts successfully and proxies the site, but it does not detect file changes or trigger browser reloads.


Debugging Steps Taken

1. Increased inotify watchers

Since WSL2 has limited inotify watchers by default, increased the limit:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

2. Verified file permissions

Ensured the user has the correct permissions to modify files:

sudo chown -R $USER:$USER /var/www/html/phpLab/day4
sudo chmod -R 755 /var/www/html/phpLab/day4

3. Checked BrowserSync UI

Opened http://localhost:3001 and verified that no browsers were connected under "Current Connections".


Looking for a solution to get live reloading working properly within this environment. Any help or insights are appreciated!

Environment

  • OS: Windows 11 (WSL2 with Ubuntu 22.04)
  • BrowserSync Version: 2.29.3
  • Node.js Version: 18.x
  • Project Directory: /var/www/html/phpLab/day4
  • Browser: Chrome (latest)

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions