317

I have cmsplus.dev under /etc/apache2/sites-available with the following code,

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName www.cmsplus.dev
    ServerAlias cmsplus.dev

    DocumentRoot /var/www/cmsplus.dev/public

    LogLevel warn
    ErrorLog /var/www/cmsplus.dev/log/error.log
    CustomLog /var/www/cmsplus.dev/log/access.log combined
</VirtualHost>

Now when I use sudo /usr/sbin/a2ensite cmsplus.dev, I am getting the error,

ERROR: Site cmsplus.dev does not exist!

My webserver Apache/2.4.6 (Ubuntu)

How to solve this issue?

11 Answers 11

690

Solved the issue by adding .conf extension to site configuration files.

Apache a2ensite results in:

Error! Site Does Not Exist

Problem; If you found the error while trying to enable a site using:

sudo a2ensite example.com

but it returns:

Error: example.com does not exist

a2ensite is simply a Perl script that only works with filenames ending .conf

Therefore, I have to rename my setting file for example.com to example.com.conf as might be achieved as follows:

mv /etc/apache2/sites-available/example.com /etc/apache2/sites-available/example.com.conf

Success

9
  • 26
    Weird! This used to work fine without an extension in Ubuntu 12.04 and 12.10. Mar 26, 2014 at 11:21
  • Same for me. Like says Guilherme the apache2.conf changed between ubuntu or Apache versions. Aug 11, 2014 at 13:35
  • 7
    As an alternative I believe you could just edit the apache.conf file. The relevant line is "IncludeOptional sites-enabled/*.conf" Remove the .conf on the end and you'll be back to what worked in 12.04. I think this may be a change Debian made that trickeled into Ubuntu, but I'm not sure.
    – Josiah
    Sep 11, 2014 at 3:19
  • 2
    Why is this answers 3rd? This is the correct way of doing it.
    – nish
    Sep 29, 2014 at 6:41
  • I had already given up after changing pretty much everything... I will remember to add the .conf extension from now on... Mar 2, 2015 at 17:53
96

You probably updated your Ubuntu installation and one of the updates included the upgrade of Apache to version 2.4.x

In Apache 2.4.x the vhost configuration files, located in the /etc/apache2/sites-available directory, must have the .conf extension.

Using terminal (mv command), rename all your existing configuration files and add the .conf extension to all of them.

mv /etc/apache2/sites-available/cmsplus.dev /etc/apache2/sites-available/cmsplus.dev.conf

If you get a "Permission denied" error, then add "sudo " in front of your terminal commands.

You do not need to make any other changes to the configuration files.

Enable the vhost(s):

a2ensite cmsplus.dev.conf

And then reload Apache:

service apache2 reload

Your sites should be up and running now.


UPDATE: As mentioned here, a Linux distribution that you installed changed the configuration to Include *.conf only. Therefore it has nothing to do with Apache 2.2 or 2.4

3
  • 1
    Strange, I got the error when I tried to enable a site using a path: "sudo a2ensite /etc/apache2/sites-available/example.com.conf". On the other hand opening a console window within the sites-available directory and running "sudo a2ensite example.com.conf" executed perfectly.
    – Mark Lee
    Aug 27, 2021 at 19:53
  • I also tried within sites available folder and. just worked that ubuntu 20.04 Oct 12, 2022 at 4:48
  • @MarkLee, the a2ensite command doesn't expect a path. Just sudo a2ensite example.com should have worked regardless of the directory you were in Mar 29, 2023 at 11:28
28

There's another good way, just edit the file apache2.conf theres a line at the end

