Creating subdomains

I need the ability to create subdomains.

ex. dog.mydomain.com

With previous providers this was easy with cpannel, now thats another story without a control panel.

Does anyone know of a quick/easy way to create subdomains?

Ive installed Webmin in hopes it had the ability to create subdomains but have not had any luck with it.

I am very new to unmanaged servers, so everything is a long process for me.

23 Replies

Just DNS wise? Or in your webserver? Do you use Apache? Nginx? Which OS?

Hey Guys,

If I could be so rude to hijack this post as after the same information.

I'm on NGINX with Ubuntu 12.04, PHP 5.3, DNS instructions would be good for me (assuming it's via the Linode DNS manager?).

Thanks in advance,

Paul

livefree:

You need to install the virtualmin module to webmin to be able to create subdomains easily.

@livefree:

Hey Guys,

If I could be so rude to hijack this post as after the same information.

I'm on NGINX with Ubuntu 12.04, PHP 5.3, DNS instructions would be good for me (assuming it's via the Linode DNS manager?).

Thanks in advance,

Paul

DNS Wise it's simply creating a new A Record, set the subdomain you want as name (if you want sub.domain.tld, use sub as value) and the IP to your Linode's IP. You can add 2, one with IPv4 IP, other with IPv6, if you set up your nginx to allow IPv6 traffic.

Nginx wise, assuming you use apt-packages,

1. copy current config, e.g.: cp /etc/nginx/sites-available/0-default /etc/nginx/sites-available/1-sub.domain.tld

2. Edit 1-sub.domain.tld, change values:

  • server_name sub.domain.tld;

  • access_log

  • error_log

  • root

^ use own values for logs/root

Do you use PHP-FPM? That might require some extra settings for the PHP Pool.

im using apache with debian

The450man: DNS wise it's the same as I said to livefree,

I use nginx, but with apache it should be about the same:

1. copy the current config, e.g. /etc/apache2/sites-available/0-default to /etc/apache2/sites-available/1-sub.domain.tld

I believe the following matters with Apache2 for stuff you need to change:

ServerName sub.domain.tld

ServerAdmin admin@sub.domain.tld

DocumentRoot /folder/to/public/html

ErrorLog /var/log/apache2/sub.domain.tld-error.log

CustomLog /var/log/apache2/sub.domain.tld-access common

Thanks Nuvini!

I have Three files: default, default-ssl and mydomain.tld (has the MS-DOS application extension). I believe the MS-dos application extension was from using putty?

The other two files appeared as if they are using a wildcard *, the ms-dos one seemed to have the proper format so I copied it and edited the mydomain.tld with subdomain.mydomain.tld

As far as setting the DNS goes, do we do this within the linode manager itself? If so, how is this done? Creating a new domain zone? Master or slave?

I'm not sure what you mean with the MS-DOS Extension.

After editing, I believe Apache has a built in command to enable the site: a2ensite If that doesn't work, just do ln -s /etc/apache2/sites-available/sub.domain.tld /etc/apache2/sites-enabled/sub-domain.tld

DNS wise, I don't know your domain name, but you have to set it where your nameservers are located. Linode doesn't handle domain registrations, so by default you'll have to add the A-records where you registered your domain.

If you want to use the Linode DNS manager for this you have to point your domain's nameservers to ns1.linode.com to ns5.linode.com. If you can't fill in 5 nameservers, check here which ones are the best geographically and use those: https://www.linode.com/wiki/index.php/Linode_DNS (e.g. If you're in Europe, make sure to at least include ns5.linode.com)

Im using linodes domain manager and have my domains nameservers pointend to the linode nameservers.

After editing, it appears the sub domain now works but it displays the content of the main domain.

What does 'apache2ctl -S' report?

@Nuvini:

I'm not sure what you mean with the MS-DOS Extension.
He has a file named "mydomain.com" in the sites directory, and is using Windows, which interprets .com as the old DOS-style executable.

When i ran "apache2ctl -S" i got:

apache2: Could not reliably determine the server's fully qualified domain name, using 74.207.xxx.xxx for ServerName

VirtualHost configuration:

wildcard NameVirtualHosts and default servers:

*:80 is a NameVirtualHost

default server www.mydomain.com (/etc/apache2/sites-enabled/mydomain.com:4)

port 80 namevhost www.mydomain.com (/etc/apache2/sites-enabled/mydomain.com:4)

port 80 namevhost www.mydomain.com (/etc/apache2/sites-enabled/sub-mydomain.com:4)

port 80 namevhost www.mydomain.com (/etc/apache2/sites-enabled/sub-mydomain.com:21)

It looks like you need to change ServerName for both of the stanzas in sub-mydomain.com.

I did some editing and ran apache2ctl -S again:

VirtualHost configuration:

wildcard NameVirtualHosts and default servers:

*:80 is a NameVirtualHost

default server http://www.mydomain.com (/etc/apache2/sites-enabled/mydomain.com:4)

port 80 namevhost http://www.mydomain.com (/etc/apache2/sites-enabled/mydomain.com:4)

port 80 namevhost sub.mydomain.com (/etc/apache2/sites-enabled/sub-(the domain name here is wrong. My domain has three characters sperated by a -, it is missing the first 4 characters).com:4)

Syntax OK

