Apache Document Root In XAMPP

Apache Document Root in XAMPP 
Document Root on Apache web server is the location or directory where to save files that are the source of web application. Files that are stored in the document root directory are files that contains scripts written in web programming language or other file types such as images which these files are the sources used to create web application. Before performing coding using PHP programming language, found the location of the document root is important because in this directory PHP script will be saved with the extension (*.php). Web Server will search the files in the document root when receiving requests from users. It means that the PHP files will only be recognized by the Web server when placed in the document root directory.

I will share a way to found the location of Apache document root. For beginners who are not yet understand the location of the document root on the Apache web server, you can read this article. Previous Apache Web Server must be installed on your computer, if Apache is not yet installed you can read my previous post about installing the Apache web server on Windows Operating System.

If previously, Apache Web Server has been installed through XAMPP package by default,  the document root location can be found by using a web browser to access PHPInfo on XAMPP dashboard with the address http://localhost/dashboard/ then click PHPInfo.

Click PHPInfo link on the XAMPP Dashboard

After getting PHPInfo, then look for information about DOCUMENT_ROOT by pressing CTRL + F and typing search keywords DOCUMENT_ROOT on the search box of your web browser. Document Root's location on my computer was in C:/xampp/htdocs, in this directory I will put the PHP file and then testing the script that I wrote.

Find Document Root's Location In PHPInfo

In addition to the location of the document root, Server Root's location is also important to know, because if you want to configure the settings of PHP and Apache you must make changes to the php.ini and httpd.conf file that located in the Server Root's directory. The short explanation, Server Root is the directory where XAMPP is installed. To locate the Server Root, it was almost the same as finding the location of the Document Root. On PHPInfo page look for the string Server Root by typing these keyword in the search bar of your web browser. On my computer, the location of the Server Root located at C:/xampp/apache.

Now we will try to change the location of the Document Root directory to another. To change the document root configuration we have to open the file httpd.conf, usually the httpd.conf file located in the conf folder in Server Root directory. Because the Server Root on my computer is C:/xampp/apache, the httpd.conf file located in C:/xampp/apache/conf/httpd.conf. Or we can use another way to open the file httpd.conf through XAMPP Control Panel. We can bring out XAMPP Control Panel window via the Start Menu, All Programs, XAMPP, XAMPP Control Panel.

Open XAMPP Control Panel through Start Menu on Windows

After the XAMPP Control Panel window appears, click the config button on the Apache module then select Apache (httpd.conf) menu. It will open the httpd.conf file directly.

Open httpd.conf through XAMPP Control Panel

After httpd.conf file is open, look for the string DocumentRoot on this file. You will find the configuration of Document Root in Apache web server. To change the location of the document root directory to another, you simply replace the value of the document root configuration. For example the location of the document root on my computer is in C:/XAMPP/htdocs, then I want to change it to D:/public_html, then I simply replace the line DocumentRoot "C:/XAMPP/htdocs" to DocumentRoot "D:/public_html" and the line <Directory "C:/xampp/htdocs"> to <Directory "D:/public_html">.

Change the location of document root by editing the httpd.conf file

In terms of changing the location of the Apache document root, you must ensure that the Document Root location that specified in httpd.conf should be available. For example, I change the location of the Document Root to D:/public_html, then the public_html folder must be on drive D. Because if we determine the location of Document Root, but the location was not discovered by the web server, then Apache will not be working. After changes to the httpd.conf file is complete, save the file by pressing CTRL + S on the keyboard, then restart Apache. To restart Apache, click the Stop button on Apache modules in XAMPP Control Panel, then click the Start button to run Apache. Furthermore, to test whether the change is successful, you can open a web browser and visit http://localhost. If the web browser appears as below, the changes have been successful.

Open localhost to test changes to the location of the document root

This article is intended for beginners who want to learn and work on web programming, because a preliminary understanding of the location of the document root is essential. Before learning PHP, beginners should know where they will put the PHP file in order to run.