Home >Backend Development >PHP Tutorial >Can XAMPP Serve Files Outside the htdocs Directory?

Can XAMPP Serve Files Outside the htdocs Directory?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-10 02:33:09631browse

Can XAMPP Serve Files Outside the htdocs Directory?

Serving Files Beyond htdocs with XAMPP

Question:

Can XAMPP serve files from directories outside of the default htdocs folder?

Answer:

Yes, there are three methods to serve files from alternative locations:

Method 1: Virtual Hosts

  1. Uncomment the NameVirtualHost directive in httpd-vhosts.conf.
  2. Create a new VirtualHost directive with a custom DocumentRoot and ServerName.
  3. Add an entry to the C:WindowsSystem32driversetchosts file to resolve the custom hostname to 127.0.0.1.

Method 2: Aliasing

  1. Copy and paste the Directory directives from the htdocs section to the desired new directory (e.g., C:/Projects).
  2. In the alias_module section, add an Alias directive mapping the desired URL (e.g., /transitCalculator) to the new directory.

Method 3: Changing Document Root

  1. In httpd.conf, comment out the original DocumentRoot directive.
  2. Edit a later directive (e.g., line 203) to set the new DocumentRoot to the desired location.

Additional Notes:

  • Use forward slashes (/) instead of backslashes () in file paths.
  • Don't include trailing slashes in paths.
  • Restart Apache after making changes.

The above is the detailed content of Can XAMPP Serve Files Outside the htdocs Directory?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn