Server Administration & Management

How to Pointing a sub-domain to folder outside public_html

Issue : When you create a sub-domain, cPanel points it to the corresponding folder under public_html by default. How to point it to a folder outside the public_html?

Solution : This cannot be done via cPanel/WHM but can be achieved if you have ‘root’ SSH access to the server.

1. Open the apache configuration file

# vi /usr/local/apache/conf/httpd.conf

2. Search for the virtual host entry for your sub-domain.

3. Edit the document root of your sub-domain to match the desired location.

4. Save and Exit; Restart apache.

# /etc/init.d/httpd restart

Note : cPanel rebuilds httpd.conf from userdata files and its overwritten on every cPanel update, on every account creation, subdomain addition, or any such activity related to apache and any manual changes you make will be overwritten. To make permanent changes to a subdomain’s root folder :

1. Edit the file /var/cpanel/userdata/<username>/subdomain.domain.com file, change the path and save it.

# vi /var/cpanel/userdata/username/subdomain.domain.com

2. Run /scripts/rebuildhttpdconf

# /scripts/rebuildhttpdconf

3. Restart apache.

# /etc/init.d/httpd restart

October 13, 2011 Posted by | Apache, DNS | , , | Leave a comment