IncludeOptional sites-enabled/*.conf

just remove the .conf at the end, like this

IncludeOptional sites-enabled/*

and restart the server.

(I tried this only in the Ubuntu 13.10, when I updated it.)

3
  • 1
    Hmm... I tried this on Ubuntu 14.04 and it didn't work. Adding .conf to the config files did, though. Jun 16, 2014 at 19:32
  • strange, I had this error when I updated my ubuntu 12.04 to 13.10 (because I substituted unintentionally the apache config files). In the 14.04 update I remembered to not substitute, and I did had any trouble.
    – Guilherme
    Jun 19, 2014 at 19:08
  • This is really not a good way. Files under sites-enabled are symlinks to the corresponding files under sites-available and should just be removed to disable the site - that is in fact what a2dissite does a2ensite correspondingly enables the site.
    – Dokbua
    May 15, 2020 at 9:47
8

I just had the same problem. I'd say it has nothing to do with the apache.conf.

a2ensite must have changed - line 532 is the line that enforces the .conf suffix:

else {
    $dir    = 'sites';
    $sffx   = '.conf';
    $reload = 'reload';
}

If you change it to:

else {
    $dir    = 'sites';
    #$sffx   = '.conf';
    $sffx   = '';
    $reload = 'reload';
}

...it will work without any suffix.

Of course you wouldn't want to change the a2ensite script, but changing the conf file's suffix is the correct way.

It's probably just a way of enforcing the ".conf"-suffix.

1
8

So .. quickest way is rename site config names ending in ".conf"

mv /etc/apache2/sites-available/mysite /etc/apache2/sites-available/mysite.conf

a2ensite mysite.conf

other notes on previous comments:

  • IncludeOptional wasn't introduced until apache 2.36 - making change above followed by restart on 2.2 will leave your server down!

  • also, version 2.2 a2ensite can't be hacked as described

as well, since your sites-available file is actually a configuration file, it should be named that way anyway..


In general do not restart services (webservers are one type of service):

  • folks can't find them if they are not running! Think linux not MS Windows..

Servers can run for many years - live update, reload config, etc.

The cloud doesn't mean you have to restart to load a configuration file.

  • When changing configuration of a service use "reload" not "restart".

  • restart stops the service then starts service - if there is a any problem in your change to the config, the service will not restart.

  • reload will give an error but the service never shuts down giving you a chance to fix the config error which could only be bad syntax.

debian or ubunto [service-name for this thread is apache2]

service {service-name} {start} {stop} {reload} ..

other os's left as an excersize for the reader.

6

Worked after I added .conf to the configuration file

6

I realise that's not the case here but it might help someone.

Double-check you didn't create the conf file in /etc/apache2/sites-enabled by mistake. You get the same error.

3
  • Where should the file be? Oct 4, 2022 at 2:32
  • 2
    @LucasSteffen /etc/apache2/sites-available. From memory, the one in sites-enabled is created automatically
    – Dave
    Oct 5, 2022 at 5:05
  • 1
    There are so many online "guides" that get this wrong.
    – Trunk
    Apr 11, 2023 at 14:09
3

I have just upgraded the Ubuntu Server version from 12.04 LTS to 14.04 LTS.

Indeed, as said above, the .conf extension to Apache 2.4.x is needed to the websites vhost files that resides on sites-available directory.

Before read this question I did not have a clue what was going on with the server.

Pretty nice solution.

Just summarizing I did the following steps on Terminal:

1) Access sites-enabled folder

$ cd /etc/apache2/sites-enabled

2) Because the command a2dissite will not work with deprecated files (without .conf) remove the old website files that was published

$ sudo rm <my-old-website-without-.conf>

3) Rename the website vhost files changing its extension adding .conf to the end

$ sudo mv /etc/apache2/sites-available/mywebsite /etc/apache2/sites-available/mywebsite.conf

4) Republish the new and correct vhost file

$ sudo a2ensite mywebsite.conf

5) Check the website on browser and have fun! :)

1
  • Thanks, that's the only thing that did it for me: cleaning sites-enabled before re-enabling them.
    – Clément
    Feb 3, 2022 at 3:31
2

In my case with Ubuntu 14.04.3 and Apache 2.4.7, the problem was that I copied site1.conf to make site2.conf available, and by copying, something happend and I could not a2ensite site2.conf with the error described in thread.

The solution for me, was to rename site2.conf to site2 and then again rename site2 to site2.conf. After that I was able to a2ensite site2.conf.

1
  • 1
    yes, this is working in Ubuntu 20. cd /etc/apache2/sites-available, mv mysite.conf mysite && mv mysite mysite.conf. Then a2ensite mysite.conf shows Enabling site mysite. Then we can systemctl start apache2 or systemctl reload apache2 Feb 16, 2022 at 19:07
0

I had the same issue, because of I tried to use absolute path.

 sudo a2ensite /etc/apache2/sites-available/test.conf

instead just run

 sudo a2ensite test.conf

it will work after

sudo systemctl reload apache2
-2

Try like this..

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName www.cmsplus.dev
    ServerAlias cmsplus.dev

    DocumentRoot /var/www/cmsplus.dev/public

    LogLevel warn
    ErrorLog /var/www/cmsplus.dev/log/error.log
    CustomLog /var/www/cmsplus.dev/log/access.log combined
</VirtualHost>

and add entry in /etc/hosts

127.0.0.1 www.cmsplus.dev

restart apache..

3
  • Now it's giving me the default It works page instead of the settings. Dec 15, 2013 at 6:44
  • Do you have multiple virtual hosts configuration? Can you post whole file content? Dec 15, 2013 at 6:50
  • 3
    Thanks, solved this issue by just adding .conf extension to these site configuration files. Dec 15, 2013 at 6:51

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