Configuring a virtual host

epanagio

Well-Known Member
May 26, 2012
50
1
58
cPanel Access Level
Website Owner
Shiver me timbers!

I would like to have a special documentroot for just one domain and I am wondering if I am going about it correctly.

In /usr/local/apache/conf/extra/ I found this interesting file, httpd-vhosts.conf.

I am hosting several domains. All except one will have the default documentroot.

Is this all I need to have?

NameVirtualHost *:80
# VirtualHost example:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/usr/local/apache/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
If my domain name is domain.com with the document root in /home/evan/public_html/wordpress would the httpd-vhosts.conf look like this?

NameVirtualHost *:80
# VirtualHost example:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/home/evan/public_html/wordpress"
ServerName evan.com
ServerAlias http://www.domain.com
ErrorLog "<some path here>"
CustomLog "some other path here" common
</VirtualHost>
How would I let apache know that I am using virtual hosts?


Also, if something goes wrong and I want to disable virtual hosting because the httpd-vhosts.conf is incorrect how would I let apache know to ignore the erroneous httpd-vhosts.conf file?

Thanks!
 
Last edited:

epanagio

Well-Known Member
May 26, 2012
50
1
58
cPanel Access Level
Website Owner
I looked in httpd.conf and there is a virtual host included for every domain. If I were to include a httpd-vhosts.conf that would override the cpanel's entry I am guessing that I would include it AFTER the cpanel's generated entry in httpd.conf?
 

epanagio

Well-Known Member
May 26, 2012
50
1
58
cPanel Access Level
Website Owner
After adding a virtual host the documentroot is not served properly.

httpd restarts without errors.

NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin <email here>
DocumentRoot "/home/<account>/public_html/wordpress"
ServerName <domain name>
ServerAlias www.<domain name>
ErrorLog "/usr/local/apache/logs/a-name_log"
CustomLog "/usr/local/apache/logs/a-name-access_log" common
</VirtualHost>

When I go to domain name it does not shows me the contents of the documentroot path, instead, I get the contents of the domain name, which is a list of directories.