how to configuring a xampp web server for different root directory

how to configuring a xampp web server for different root directory

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Configuring XAMPP to Serve a Custom Web Root

By default, XAMPP installs your Apache web server with htdocs as the document root. When you navigate to http://localhost/, the server serves files directly from C:\xampp\htdocs (on Windows) or /Applications/XAMPP/xamppfiles/htdocs (on macOS). This is the standard setup for quick prototyping, but it often fails to align with modern application structures where public assets live in a subdirectory like myproject/web.

You want to access your application at http://localhost/myproject or simply http://localhost, while having the server physically read files from xampp\htdocs\myproject\web. Achieving this requires distinguishing between the Document Root and the Directory Structure.

Understanding Document Root vs. Physical Path

The core confusion often lies in mixing up where Apache looks for files versus how you type the URL.

  • Document Root: The directory Apache treats as the base of your web site. If this is set to /public_html, accessing http://localhost/ serves files from that folder.
  • Application Entry Point: Where your actual PHP code or framework starts (e.g., public/index.php).

In your specific scenario, you have two main options: modifying Apache's configuration to point the root to the web folder, or using URL rewriting to simulate a deeper structure.

Option 1: Modifying the VirtualHost Configuration

The most robust solution is to tell Apache that the Document Root for your project is specifically the web directory. This allows you to keep htdocs as a container for multiple projects while serving the correct files when you hit the root URL.

Open your XAMPP configuration file, typically located at C:\xampp\apache\conf\extra\httpd-vhosts.conf. If this file does not exist, create it inside the extra folder.

Add a <VirtualHost *:80> block configured for your specific project:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/xampp/htdocs/myproject/web"
    
    <Directory "C:/xampp/htdocs/myproject/web">
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    # Optional: Ensure .htaccess rules work if your framework needs them
    ErrorLog "C:/xampp/apache/logs/error.log"
    CustomLog "C:/xampp/apache/logs/access.log" combined
</VirtualHost>

Key details to note here:

  1. DocumentRoot Path: You must use forward slashes (/) in the configuration string, regardless of your operating system, even though you are on Windows. This is a strict requirement for Apache config files.
  2. AllowOverride All: This directive is crucial. It tells Apache to respect .htaccess files inside your web directory. If you are using Laravel or Symfony, they rely on these files to route requests and protect the directory. Without this, your framework might throw a "Directory index forbidden" error.
  3. Security: Ensure that the parent htdocs folder isn't accidentally served. By setting the DocumentRoot precisely to the web subfolder, you prevent users from accessing .env files or cache directories located outside the public root.

After making these changes, restart the Apache service in the XAMPP Control Panel. Now, visiting http://localhost/ will serve the contents of xampp\htdocs\myproject\web.

Option 2: Using .htaccess for URL Rewriting

If you prefer not to change your DocumentRoot or if you are managing multiple projects and want to keep them physically separate under different URLs (e.g., http://localhost/myproject), you can use Apache's mod_rewrite module.

This approach requires pointing the DocumentRoot back to htdocs but then rewriting requests so that anything typed after /myproject is interpreted as being relative to the web folder.

In your .htaccess file located at C:/xampp/htdocs/myproject/web/.htaccess, add:

RewriteEngine On
RewriteBase /myproject/
RewriteRule ^ index.php [L]

However, this method has a significant trade-off: it forces all traffic through your front controller (index.php). While this works well for frameworks like Laravel or Symfony that use a single-entry point, it breaks direct access to static assets (CSS, JS, images) if they aren't symlinked or referenced correctly. The first option (changing the DocumentRoot) is generally superior because it allows Apache to serve static files directly and efficiently without passing every request through PHP.

Common Pitfalls and Best Practices

When migrating from a standard htdocs setup to a nested structure, developers often encounter permission errors. Ensure the user running Apache (often ApacheService on Windows or www-data on Linux/Mac) has read permissions for the specific web directory.

Additionally, be aware that changing the DocumentRoot affects how you deploy your application. If you move your project later to production, remember that the production server likely won't have XAMPP's folder structure. You will need to configure your Nginx or Apache virtual host on the live server to point to your actual public directory, which is often just /var/www/myproject/public.

If you are working with Laravel specifically and find yourself struggling with file permissions or symlink issues when moving between environments, resources like LaravelCompany offer practical guides on configuring local development environments that match production setups.

Ultimately, setting the DocumentRoot directly in httpd-vhosts.conf is the cleanest approach. It separates your physical file structure from your logical URL structure, ensuring that static assets load fast and your framework's routing rules are respected without unnecessary overhead.

Our network