Create a subdomain on apache2

domgarofalo used Ask the Experts™
How do I create a subdomain in apache2 for a domain that I am hosting on my Raspberry Pi? Next, how do I set up the A record to point to the subdomain?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004
You don't create a subdomain in Apache.  You create a subdomain in your parent domain's DNS, and configure Apache to respond to it.

First, you will need to contact your DNS provider to  create the subdomain.  This generally consists of generating an A record pointing to an IP.  You need to know the IP ahead of time.  If it is a dynamic IP, this gets much more complicated.

Once you have the DNS, you configure Apache with a new virtual host.  Something like this:
<VirtualHost w.x.y.z:port>
    DocumentRoot /path/to/root

Open in new window

If you provide more details about your desired goal, we can be more specific with the assistance we give you.
Congrats - You run a web site on your Raspberry PI.
How do you plan to deploy it?
Do you want to access it only from your private network? Is it a home network or a business network?
Do you want to access it from the Internet?

You will have to deal with 3 configurations:
a. A DNS server must point the subdomain somewhere
b. Depending on the type of your network (see questions above) you may have to configure your router
c. Your Apache must recognize the new subdomain

Regarding Apache - the default Apache config is server name and subdomain agnostic. Any FQDN pointing to the server where Apache runs will be served. So, assuming your PI has address of, you may have
all pointing to, and all will be served exactly the same default configuration by Apache.

You only need virtual hosts defined when you want different content for different host names.


Did what you said and it's working now. Thanks!

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