I need to edit the "sites-enabled" folder files, but I believe these are system links and not actual files. How can I edit these?

My sub domain is still redirecting to my main domain.

if you edit the symlinked files you also edit the actual file.

Post output of ls -lah /etc/apache2/sites-enabled

and the output of the config files there (cat /etc/apache2/sites-enabled/*)

thanks Nuvini

I ran "ls -lah /etc/apache2/sites-enabled" and the output was:

total 8.0K

drwxr-xr-x 2 root root 4.0K Mar 30 10:29 .

drwxr-xr-x 7 root root 4.0K Mar 28 14:31 ..

lrwxrwxrwx 1 root root 37 Mar 28 14:37 mydomain.com -> ../sites-available/mydomain.com

lrwxrwxrwx 1 root root 56 Mar 30 10:29 sub-mydomain.com -> /etc/apache2/sites-available/sub.mydomain.com

my domain does have a "-" character in it, im not sure if this can screw things up.

Would anyone be willing to share an instant messaging service? Aim, yahoo, skype, etc. It would be great if I could talk to someone in real time.

Could you also post:
> and the output of the config files there (cat /etc/apache2/sites-enabled/*)

The dash doesn't matter :)

I am on IRC (#linode), so you can poke me (Kami) there or someone else. It's probably best to ask in the chat in general, I don't do much with Apache, just nginx :)

> ````

lrwxrwxrwx 1 root root 56 Mar 30 10:29 sub-mydomain.com -> /etc/apache2/sites-available/sub.mydomain.com
````
This is crazy, the names don't match.

Have you made this symlink manually?

To put all info in one place:

0. You need a DNS entry for the domain and/or subdomain pointing to the server.

1. You should edit only the "real files" in /etc/apache2/sites-available/

2. To "activate" a site, you run a2ensite file.name.here && invoke-rc.d apache2 reload which creates a symlink in the sites-enabled directory and tells Apache to re-read config files.

3. To deactivate, similarly use a2dissite file.name.here && invoke-rc.d apache2 reload which removes the symlink and tells Apache to re-read config.

4. A file in /etc/apache2/sites-available can have any name (using the domain name it is for is a good idea though.)

5. It should look like that,in its simplest form:

 <virtualhost *:80="">ServerName sub.example.com
    DocumentRoot /path/to/files/for/the/site</virtualhost> 

You should not put the domain name on the VirtualHost line in most cases.

Just the ServerName line.

Of course it can have a lot other entries, setting up redirects, scripting, and stuff. We can share some examples if you wish.

6. If your server is accessed by a (sub)domain name for which you do not have an explicit sites-enabled file, it'll show the first site that was configured.

The sites files are loaded in alphabetical order.

So, you should create a sites file for a placeholder (or redirect) site that should be displayed in cases like accessing your server by IP (http://1.2.3.4/), name it like 000default or ___default or similar, and enable it.

@Nuvini:

Could you also post:
> and the output of the config files there (cat /etc/apache2/sites-enabled/*)

The dash doesn't matter :)

I am on IRC (#linode), so you can poke me (Kami) there or someone else. It's probably best to ask in the chat in general, I don't do much with Apache, just nginx :)

Running "cat /etc/apache2/sites-enabled/*" gave me the output:

root@testosterone:~# cat /etc/apache2/sites-enabled/*

domain: mydomain.com

public: /home/user/public/mydomain.com/

# Admin email, Server Name (domain name), and any aliases

ServerAdmin webmaster@mydomain.com

ServerName www.mydomain.com

ServerAlias mydomain.com

Index file and Document Root (where the public files are located)

DirectoryIndex index.html index.php

DocumentRoot /home/user/public/mydomain.com/public

Log file locations

LogLevel warn

ErrorLog /home/user/public/mydomain.com/log/error.log

CustomLog /home/user/public/mydomain.com/log/access.log combined

domain: sub.mydomain.com

public: /home/user/public/sub.mydomain.com/

# Admin email, Server Name (domain name), and any aliases

ServerAdmin webmaster@mydomain.com

ServerName sub.mydomain.com

ServerAlias sub.mydomain.com

Index file and Document Root (where the public files are located)

DirectoryIndex index.html index.php

DocumentRoot /home/user/public/sub.mydomain.com/public

Log file locations

LogLevel warn

ErrorLog /home/user/public/sub.mydomain.com/log/error.log

CustomLog /home/user/public/sub.mydomain.com/log/access.log combined

thanks Rsk.

I messed around a little, im learning but now neither my main domain or sub domain works. I tried re enabling them and im still getting erros.

Im in the IRC chat now, its empty.

@rsk:

> ````

lrwxrwxrwx 1 root root 56 Mar 30 10:29 sub-mydomain.com -> /etc/apache2/sites-available/sub.mydomain.com
````
This is crazy, the names don't match.

Have you made this symlink manually?

nope. although I may have created the vhost wrong and enabling that site created the false symlink

@the450man:

thanks Rsk.

I messed around a little, im learning but now neither my main domain or sub domain works. I tried re enabling them and im still getting erros.

Im in the IRC chat now, its empty.

You must be in the wrong channel. There's a lot of people. http://chat.linode.com/cgi-bin/irc/irc.cgi should get you to the right place.

Glad to say my problem has been solved.

apache was not running :0

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct