
Loading ...
Posted by copilas12
Step 1: DNS: A Record
First we’ll need to log in to WHM. Under DNS Functions, select Edit DNS Zone. Choose the domain for the zone in which you wish to edit. Add an A record mapped to asterisk (wildcard) for the subdomain and the IP Address the site is hosted on. You likely already have A records for ftp, webmail, etc. just model this new one after those.
You should now be able to enter any subdomain on your domain, but it will not likely find your main site. So now we need to set that up.
Step 2: ServerAlias
Log in to your server via SSH and go open /etc/httpd/conf/httpd.conf (I’ll assume you know your way around linux via command line as well as vi or some other editor)
*Note: wherever you see example.com you should expect to see your domain name that you are setting up
Now, we could edit this file and make everything work, but there is a problem with that. Look at the top ofthe document and you should see something like this:
Direct modifications to the Apache configuration file may be lost upon subsequent regeneration of the configuration file. To have modifications retained, all modifications must be checked into the configuration system by running:
/usr/local/cpanel/bin/apache_conf_distiller –update
To see if your changes will be conserved, regenerate the Apache configuration file by running:
/usr/local/cpanel/bin/build_apache_conf
and check the configuration file for your alterations. If your changes have been ignored, then they will need to be added directly to their respective template files.
Basically what it’s saying is don’t edit this file directly because you’re changes may be lost.
Do a search for the domain you are adding the wildcard to. You should find the VirtualHost set up for your domain. Here is mine:
# DO NOT EDIT. AUTOMATICALLY GENERATED. IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.
<VirtualHost 67.225.128.241:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/example/public_html
ServerAdmin webmaster@example.com
UseCanonicalName Off
Options -ExecCGI -Includes
RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
CustomLog /usr/local/apache/domlogs/example.com combined
CustomLog /usr/local/apache/domlogs/example.com-bytes_log “%{%s}t %I .\n%{%s}t %O .”
## User example # Needed for Cpanel::ApacheConf
<IfModule !mod_disable_suexec.c>
SuexecUserGroup example example
</IfModule>
# To customize this VirtualHost use an include file at the following location
# Include “/usr/local/apache/conf/userdata/std/2/example/example.com/*.conf”
</VirtualHost>
Notice the highlighted lines. This is where we are going to create a file. We are going to create a file at:
/usr/local/apache/conf/userdata/std/2/example/example.com/ServerAlias_wildcard.conf
(you can give it any name you want really)
*Hint: You may need to create the directories first, run this command:
mkdir -p /usr/local/apache/conf/userdata/std/2/example/example.com/
So really, you don’t need to edit anything it httpd.conf, we just needed some info.
Inside of the ServerAlias_wildcard.conf file, enter this line:
ServerAlias *.example.com
Now, you’ll need to rebuild the httpd.conf file per the instructions at the top of that file by running the following command:
/usr/local/cpanel/bin/build_apache_conf
If you open your /etc/httpd/conf/httpd.conf file again you should see that your VirtualHost for your domain as changed slightly:
<VirtualHost 67.225.128.241:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/example/public_html
ServerAdmin webmaster@example.com
UseCanonicalName Off
Options -ExecCGI -Includes
RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
CustomLog /usr/local/apache/domlogs/example.com combined
CustomLog /usr/local/apache/domlogs/example.com-bytes_log “%{%s}t %I .\n%{%s}t %O .”
## User example # Needed for Cpanel::ApacheConf
<IfModule !mod_disable_suexec.c>
SuexecUserGroup example example </IfModule>
Include “/usr/local/apache/conf/userdata/std/2/example/example.com/*.conf”
</VirtualHost>
Step 3: Restart Apache
The last step required is to restart apache. I suppose there are a number of ways to do this. As long as we are logged in to SSH, we might as well just run the command:
service httpd restart
Now, give it a try. you should be aby to access something like http://whatever.example.com and still see your main page.
If you enjoyed this post, make sure you subscribe to my RSS feed!