The steps to change the document root in Apache

Step 1: Environment Check

  • Confirming Apache is installed. Open Command Prompt and type httpd -v.
httpd -v
  • If Apache is not installed, download and install it from the Apache Lounge.
  • before we make changes first we create a backup file of httpd.conf as shown below.
copy C:\Apache24\conf\httpd.conf 
C:\Apache24\conf\httpd.conf.bak

Step 2: Editing Config File

Find the httpd.conf File: It’s usually located at C:\Apache24\conf\httpd.conf.

Modify httpd.conf file:

  • Open httpd.conf file using any text-editor tools like Notepad.
  • Using ctrl+f find the below line.
DocumentRoot "C:/Apache24/htdocs".
  • Change the path of DocumentRoot directory shown above to your desired new path where the files hosting files exist, as shown below.
DocumentRoot "C:/MyWebsite"
  • After updating the DocumentRoot update the below Directory as shown below.
<Directory "C:/MyWebsite">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Step 3: Applying Changes

  • To save the changes click ctrl+s or click on file if it is notepad and click save.
  • To apply the changes, restart the Apache service. This can be done via Command Prompt with a simple command, Open cmd with administrative privileges and run following command:
httpd -k restart

Step 4: Verifying Changes

  • Visit this url ( http://localhost:custom_port ) in your browser after saving the changes and restarting the Apache service.
  • You should see your new DocumentRoot content.

How to Change the DocumentRoot in Apache?

Document root is a folder where the web application files are stored and these files are accessed by the Apache to serve on demand. In this article, we will look at how we can change the DocumentRoot in Apache.

Similar Reads

The steps to change the document root in Apache

Step 1: Environment Check...

Troubleshooting Tips

Permissions: Make sure Apache can access the new DocumentRoot. Syntax Check: Run httpd -t to check for config errors. Service Issues: If Apache didn’t start, peek at the logs in C:\Apache24\logs....