1

I have one domain and a sub domain which are supposed to point to two different folder, i have tried this help but still i have issues. (https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04)

www.wasamar.com.ng | wasamar.com.ng -> /var/www/html/wasamar/public

this is the virtual host file (/etc/apache2/sites-available/wasamar.com.ng.conf)

ServerName wasamar.com.ng

ServerAlias www.wasamar.com.ng

ServerAdmin info@wasamar.com.ng
DocumentRoot /var/www/html/wasamar/public

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

www.ts.wasamar.com.ng | ts.wasamar.com.ng -> /var/www/html/wasamar_ts/public

this is the virtual host file (/etc/apache2/sites-available/ts.wasamar.com.ng.conf)

ServerName ts.wasamar.com.ng

ServerAlias www.ts.wasamar.com.ng

ServerAdmin info@wasamar.com.ng
DocumentRoot /var/www/html/wasamar_ts/public/

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

The pastebin of apache.conf file http://pastebin.com/dnDfB21y

How do i achieve this?

  • Can you specify what "issues" you still have. I see the conf files, but don't know what issue you think you have. – Gypsy Spellweaver Jan 21 '17 at 3:31
  • @Gypsy i want to make a domain and a subdomain point to two diffrent document path, how do i do that? – udemethegrtman Jan 21 '17 at 3:35
  • That you did, the DocumentRoot directive tells the server where to look for the files. Have you enable the directories for the server? Have you enabled virtual hosts? Does you main conf file include these files? – Gypsy Spellweaver Jan 21 '17 at 3:40
  • I have enabled virtualhost sudo a2ensite wasamar.com.ng.conf and sudo a2ensite ts.wasamar.com.ng.conf let me add my main config (/etc/apache2/apache2.conf) please look up. – udemethegrtman Jan 21 '17 at 6:58
0

From what I can see, there are a few problems, and could be more. For beginners, while you have told Apache where to find the root for each server, you haven't given Apache permission to "serve" files from those directories. Nor have you told Apache that these are virtual hosts. There are other things you need to do with the virtual host conf files, but at a minimum you need to give Apache permission to server the files in the directory, and you need to tell Apache that this is a virtual host definition. Modified for only this minimum, the two files look like this:

This is the new virtual host file (/etc/apache2/sites-available/wasamar.com.ng.conf):

<VirtualHost *:80>

ServerName wasamar.com.ng

ServerAlias www.wasamar.com.ng

ServerAdmin info@wasamar.com.ng
DocumentRoot /var/www/html/wasamar/public

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

# At least you need to make the folder accessable for serving by the server.
# Versions of Apache, and modules installed can make a difference in what's inside
# the Directory directive. But as an example:
<Directory "/var/www/html/wasamar_ts/public">
        <IfModule mod_authz_core.c>
            Require all granted
        </IfModule>
        <IfModule !mod_authz_core.c>
            Order allow,deny
            Allow from all
        </IfModule>
</Directory>
</VirtualHost>

This is the new virtual host file (/etc/apache2/sites-available/ts.wasamar.com.ng.conf):

<VirtualHost *:80>

ServerName ts.wasamar.com.ng

ServerAlias www.ts.wasamar.com.ng

ServerAdmin info@wasamar.com.ng
DocumentRoot /var/www/html/wasamar_ts/public/

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

# At least you need to make the folder accessable for serving by the server.
# Versions of Apache, and modules installed can make a difference in what's inside
# the Directory directive. But as an example:
<Directory "/var/www/html/wasamar_ts/public">
        <IfModule mod_authz_core.c>
            Require all granted
        </IfModule>
        <IfModule !mod_authz_core.c>
            Order allow,deny
            Allow from all
        </IfModule>
</Directory>
</VirtualHost>

In both cases the change is adding the first line, and the last ten lines. Inside the directive you probably need other things, such as Options and AllowOverride for example.

For all this to work, you also need something more in your main conf file, probably httpd.conf in some directory, likely /etc/apache2/. What's needed is an instruction to include these new files in the configuration. at its simplest, based on the paths given, it would look like these:

Include sites-available/wasamar.com.ng.conf
Include sites-available/ts.wasamar.com.ng.conf

If you only include virtual hosts in the sites-available directory, then you can use

Include sites-available/*.conf

That will include any .conf file placed there, so you can create additional hosts as needed and not have to add a line to httpd.conf everytime you do.

You can learn a lot, and spend days reading, and re-reading, the Apache documentation online, or probably included with your installation of Apache locally. It may seem like a lot, but it is time well spent.

  • i am having issues on this when i added ssl to it, on another server and i have to the config bit.ly/2m9EDAf – udemethegrtman Mar 17 '17 at 11:34
  • Glad that you got this part working. On the Stack Exchange family of sites, if one of the answers you received solved your issue, please take a moment and accept it by clicking on the check mark to the left. That will mark the question as answered and is the way thanks are expressed on the Stack Exchange sites. – Gypsy Spellweaver Mar 17 '17 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.