Web Programming: HOw to Create Your Own Subdomain



First and foremost, you need to create the vhost.conf file for the domain itself.  The vhost.conf and vhost_ssl.conf file needs to be created in the conf directory of the domain.  On Plesk it should be similar to: /var/www/vhosts/domain.com/conf/vhost.conf.

You can create the file from within the Plesk panel itself or using an SSH client like Putty (my preference).

Within the vhost.conf file you need to include the following line:

ServerAlias *.domain.com

Replacing “domain.com” with your domain.

Once you’ve done that you’ll need to run the following from your SSH client (there’s other ways to do this but this worked fine for me):

/usr/local/psa/admin/sbin/websrvmng –reconfigure-vhost –vhost-name=domain.com

Then restart apache and go try it out.  Guess what?  It’s supposed to work but it still doesn’t!

This is where the final magical step comes in.  Log in to your Plesk panel, go to domains, and select the domain that you are trying to set this up on.  Once the page loads, select DNS Settings.

From there, click the Add Record button from the top.

The Record Type should be CNAME.  In the “Enter domain name” field enter a *.  Then in the canonical name field enter your domain (without a www, just a plain domain.com).

Click Ok to save the record and try again.

thanks to vernonkesner.com

Everyone has a “www” subdomain (In “www.yourdomain.com”, the “www” part is the subdomain). The www subdomain is created by, and serves files from, your /htdocs/www directory on the filesystem.

To add more subdomains, just create new subdirectories in the /htdocs directory.
For instance, if you had the domain name mychevycars.com and wanted a subdomain for Corvettes, then you would just create the directory /htdocs/corvettes and upload the files in there that you wanted to see at http://corvettes.mychevycars.com

Second Level Subdomains
To create second level subdomains like http://www.corvettes.mychevycars.com (“www” is the second level subdomain and “corvettes” is the first level subdomain in this example) then you would do one of the following:

1. If you have made an /htdocs/corvettes directory so that you have http://corvettes.mychevycars.com then you can make http://www.corvettes.mychevycars.com by getting a shell prompt and creating a symlink like so:

cd /htdocs
ln -s corvettes http://www.corvettes

Now http://www.corvettes.mychevycars.com will lead to the same place as http://corvettes.mychevycars.com and all the files for both of these URLs are uploaded in the /htdocs/corvettes directory.

2. Alternatively, you may want your second level subdomain to lead to a separate area of your website instead of being symlinked together with the first level subdomain. For example you may want http://splitbumper.corvettes.mychevycars.com (where “splitbumper” is the second level subdomain) to lead to a section of your website dedicated to 1963-1965 Corvettes with split bumpers, and have http://corvettes.mychevycars.com just lead to a different section of your site about Corvettes in general. To setup the second level subdomain this way, you would make a separate directory altogether for it, like this:

cd /htdocs
mkdir splitbumper.corvettes

The “splitbumper.corvettes” subdirectory is created right alongside all the other subdomain subdirectories, including the “corvettes” subdirectory, if you made one. Then you upload files related to splitbumpers into the/htdocs/splitbumper.corvettes subdirectory, and view them in a browser at http://splitbumper.corvettes.mychevycars.com

#Some tips from contributors:

If you need to delete a subdomain symlink made with the “ln -s …”

rm -f /htdocs/www.corvettes

Make sure the directory name you create is all lower-case, with no spaces. CAPS or Mixed-Case will not work.

Careful that you only use letters, numbers and (I think) hyphens in your sub-domains. I spent a whole day debugging and wondering why PHP sessions weren’t carrying through page to page. It was because I had an underscore in the subdomain. As soon as I changed the subdomain name not to have an underscore, then PHP sessions worked again and I could login to my application.

source: support.modwest.com


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s