When developing local web applications with Xampp, you may eventually need to optimize and customize your working environment. One such customization could involve changing the location of the htdocs folder, where your application files are stored. Whether for reasons of space, organization, or performance, moving htdocs to another location is a straightforward task that can be done in different ways. In this article, we’ll explain how to change the htdocs directory in Xampp in Windows by modifying the Apache configuration file or by creating symbolic links.
By default, Xampp reads the files for your local web applications from the htdocs directory within the installation folder. In some cases, you might need to change this location. For example, if you installed Xampp on a solid-state drive (SSD) but want to store your web application files on a separate hard drive (HDD). In this case, you’ll need to change the htdocs path.
Let’s assume your Xampp is installed on C:\xampp, which means htdocs will be located at C:\xampp\htdocs. In this example, let’s say your HDD is D and you want to store your files in D:\www. To achieve this, you can do it in two ways: by changing the path in the Apache configuration file or by using symbolic links.
To change the path from which documents are served over HTTP in Xampp, you’ll need to replace the DocumentRoot value and its corresponding in the Apache configuration file.
To make this change, access the httpd.conf file in Xampp, either from the Config button, selecting Apache (httpd.conf), or by navigating manually to C:\xampp\apache\conf\httpd.conf. Then, look for the DocumentRoot option and the tag below it, and replace the path in both cases.
If you’ve already done some work inside htdocs, it might be tedious to copy all the files to the new location, especially if you’re dealing with large applications. Depending on your case, it’s possible to host new web applications in a new location using symbolic links. To create symbolic links, you need to use the MKLINK command with the /D option to indicate a directory, like this:
mklink /d project D:\www\project
With this command, we create a symbolic link named project inside the htdocs folder, pointing to D:\www\project. In this case, to access the files via a browser, you would use the path localhost/project.
Changing the htdocs location in Xampp is a great option when you want to better utilize system resources, such as different storage drives. Whether you prefer to modify the httpd.conf file directly or create symbolic links, both methods allow you to keep a more organized and efficient development environment. Depending on whether you’re starting a new project or working with existing files, you can choose the method that best suits your needs.