====== Domains ======
Typically, you'll want to use your shared hosting account to serve websites and handle mail with your domain(s). A //domain// is typically understood as a hostname of two parts (e.g. //mydomain.com//), sometimes of three parts (e.g. //mycompany.co.uk//) - compared to subdomains which usually introduce an additional minor part (e.g. //blog.mydomain.com//).
Make sure you have enabled the web virtual server, otherwise you will not be able to serve websites from your domain. You can enable the web virtual server from Virtualmin by doing the following:
- Sign in to Virtualmin (see [[Logins]]).
- Select a virtual server from the drop-down in the left-hand navigation (your main virtual server should be already selected when you first login to Virtualmin).
- Click **Edit Virtual Server** in the left-hand navigation.
- Click **Enabled features**
- Select **Web virtual server enabled?** and **Enable PowerDNS domain?**
- Click **Save Virtual Server**
===== Adding a domain =====
First, you should //own// a domain - that is, have it registered with a domain registrar. Joyent does not provide a domain registrar service, so you'll need to register a domain first with a 3rd party provider. Once you have a registered domain, do the following:
- Sign in to Virtualmin (see [[Logins]]).
- From the left-hand navigation, click **Create Virtual Server**.
- In the //Domain name// field, enter the desired name for your new domain (do not enter ''%%http://...%%'' or even ''www.'') and a brief description in the //Description// field.
- A mail user suffix and database prefix will be automatically chosen, but you can customize them under “Advanced Options” if you want (see note below). The mail user suffix can be changed until a user is created.
- Click **Enabled features**. From here you can decide whether you want to enable email, MySQL, WebDAV, Subversion etc. for your domain. Most of the features are disabled by default **(including the web server!)**, so be sure to check over the options and enable what you need. It is a good practice to leave off things you don't currently need; they can always be turned on later. Since you're adding a domain, you'll most likely want to enable **Web virtual server enabled?** to make your website accessible.
- Finally, click **Create Server** to create your domain.
**Advanced Options > Mail user and database prefixes:**
With administration username ''foo'' for domain ''bar.com'' your main domain name’s default prefixes will be:
* **Mail user:** “''//user name//-admin username''” eg for a user called ''billbarnicle'' the resulting email login will be ''billbarnicle-foo'' (note that this only affects the POP/Usermin login name, the email address will be ''billbarnicle@bar.com''). The admin user’s POP/Usermin login will just be ''foo'' (not ''foo-foo'').
* **Database:** “''admin username_//database name//''” eg for a database called ''wombat'' the resulting database name will be ''foo_wombat''.
When you create a virtual server (a subserver), eg for the domain ''baz.com'' your sub-server’s default prefixes will be:
* **Mail user:** “''//user name//-subserver name''” eg for a user called ''samsawnoff'' the resulting email login will be ''samsawnoff-baz''. Specify a new prefix as it is, eg ''qux'' would give you the email login ''samsawnoff-qux''.
* **Database:** “''admin username_subserver name_//database name//''” eg for a database called ''possum'' the resulting database name will be ''foo_baz_possum''. To specify a new prefix **include the admin username and trailing underscore**, eg ''foo_qux_'', which would give you ''foo_qux_possum''.
===== Renaming a domain =====
- Sign in to Virtualmin (see [[Logins]]).
- Select a domain from the drop-down in the left-hand navigation (your main domain should be already selected when you first login to Virtualmin). The domain you select will be the one that you'll be renaming.
- Click **Server Configuration** and click **Change Domain Name**.
- In the **New domain name** field, enter the new name for your domain.
- If you'd like to keep the name of the home directory for this domain, select **Leave as /users/home/...** for //Change home directory//, but usually you want the name change as well (this will have no effect on primary virtual servers).
- If you'd like to keep the names of your mail/SFTP users, select **No** for //Rename mail / FTP users too?//.
* Remember, any users you create for a domain will have a username based on the domain name. So, if the user's name is //joe// and the domain name is //example.com//, Joe's login would be //joe-example//.
- Click **Rename Now**.
===== Deleting a domain =====
- Sign in to Virtualmin (see [[Logins]]).
- Select a domain from the drop-down in the left-hand navigation (your main domain should be already selected when you first login to Virtualmin). The domain you select will be the one that you'll be renaming.
- Click **Disable and Delete** and click **Delete Virtual Server**.
- Click **Yes, Delete It** to delete the domain.