Development Workflow

Configure XAMPP Virtual Hosts for Multiple PHP Projects

Use named local hostnames and separate document roots to develop several PHP projects with XAMPP.

A single htdocs directory becomes awkward when several applications are developed at once. Apache virtual hosts let each project use a local hostname and its own document root, which more closely resembles production URL routing.

Create a project document root

For example, create C:/dev/sites/storefront/public and place only public entry-point files inside public. Keep application classes, configuration, logs and private uploads outside that directory where the project architecture permits.

Add a virtual host

In the Apache configuration, enable the virtual-host include if it is not already active. Add a host definition similar to this, adjusting the path and hostname:

<VirtualHost *:80>
    ServerName storefront.test
    DocumentRoot "C:/dev/sites/storefront/public"
    <Directory "C:/dev/sites/storefront/public">
        AllowOverride All
        Require local
    </Directory>
    ErrorLog "logs/storefront-error.log"
    CustomLog "logs/storefront-access.log" combined
</VirtualHost>

Resolve the local hostname

Add 127.0.0.1 storefront.test to the Windows hosts file using an elevated editor. Restart Apache and open http://storefront.test/`. If the default XAMPP page appears, check that the virtual-host configuration is loaded and that the hostname matches exactly.

Keep rewrite rules scoped

Use .htaccess only when AllowOverride is enabled for that directory. Prefer project-specific rewrite rules and avoid broad rules that affect sibling sites. Confirm that direct requests to private configuration files are denied and that the document root points to the public directory, not the project root.

Validate changes

Run Apache's configuration test before restarting if the installed build provides httpd -t. Keep a backup of the configuration and document each local hostname so team members can reproduce it.

Further reading

Share this page Help other developers discover this resource.