Configuring Subdomains Apache
Oct 17, 2020
Pre-requisites:
Create DNS records.
- One A DNS Record for *.domain.com
- One A DNS Record for domain.com
Configuring sub-domain
Apache’s main web folder is /var/www/. There should already be the folder html in here. For this example, we’ll pretend we want to make the subdomain: test.example.com.
- First, you’ll want to create a directory in /var/www/ called “test” using mkdir -p /var/www/test/.
- Next, you’ll want to go to: /etc/apache2/sites-available/. In here there is a file called 000-default.conf. You will want to copy this file in the same directory, and name it: test.example.com.conf in our case.
- In this file, you’ll want to have the following code:
ServerAdmin webmaster@test.example.com
ServerName test.example.com
DocumentRoot /var/www/test
<Directory /var/www/test/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /error.log
CustomLog /access.log combined
- Then you’ll want to enable the subdomain:
a2ensite test.example.com.conf
- Finally, you’ll want to do a reload on the apache service to make sure the changes come through.
systemctl reload apache2
Now you should be good to go with your new subdomain!