Change Subdomains Document Root In Apache Server

18 July, 2019

Step 1 - Create Subdomain

If you don’t have a subdomain on your apache server, you can follow this tutorial first and then come back.

Change Document Root

In ‘httpd-vhosts.conf’ change the ‘Document Root’ for the correct subdomain.

Mine, after editing, looks like this:

<VirtualHost *:80>
  ServerName cd.sbond.co
  DocumentRoot "C:\Path\To\Custom\Dir"

  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>
</VirtualHost>

Step 3 - Allow Access To Dir & Make Alias

Go to your ‘httpd.conf’ & find:

<Directory />
  AllowOverride none
  Require all denied
</Directory>

Under it paste & edit:

<Directory "C:\Path\To\Custom\Dir">
   Require all granted
</Directory>

Alias /Dir "C:\Path\To\Custom\Dir" // So you can access this dir easily

Step 4 - Test It

Put a text index file in the custom dir you created and type your subdomain into the address bar on your browser.