Skip to main content

Virtual Hosts & Hosts File

For every project, LaraEnv writes a virtual host config and adds a matching entry to the Windows hosts file so <name>.<tld> resolves to your machine.

Where files live

  • The per-project vhost is written to C:\laraenv\nginx\conf\sites\<name>.conf (or the Apache equivalent under C:\laraenv\apache\...).
  • LaraEnv patches C:\Windows\System32\drivers\etc\hosts to point <name>.<tld>127.0.0.1.
note

Editing the hosts file requires Administrator rights, so LaraEnv needs to run elevated to add or remove these entries.

The vhost editor

The vhost editor lets you work with the generated config inline:

  • Edit it with syntax highlighting.
  • Save your changes.
  • Reset to template to discard edits and regenerate the default config.

Example Nginx server block

server {
listen 80;
server_name mysite.test;
root C:/laraenv/www/mysite;
index index.php index.html;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
fastcgi_pass php_upstream_84;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

The fastcgi_pass upstream points at the PHP-FPM pool for the version chosen in the project's configuration.

SSL

Enabling SSL generates a self-signed certificate under C:\laraenv\nginx\certs\ and adds a 443 server block to the vhost so the site is reachable over HTTPS.

Changing the global TLD

Changing the global TLD (.test / .local / .dev) regenerates every vhost and hosts-file entry at once, so all projects switch to the new suffix together.