Server administration How to add a new domain to Apache2 server

Underground Forum

Underground Forum

  • #1

Apache2, adding new domain​

In order to bind a domain(s) or subdomains to your httpd server, you will need to edit the configuration file.
But keep in mind that you will also need to set up DNS on the side of the domain registrar, otherwise no one will see your site.

Where to find VirtualHost settings in Apache​

On Ubuntu OS, the virtual host configuration is located in the directory/etc/apache2/sites-available. Other, similar operating systems have virtualhost settings right in the apache2.conf file.
On CentOS, virtualhost settings can be found in the main configuration file httpd.conf located at /etc/httpd/conf/httpd.conf .

Use the <VirtualHost * :80> container to add a new virtualhost. You can add as many as you like.

Configure container VirtualHost * :80

# First domain (VirtualHost)
<VirtualHost *:80> # Tag denoting virtual host settings, 80 is the port
     ServerAdmin # Administrator's contact address
     DocumentRoot /var/www/ # Website's directory
     ServerName # Domain name
     ServerAlias # Alternative names
     ErrorLog logs/ # Logs
     CustomLog logs/ common # Logs
     <Directory /> # Defines the rules for a directory
         Options FollowSymLinks
         AllowOverride All


# Second domain (VirtualHost)
<VirtualHost *:80>
     DocumentRoot /var/www/html/
     ErrorLog logs/
     CustomLog logs/ common

    <Directory />
         Options FollowSymLinks
         AllowOverride All