19

I'm trying to add subdomains to my home server.

svn.domain.com trac.domain.com

Due to dynamic IP I use dyndns service, on top of that I have domain.com hosted somewhere else. I created CNAME for subdomains on remote host to point to my user.dyndns.org domain.

So now when I visit either of subdomains: trac or svn, I see "It works!" message.

This done, I created two virtual host files under /etc/apache2/sites-enabled

file1: svn.domain.com and file2: trac.domain.com

contents:

<VirtualHost *:80>

  ServerName trac.domain.com

   DocumentRoot = /var/www/trac/repos

   <Directory /var/www/trac/repos>
    Order allow,deny
    allow from all
   </Directory>

</VirtualHost>

And

<VirtualHost *:80>

  ServerName svn.domain.com

   DocumentRoot = /var/svn/repos

   <Directory /var/svn/repos>
    Order allow,deny
    allow from all
   </Directory>

</VirtualHost>

But I get error: ERROR: Site trac.domain.com does not exist!

what am I doing wrong?

Rishabh
  • 3,752
  • 4
  • 47
  • 74
  • You want serverfault or something similar - stackoverflow is read by software developers rather than sysadmin. –  May 11 '12 at 19:55

7 Answers7

110

I had this problem when upgrading from Apache 2.2 to Apache 2.4. The (ridiculous) solution was to ensure all files end with .conf, or a2ensite would ERROR: Site example does not exist!.

Also, when linked manually in sites-enabled, they would not even load without the .conf extension.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
Simon A. Eugster
  • 4,114
  • 4
  • 36
  • 31
19

I also came across the same problem when I upgraded from Apache 2.2 to 2.4; all my virtual hosts suddenly broke and while trying to search for why this was the case, I stumbled across this question.

It turns out the reason is because of a difference between my old apache2.conf and the new apache2.conf. My old Apache 2.2 conf file had the line

Include sites-enabled/

whereas my new Apache 2.4 conf file had the line

IncludeOptional sites-enabled/*.conf

Lo and behold, when I changed the line to

IncludeOptional sites-enabled/

everything went back to normal.

sakibmoon
  • 2,026
  • 3
  • 22
  • 32
badcook
  • 3,699
  • 14
  • 25
  • Thanks a lot for these explanations ! – Alexandre Tranchant Aug 18 '13 at 17:01
  • This is really useful info. Now we just need to figure out how to get a2ensite working again. – Joel Mellon Aug 23 '13 at 18:16
  • I swore I tried renaming to .conf and it didn't work...I tried again and it did work. a2ensite is a perl script and has been updated to only allow *.conf files. ...so yeah, the "Right" way to set up vhosts from now on is by naming all sites *.conf. Thanks Obama! – Joel Mellon Aug 23 '13 at 18:28
  • thanks to this I added a new line "IncludeOptional sites-enabled/" and there you go it works. I am using LMDE but I think this might have been a problem in the Upstream. So every debian distro might have got this update. – Gayan Hewa Oct 02 '13 at 21:25
8

Try moving the files to /sites-available. Then run a2ensite svn.domain.com and a2ensite trac.domain.com and reload Apache.

BluesRockAddict
  • 15,525
  • 3
  • 37
  • 35
  • Syntax error on line 5 of /etc/apache2/sites-enabled/trac.domain.com: DocumentRoot takes one argument, Root directory of the document tree Action 'configtest' failed. –  May 11 '12 at 20:35
  • 1
    Try removing `=` from DocumentRoot directive: `DocumentRoot /var/www/trac/repos` – BluesRockAddict May 11 '12 at 20:37
  • 4
    Something that tripped me up was that I was doing a2ensite on the subdomain name, which was wrong. You need to run a2ensite on the *file*. – Joseph Oct 04 '12 at 17:41
  • As @Joseph mentioned, you have to run a2ensite on the conf file, so the naming of that file is all that matters. Otherwise, just run a2ensite withouth specifying the name, you can choose from the list then. – moojen Aug 18 '19 at 18:30
5

if you type a2ensite. it will prompt. Which sites do you want to enable (ie., after you put a .conf file in the sites-available and link it from sites-enabled.

a2ensite expect the full name of the conf file with the .conf extension

tven
  • 547
  • 6
  • 18
  • I had the .conf extension as I had encountered this problem before. BUT when you get the default name using tab, for example type "a2ensite t..." press tab and get the name autofilled for you IT LEAVES OFF THE .CONF extension. You have to type the .conf. – MagicLAMP Nov 22 '15 at 23:55
3

a2ensite ONLY accepts .conf files, so copy all sites in sites-available so the have a .conf extension (renaming didn't work itconfused the linkssomehow), erase the original files from sites-available AND sites-enabled. use a2ensite on the new files (you don't need to add .conf) and it all works, with our without the *.conf in /etc/apache2/apach2.conf

There must be some "memory" of the original file even when it is renamed -the symbolic link renames also, butthe erases & enabling "new" .con files works and you can then use a2dissite and a2ensite as before

user2903751
  • 31
  • 1
  • 1
1

My solution for local server name is replacing:

sudo a2ensite serverName

with

sudo a2ensite serverName.conf
Manolo
  • 24,020
  • 20
  • 85
  • 130
0

1) remove all default site inside sites-enable

a2dissite <site-configuration-file-name>

2) take a closed look at your config file: start with a minimum properties like:

<VirtualHost [Domain]:80>
ServerAdmin webmaster@localhost
ServerName [Domain]
DocumentRoot [webAppPath]

<Directory [webAppPath]>
    AllowOverride All
     Order allow,deny
     Allow from all
     Require all granted
</Directory>


ErrorLog ${APACHE_LOG_DIR}/my_domain_name_error.log

CustomLog ${APACHE_LOG_DIR}/my_domain_name_access.log combined
</VirtualHost>
Ulrich Horus
  • 352
  • 3
  • 9