Articles

How to Create a Subdomain

Using subdomains with ServerPilot is exactly the same as any other domain name.

If you want your users to see a different website when visiting the subdomain, you should create a new app and assign the subdomain as one of the new app's domain names.

If the subdomain is just an alias for an existing website, go to the app you already created in ServerPilot and add the subdomain to the app's list of domain names.

You can add and remove domain names from your apps at any time.

Subdomain Example

Imagine you have two apps to run on your server. One of them is your main website, a Magento app, and you need it to be available as both example.com and www.example.com. Your other app is your WordPress blog that needs to be available as blog.example.com.

Here's how you'd set this up through ServerPilot.

Step 1: Create an app for your main website.

In ServerPilot, go to the Apps page and click + Create App. Give this app a name like magento. Next, also in ServerPilot, add both example.com and www.example.com as this app's domains.

Step 2: Create an app for your blog.

Now repeat what you did in Step 1. In ServerPilot, go to the Apps page and click + Create App. Give this app a name like blog. Now add blog.example.com as this app's domain name.

Step 3: Upload your files.

After you've completed Step 1 and Step 2, you'll have two separate web root directories on your server, one for each app. These directories will be located at:

/srv/users/serverpilot/apps/magento/public
/srv/users/serverpilot/apps/blog/public

As you've probably guessed, you would upload your Magento files to /srv/users/serverpilot/apps/magento/public and your WordPress files to /srv/users/serverpilot/apps/blog/public.

Step 4: Point DNS to your server's IP address.

Now go to where you manage DNS for your domain. In this example, it would be where we manage DNS for example.com. You should create separate A records pointing to your server's IP address for each of the following:

  • example.com
  • www.example.com
  • blog.example.com

Once your DNS changes have propagated (this can take a few minutes to an hour, depending how your domain's DNS is configured), your apps will be accessible by the names you've assigned to them.

Optional Step 5: Adding more domain names.

You can add and remove domain names from your app at any time. Imagine you decide you want your blog to also be accessible as www.blog.example.com. Just log in to ServerPilot, go to your blog app, and add the domain name www.blog.example.com. Don't forget to also go to your DNS provider and created an A record for this name.