How do I setup a subdomain on a second server?

jay28lee
jay28lee used Ask the Experts™
on
I have two servers with different hosting companies.

eg. mydomain.com with hosting #1

I would like to setup subdomain.mydomain.com with hosting #2

How can this be done?  What's the process?  In terms of DNS and records configuration.

I'm using unmanaged hosting, and I'll need to know the workflow.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi there,

First, you set up the webhosting part at hosting #2 for the domain name subdomain.mydomain.com,
so the webserver will serve content for that domain. Then, you'll have to set up a DNS entry at hosting #1
to let the entry subdomain.mydomain.com ponit to the IP of the box you run at hosting #2.

That should be all.

--TheDoctor

Author

Commented:
I know the overall big picture, but I'll need a more detail walk through of how this is done in terms on configuration.  I do have a second IP assigned to me on hosting #2.

1. setting up the subdomain at hosting #2 in apache and configurating IP association with that subdomain, how?

2. how to setup a DNS entry at hosting #1.
Commented:
Jay,

Shouldn't be a big deal, since you have a separate IP and everything. So in Apache, if the second machine is only bound to one IP, you can simply add a config like the one below to your sites-available folder, then symbolically link that file to the sites-enabled folder (and then restart Apache). There are two portions of the config, one designating the directory and what permissions it has enabled, then one for the VirtualHost itself. The virtual host section designates the port for the traffic, the web root, the server name, any additional aliases, logging, etc.. Make sure your document roots are the same and point to the folder where your content lives:

<Directory /home/folder/www>
      Options ExecCGI FollowSymLinks
      # Options Indexes ExecCGI FollowSymLinks
      AllowOverride All
      Order allow,deny
      allow from all
</Directory>

<VirtualHost *:80>
      ServerAdmin webmaster@company.com
      ServerName server2.company.com
      ServerAlias othername2.company.com
      DocumentRoot /home/images/www

      LogLevel warn
      ErrorLog /var/log/apache2/server2-error.log
      CustomLog /var/log/apache2/server2-access.log combined
      ServerSignature On
</VirtualHost>

DNS for your second host should simply be an A record pointing your servername to your second IP, like this:

   server2.company.com.        IN        A         123.234.111.222

After you've published that, you can use a command-line query like "nslookup server2.company.com" to see if your name address is resolving to the right address. If that's working, then your Apache server for the 2nd site should be listening for calls to that address, and serve up the content for your site.

Just FYI - this technically is not a "subdomain" at all. It's a common name we use in cases like this but this is only a hostname within your primary domain itself, xxxx.company.com. A true subdomain is actually a second-tier container inside of the domain that can hold lots more hostnames itself, like xxxxx.support.company.com (where "support" is the subdomain).
Commented:
Just to add a bit more on the Apache config, if you are SSHd into the server (hopefully you can), you will probably find your main Apache config in /etc/apache2/ and within there will see the apache2.conf and a few folders, etc. If you look in sites-available there should at least be a default and default-ssl config, and if you look in sites-enabled you will probably see a symbolic link to the default file (this is how it comes with a standard install).

So you may simply want to edit the /etc/apache2/sites-available/default file to point to the right webroot, with the right permissions, etc., and then you're good to go. But in many cases we run multiple sites out of one server. In that case, we can just create additional files like the default configuration file, each one customized to a different servername, and then symbolically link them into the sites-enabled folder. The idea here is that your actual files for site configs live in the sites-available folder, but only those files or links in the sites-enabled folder are actually being served up. But rather than copying the files over from one to the other, the symbolic link does the job.

To create a symbolic link, just change directories to the sites-enabled folder: cd /etc/apache2/sites-enabled and then issue this command:

    ln -s ../sites-available/filename filename (where filename is the name of the config file you want to link).

After that's in place, be sure to restart Apache for the changes to take effect:

    /etc/init.d/apache2 restart

If this is not where your Apache config lives, it should be something similar.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial