Manuals
RU EN

Server · 27

*.loc Virtual Host on Windows

Server 6 min read

A *.loc virtual host lets a script open like a real site: http://project.loc, not http://localhost/project. The second option breaks absolute paths, redirects, and sometimes authorization. Old local stacks solved this with drive mappings and manual aliases; MicroServer keeps it simpler.

Rule: folder name in www equals host name. You do not need to write a separate Apache config block for every training project.

Quick path

  1. Create a project.loc folder in the MicroServer www directory, often D:\MicroServer\www.
  2. Put the script files there: index.php in the folder root.
  3. Wait for hosts synchronization or restart the server if that is how your panel works.
  4. Open http://project.loc. If SSL is enabled, use https.

Stack overview: local server. If you came from old Denwer searches: Denwer PHP 8.

Why not localhost/folder

Many scripts treat the host document root as the site root. In a subfolder, CSS and ajax paths move to the wrong place, and the admin area gets broken links. Fixing it with constants is worse than starting with a proper vhost.

Cookies for localhost and project.loc behave differently. Debugging authorization on a fake domain is closer to production.

hosts file

MicroServer writes mappings into the system hosts file. If the host does not open:

  • the server is not running;
  • the hosts entry was not created because of administrator rights or antivirus;
  • Windows DNS cache still holds the old value: ipconfig /flushdns;
  • the browser uses secure DNS and ignores hosts; disable it temporarily.

A manual line like 127.0.0.1 project.loc is acceptable for a check, but avoid duplicates with what the server writes.

Nested folders after unpacking

Archives often contain a folder inside. You unpack and get project.loc/project/index.php. The browser then sees the wrong root. Move the contents up to the host level. This is the same trap during installation: installation.

HTTPS for *.loc

A local CA issues certificates for your hosts. The browser must trust the root. Without that, you will see a warning, but for debugging Secure cookies it is still better to configure trust. Instruction: local HTTPS.

Several projects

Each script gets its own folder and database. Do not install two products in one host "temporarily". Dumps and configs will be mixed. Databases: phpMyAdmin.

.loc suffix is a local convention. This domain is not delegated on the internet. Production will use a normal .ru/.com; migration is here.

If you are used to manual Apache

You can write VirtualHost blocks manually in other stacks such as OpenServer or XAMPP. The idea is the same: ServerName, DocumentRoot, PHP access. In MicroServer this layer is automated, so do not duplicate configs behind its back and later wonder which one wins.

On a Linux VDS, virtual hosts are configured differently through Nginx/Apache: Nginx + PHP-FPM, server choice: VDS.

Diagnostics

  • Another site opens: folder mismatch or DNS cache.
  • 403/404: no index in the root or wrong document root.
  • 500: PHP log, see 500 error.
  • Connection refused to MySQL: server/database is not running, see database error.

Composer, if the project needs it: Composer on Windows.

Host name details that break the day

Spaces, non-Latin characters, and mixed uppercase letters in the folder name are a bad idea. Use lowercase Latin letters and the .loc suffix. Board.Loc and board.loc may merge on the Windows file system while behaving annoyingly in browsers and cookies.

Do not use real third-party domains in hosts "for convenience". Tomorrow you will forget the line and wonder why example.com opens your local store.

Subfolders and script routing

If the script really lives in project.loc/public, document root must point to public. In MicroServer, for simple cases it is easier to keep index in the host root as delivered. Otherwise you need a manual vhost, and the "folder equals host" idea is lost.

Clean URLs usually depend on the host root. If installing into a /shop/ subdirectory on production, read the readme; not every product supports this out of the box. Locally, start at the root: installation.

Several versions of one project

board.loc is current work; board-old.loc is a copy before update. Different folders, different databases. If board.loc breaks after code changes, compare with old. This is cheaper than remembering yesterday's state. Backup before updates is still required: backup.

HTTPS on a specific host

Not every local host must use 443. Enable SSL where you debug the account area and cookies. Instruction: local HTTPS. For simple layout review, http is enough.

Hosts and corporate DNS

In a corporate network, DNS may intercept requests and ignore your hosts file for some zones. If ping project.loc does not go to 127.0.0.1, the problem is not MicroServer. Test on another network or ask your IT team.

ping may show IPv6 ::1; that is normal if the server listens on IPv6 too. If not, disable IPv6 in the browser for a test or adjust stack listeners.

Database and migration link

Site host and MySQL host are different things. The site is project.loc; MySQL is usually 127.0.0.1 locally. Do not confuse them in the installer form. Database: phpMyAdmin. Requirements: PHP/MySQL.

When the local host is tested, move to a real domain: migration. In production, the virtual host is configured by the panel or Nginx: Nginx + PHP-FPM, not by a *.loc folder.

A useful trick: create project-stg.loc as a copy before dangerous template updates. Copy the folder, clone the database through export/import, and set different database credentials in the copy config. Break staging and the local production copy stays alive. It is not Git, but for solo Windows development it works for years. Just do not keep dozens of dead hosts without folders in hosts. Copy database: phpMyAdmin, backup before copying: backup. If a copied site returns 500, you probably forgot to change the database name in config: database error. Stack overview: MicroServer. Host HTTPS: local HTTPS. Installing a script in the host root: installation. If a directory listing opens instead of the site, there is no index.php in the host folder root.

FAQ

How to create loc virtual host windows?

In MicroServer, the folder name becomes the host. You do not write a separate vhost by hand.

How long does “*.loc Virtual Host on Windows” take?

About 6 minutes to read. In practice it depends on your hosting and database setup.

Do I need a dedicated server?

For most scripts, shared hosting or a VDS with PHP and MySQL is enough. See the VDS section and PHP/MySQL requirements.

Denwer php 8 free download?

See the related manual for this query. denwer php 8 free download

Windows local server php 8 mysql?

See the related manual for this query. windows local server php 8 mysql

Section
Denwer and local server

A Windows local stack for debugging scripts before you deploy to a VDS.