How to create a subdomain with apache on CentOS 7?

October 3, 2015 32k views


I followed this tutorial:

But my problem is that i don’t have any idea how to set-up a subdomein my currently site is but i can’t launch the admin panel i made cuz the admin panel needs a subdomain:

But how can i create a subdomain?

3 Answers

If you follow this steps you have to edit YOUR_DOMAIN.conf file which is located /etc/httpd/sites-available/YOUR_DOMAIN.conf

sudo nano /etc/httpd/sites-available/YOUR_DOMAIN.conf

add this codes end of the file:

<VirtualHost *:80>
    ServerAlias YOUR_DOMAIN
    DocumentRoot /YOUR/SUB/DOMAIN/PATH
    CustomLog /YOUR/REQUESTED/LOG/PATH combined

Restart apache:

sudo apachectl restart
by Josh Barnett
The Apache web server is extremely powerful and flexible, which is why it's the most popular way of serving web content. Apache can host multiple domains or interfaces on one server by splitting sites into separate virtual hosts. In this guide, we will walk you through how to set up Apache virtual hosts on a CentOS 7 VPS.
  • The above process is correct ,But you have to follow 3 more steps

    1- before restarting the apache be sure that the document root directory is present.
    2- Create a new host record in /etc/hosts with the sub domain name
    3- create a CNAME record in your DNS zone

This answer is not correct. “sites-available” is a Debian thing, not a CentOS thing.

Hi There.
In My case, just change “sites-available” with “conf.d” and follow with your_domain.conf

Have another answer? Share your knowledge.