Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • SensioLabs Professional services to help you with Symfony
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by SensioLabs
  1. Home
  2. Documentation
  3. Frontend
  4. Using Encore in a Virtual Machine
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud

Table of Contents

  • File Watching Issues
  • Development Server Issues
    • Configure the Public Path
    • Allow External Access
    • Fix "Invalid Host header" Issue

Using Encore in a Virtual Machine

Edit this page

Using Encore in a Virtual Machine

Encore is compatible with virtual machines such as VirtualBox and VMWare but you may need to make some changes to your configuration to make it work.

File Watching Issues

When using a virtual machine, your project root directory is shared with the virtual machine using NFS. This introduces issues with files watching, so you must enable the polling option to make it work:

1
2
3
4
5
6
7
8
// webpack.config.js

// ...

// will be applied for `encore dev --watch` and `encore dev-server` commands
Encore.configureWatchOptions(watchOptions => {
    watchOptions.poll = 250; // check for changes every 250 milliseconds
});

Development Server Issues

Configure the Public Path

Note

You can skip this section if your application is running on http://localhost instead a custom local domain-name like http://app.vm.

When running the development server, you will probably see the following errors in the web console:

1
2
3
GET http://localhost:8080/build/vendors~app.css net::ERR_CONNECTION_REFUSED
GET http://localhost:8080/build/runtime.js net::ERR_CONNECTION_REFUSED
...

If your Symfony application is running on a custom domain (e.g. http://app.vm), you must configure the public path explicitly in your package.json:

1
2
3
4
5
6
7
8
{
      ...
      "scripts": {
-        "dev-server": "encore dev-server",
+        "dev-server": "encore dev-server --public http://app.vm:8080",
          ...
      }
  }

After restarting Encore and reloading your web page, you will probably see different issues in the web console:

1
2
GET http://app.vm:8080/build/vendors~app.css net::ERR_CONNECTION_REFUSED
GET http://app.vm:8080/build/runtime.js net::ERR_CONNECTION_REFUSED

You still need to make other configuration changes, as explained in the following sections.

Allow External Access

Add the --host 0.0.0.0 argument to the dev-server configuration in your package.json file to make the development server accept all incoming connections:

1
2
3
4
5
6
7
8
{
      ...
      "scripts": {
-        "dev-server": "encore dev-server --public http://app.vm:8080",
+        "dev-server": "encore dev-server --public http://app.vm:8080 --host 0.0.0.0",
          ...
      }
  }

Caution

Make sure to run the development server inside your virtual machine only; otherwise other computers can have access to it.

Fix "Invalid Host header" Issue

Webpack will respond Invalid Host header when trying to access files from the dev-server. To fix this, set the allowedHosts option:

1
2
3
4
5
6
7
8
9
// webpack.config.js
// ...

Encore
    // ...

    .configureDevServerOptions(options => {
        options.allowedHosts = all;
    })

Caution

Beware that it's not recommended to set allowedHosts to all in general, but here it's required to solve the issue when using Encore in a virtual machine.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    We stand with Ukraine.
    Version:

    Symfony 6.2 is backed by

    Symfony 6.2 is backed by

    Symfony Code Performance Profiling

    Symfony Code Performance Profiling

    Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

    Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

    Symfony footer

    ↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

    Avatar of Quentin Favrie, a Symfony contributor

    Thanks Quentin Favrie for being a Symfony contributor

    2 commits • 6 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • Symfony at a Glance
      • Symfony Components
      • Case Studies
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • SymfonyConnect
      • Support
      • How to be Involved
      • Code of Conduct
      • Events & Meetups
      • Projects using Symfony
      • Downloads Stats
      • Contributors
      • Backers
    • Blog

      • Events & Meetups
      • A week of symfony
      • Case studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Documentation
      • Living on the edge
      • Releases
      • Security Advisories
      • SymfonyInsight
      • Twig
      • SensioLabs
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Deployed on

    Follow Symfony

    Search by Algolia